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

patch 8.2.2846: Vim9: "echo Func()" does not give an error for using void Commit: https://github.com/vim/vim/commit/68db996b621b98066fb7ab7028ed5c6aaa3954a8 Author: Bram Moolenaar <Bram@vim.org> Date: Sun May 9 23:19:22 2021 +0200 patch 8.2.2846: Vim9: "echo Func()" does not give an error for using void Problem: Vim9: "echo Func()" does not give an error for a function without a return value. Solution: Give an error. Be more specific about why a value is invalid.
author Bram Moolenaar <Bram@vim.org>
date Sun, 09 May 2021 23:30:05 +0200
parents a4fda40e0bb9
children 4a4f64cdc798
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1 /* vi:set ts=8 sts=4 sw=4 noet:
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2 *
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3 * VIM - Vi IMproved by Bram Moolenaar
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4 *
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
5 * Do ":help uganda" in Vim to read copying and usage conditions.
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6 * Do ":help credits" in Vim to see a list of people who contributed.
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7 * See README.txt for an overview of the Vim source code.
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8 */
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
9
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
10 /*
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
11 * vim9execute.c: execute Vim9 script instructions
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
12 */
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
13
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
14 #define USING_FLOAT_STUFF
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
15 #include "vim.h"
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
16
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
17 #if defined(FEAT_EVAL) || defined(PROTO)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
18
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
19 #ifdef VMS
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
20 # include <float.h>
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
21 #endif
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
22
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
23 #include "vim9.h"
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
24
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
25 // Structure put on ec_trystack when ISN_TRY is encountered.
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
26 typedef struct {
23921
a834f9c082e3 patch 8.2.2503: Vim9: a caught error may leave something on the stack
Bram Moolenaar <Bram@vim.org>
parents: 23917
diff changeset
27 int tcd_frame_idx; // ec_frame_idx at ISN_TRY
a834f9c082e3 patch 8.2.2503: Vim9: a caught error may leave something on the stack
Bram Moolenaar <Bram@vim.org>
parents: 23917
diff changeset
28 int tcd_stack_len; // size of ectx.ec_stack at ISN_TRY
23994
3daeb2060f25 patch 8.2.2539: Vim9: return from finally block causes a hang
Bram Moolenaar <Bram@vim.org>
parents: 23982
diff changeset
29 int tcd_catch_idx; // instruction of the first :catch or :finally
3daeb2060f25 patch 8.2.2539: Vim9: return from finally block causes a hang
Bram Moolenaar <Bram@vim.org>
parents: 23982
diff changeset
30 int tcd_finally_idx; // instruction of the :finally block or zero
3daeb2060f25 patch 8.2.2539: Vim9: return from finally block causes a hang
Bram Moolenaar <Bram@vim.org>
parents: 23982
diff changeset
31 int tcd_endtry_idx; // instruction of the :endtry
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
32 int tcd_caught; // catch block entered
24122
e8b21a3bb0d5 patch 8.2.2602: Vim9: continue doesn't work if :while is very first command
Bram Moolenaar <Bram@vim.org>
parents: 24112
diff changeset
33 int tcd_cont; // :continue encountered, jump here (minus one)
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
34 int tcd_return; // when TRUE return from end of :finally
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
35 } trycmd_T;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
36
24488
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
37 // Data local to a function.
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
38 // On a function call, if not empty, is saved on the stack and restored when
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
39 // returning.
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
40 typedef struct {
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
41 int floc_restore_cmdmod;
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
42 cmdmod_T floc_save_cmdmod;
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
43 int floc_restore_cmdmod_stacklen;
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
44 } funclocal_T;
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
45
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
46 // A stack is used to store:
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
47 // - arguments passed to a :def function
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
48 // - info about the calling function, to use when returning
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
49 // - local variables
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
50 // - temporary values
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
51 //
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
52 // In detail (FP == Frame Pointer):
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
53 // arg1 first argument from caller (if present)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
54 // arg2 second argument from caller (if present)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
55 // extra_arg1 any missing optional argument default value
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
56 // FP -> cur_func calling function
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
57 // current previous instruction pointer
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
58 // frame_ptr previous Frame Pointer
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
59 // var1 space for local variable
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
60 // var2 space for local variable
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
61 // .... fixed space for max. number of local variables
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
62 // temp temporary values
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
63 // .... flexible space for temporary values (can grow big)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
64
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
65 /*
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
66 * Execution context.
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
67 */
23285
112fa621b127 patch 8.2.2188: Vim9: crash when calling global function from :def function
Bram Moolenaar <Bram@vim.org>
parents: 23266
diff changeset
68 struct ectx_S {
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
69 garray_T ec_stack; // stack of typval_T values
20247
e46e72aaff74 patch 8.2.0679: Vim9: incomplete support for closures
Bram Moolenaar <Bram@vim.org>
parents: 20244
diff changeset
70 int ec_frame_idx; // index in ec_stack: context of ec_dfunc_idx
24488
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
71 int ec_initial_frame_idx; // frame index when called
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
72
23559
64dfb69e7d46 patch 8.2.2322: Vim9: closure nested limiting to one level
Bram Moolenaar <Bram@vim.org>
parents: 23557
diff changeset
73 outer_T *ec_outer; // outer scope used for closures, allocated
24488
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
74 funclocal_T ec_funclocal;
20244
23d75968ca5e patch 8.2.0677: Vim9: no support for closures
Bram Moolenaar <Bram@vim.org>
parents: 20225
diff changeset
75
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
76 garray_T ec_trystack; // stack of trycmd_T values
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
77 int ec_in_catch; // when TRUE in catch or finally block
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
78
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
79 int ec_dfunc_idx; // current function index
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
80 isn_T *ec_instr; // array with instructions
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
81 int ec_iidx; // index in ec_instr: instruction to execute
22371
15003353a464 patch 8.2.1734: Vim9: cannot use a funcref for a closure twice
Bram Moolenaar <Bram@vim.org>
parents: 22324
diff changeset
82
15003353a464 patch 8.2.1734: Vim9: cannot use a funcref for a closure twice
Bram Moolenaar <Bram@vim.org>
parents: 22324
diff changeset
83 garray_T ec_funcrefs; // partials that might be a closure
24488
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
84
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
85 int ec_did_emsg_before;
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
86 int ec_trylevel_at_start;
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
87 where_T ec_where;
23285
112fa621b127 patch 8.2.2188: Vim9: crash when calling global function from :def function
Bram Moolenaar <Bram@vim.org>
parents: 23266
diff changeset
88 };
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
89
23976
03819ebd3e6d patch 8.2.2530: Vim9: not enough testing for profiling
Bram Moolenaar <Bram@vim.org>
parents: 23934
diff changeset
90 #ifdef FEAT_PROFILE
03819ebd3e6d patch 8.2.2530: Vim9: not enough testing for profiling
Bram Moolenaar <Bram@vim.org>
parents: 23934
diff changeset
91 // stack of profinfo_T used when profiling.
03819ebd3e6d patch 8.2.2530: Vim9: not enough testing for profiling
Bram Moolenaar <Bram@vim.org>
parents: 23934
diff changeset
92 static garray_T profile_info_ga = {0, 0, sizeof(profinfo_T), 20, NULL};
03819ebd3e6d patch 8.2.2530: Vim9: not enough testing for profiling
Bram Moolenaar <Bram@vim.org>
parents: 23934
diff changeset
93 #endif
03819ebd3e6d patch 8.2.2530: Vim9: not enough testing for profiling
Bram Moolenaar <Bram@vim.org>
parents: 23934
diff changeset
94
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
95 // Get pointer to item relative to the bottom of the stack, -1 is the last one.
21826
ccad66ac6c3e patch 8.2.1462: Vim9: string slice not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 21823
diff changeset
96 #define STACK_TV_BOT(idx) (((typval_T *)ectx->ec_stack.ga_data) + ectx->ec_stack.ga_len + (idx))
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
97
21771
fcf978444298 patch 8.2.1435: Vim9: always converting to string for ".." leads to mistakes
Bram Moolenaar <Bram@vim.org>
parents: 21757
diff changeset
98 void
fcf978444298 patch 8.2.1435: Vim9: always converting to string for ".." leads to mistakes
Bram Moolenaar <Bram@vim.org>
parents: 21757
diff changeset
99 to_string_error(vartype_T vartype)
fcf978444298 patch 8.2.1435: Vim9: always converting to string for ".." leads to mistakes
Bram Moolenaar <Bram@vim.org>
parents: 21757
diff changeset
100 {
21821
0deb6f96a5a3 patch 8.2.1460: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents: 21815
diff changeset
101 semsg(_(e_cannot_convert_str_to_string), vartype_name(vartype));
21771
fcf978444298 patch 8.2.1435: Vim9: always converting to string for ".." leads to mistakes
Bram Moolenaar <Bram@vim.org>
parents: 21757
diff changeset
102 }
fcf978444298 patch 8.2.1435: Vim9: always converting to string for ".." leads to mistakes
Bram Moolenaar <Bram@vim.org>
parents: 21757
diff changeset
103
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
104 /*
19328
e99e6d794597 patch 8.2.0222: Vim9: optional function arguments don't work yet
Bram Moolenaar <Bram@vim.org>
parents: 19316
diff changeset
105 * Return the number of arguments, including optional arguments and any vararg.
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
106 */
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
107 static int
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
108 ufunc_argcount(ufunc_T *ufunc)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
109 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
110 return ufunc->uf_args.ga_len + (ufunc->uf_va_name != NULL ? 1 : 0);
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
111 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
112
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
113 /*
19981
014daa59ba50 patch 8.2.0546: Vim9: varargs implementation is inefficient
Bram Moolenaar <Bram@vim.org>
parents: 19975
diff changeset
114 * Create a new list from "count" items at the bottom of the stack.
014daa59ba50 patch 8.2.0546: Vim9: varargs implementation is inefficient
Bram Moolenaar <Bram@vim.org>
parents: 19975
diff changeset
115 * When "count" is zero an empty list is added to the stack.
014daa59ba50 patch 8.2.0546: Vim9: varargs implementation is inefficient
Bram Moolenaar <Bram@vim.org>
parents: 19975
diff changeset
116 */
014daa59ba50 patch 8.2.0546: Vim9: varargs implementation is inefficient
Bram Moolenaar <Bram@vim.org>
parents: 19975
diff changeset
117 static int
014daa59ba50 patch 8.2.0546: Vim9: varargs implementation is inefficient
Bram Moolenaar <Bram@vim.org>
parents: 19975
diff changeset
118 exe_newlist(int count, ectx_T *ectx)
014daa59ba50 patch 8.2.0546: Vim9: varargs implementation is inefficient
Bram Moolenaar <Bram@vim.org>
parents: 19975
diff changeset
119 {
014daa59ba50 patch 8.2.0546: Vim9: varargs implementation is inefficient
Bram Moolenaar <Bram@vim.org>
parents: 19975
diff changeset
120 list_T *list = list_alloc_with_items(count);
014daa59ba50 patch 8.2.0546: Vim9: varargs implementation is inefficient
Bram Moolenaar <Bram@vim.org>
parents: 19975
diff changeset
121 int idx;
014daa59ba50 patch 8.2.0546: Vim9: varargs implementation is inefficient
Bram Moolenaar <Bram@vim.org>
parents: 19975
diff changeset
122 typval_T *tv;
014daa59ba50 patch 8.2.0546: Vim9: varargs implementation is inefficient
Bram Moolenaar <Bram@vim.org>
parents: 19975
diff changeset
123
014daa59ba50 patch 8.2.0546: Vim9: varargs implementation is inefficient
Bram Moolenaar <Bram@vim.org>
parents: 19975
diff changeset
124 if (list == NULL)
014daa59ba50 patch 8.2.0546: Vim9: varargs implementation is inefficient
Bram Moolenaar <Bram@vim.org>
parents: 19975
diff changeset
125 return FAIL;
014daa59ba50 patch 8.2.0546: Vim9: varargs implementation is inefficient
Bram Moolenaar <Bram@vim.org>
parents: 19975
diff changeset
126 for (idx = 0; idx < count; ++idx)
014daa59ba50 patch 8.2.0546: Vim9: varargs implementation is inefficient
Bram Moolenaar <Bram@vim.org>
parents: 19975
diff changeset
127 list_set_item(list, idx, STACK_TV_BOT(idx - count));
014daa59ba50 patch 8.2.0546: Vim9: varargs implementation is inefficient
Bram Moolenaar <Bram@vim.org>
parents: 19975
diff changeset
128
014daa59ba50 patch 8.2.0546: Vim9: varargs implementation is inefficient
Bram Moolenaar <Bram@vim.org>
parents: 19975
diff changeset
129 if (count > 0)
014daa59ba50 patch 8.2.0546: Vim9: varargs implementation is inefficient
Bram Moolenaar <Bram@vim.org>
parents: 19975
diff changeset
130 ectx->ec_stack.ga_len -= count - 1;
20409
fd1b6f4f497e patch 8.2.0759: Vim9: missing changes for performance improvements
Bram Moolenaar <Bram@vim.org>
parents: 20353
diff changeset
131 else if (GA_GROW(&ectx->ec_stack, 1) == FAIL)
19981
014daa59ba50 patch 8.2.0546: Vim9: varargs implementation is inefficient
Bram Moolenaar <Bram@vim.org>
parents: 19975
diff changeset
132 return FAIL;
014daa59ba50 patch 8.2.0546: Vim9: varargs implementation is inefficient
Bram Moolenaar <Bram@vim.org>
parents: 19975
diff changeset
133 else
014daa59ba50 patch 8.2.0546: Vim9: varargs implementation is inefficient
Bram Moolenaar <Bram@vim.org>
parents: 19975
diff changeset
134 ++ectx->ec_stack.ga_len;
014daa59ba50 patch 8.2.0546: Vim9: varargs implementation is inefficient
Bram Moolenaar <Bram@vim.org>
parents: 19975
diff changeset
135 tv = STACK_TV_BOT(-1);
014daa59ba50 patch 8.2.0546: Vim9: varargs implementation is inefficient
Bram Moolenaar <Bram@vim.org>
parents: 19975
diff changeset
136 tv->v_type = VAR_LIST;
014daa59ba50 patch 8.2.0546: Vim9: varargs implementation is inefficient
Bram Moolenaar <Bram@vim.org>
parents: 19975
diff changeset
137 tv->vval.v_list = list;
014daa59ba50 patch 8.2.0546: Vim9: varargs implementation is inefficient
Bram Moolenaar <Bram@vim.org>
parents: 19975
diff changeset
138 ++list->lv_refcount;
014daa59ba50 patch 8.2.0546: Vim9: varargs implementation is inefficient
Bram Moolenaar <Bram@vim.org>
parents: 19975
diff changeset
139 return OK;
014daa59ba50 patch 8.2.0546: Vim9: varargs implementation is inefficient
Bram Moolenaar <Bram@vim.org>
parents: 19975
diff changeset
140 }
014daa59ba50 patch 8.2.0546: Vim9: varargs implementation is inefficient
Bram Moolenaar <Bram@vim.org>
parents: 19975
diff changeset
141
014daa59ba50 patch 8.2.0546: Vim9: varargs implementation is inefficient
Bram Moolenaar <Bram@vim.org>
parents: 19975
diff changeset
142 /*
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
143 * Call compiled function "cdf_idx" from compiled code.
23557
f50ee1ae4d9b patch 8.2.2321: Vim9: cannot nest closures
Bram Moolenaar <Bram@vim.org>
parents: 23553
diff changeset
144 * This adds a stack frame and sets the instruction pointer to the start of the
f50ee1ae4d9b patch 8.2.2321: Vim9: cannot nest closures
Bram Moolenaar <Bram@vim.org>
parents: 23553
diff changeset
145 * called function.
23559
64dfb69e7d46 patch 8.2.2322: Vim9: closure nested limiting to one level
Bram Moolenaar <Bram@vim.org>
parents: 23557
diff changeset
146 * If "pt" is not null use "pt->pt_outer" for ec_outer.
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
147 *
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
148 * Stack has:
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
149 * - current arguments (already there)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
150 * - omitted optional argument (default values) added here
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
151 * - stack frame:
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
152 * - pointer to calling function
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
153 * - Index of next instruction in calling function
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
154 * - previous frame pointer
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
155 * - reserved space for local variables
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
156 */
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
157 static int
24218
40e27d96e395 patch 8.2.2650: Vim9: command modifiers not handled in nested function
Bram Moolenaar <Bram@vim.org>
parents: 24146
diff changeset
158 call_dfunc(
40e27d96e395 patch 8.2.2650: Vim9: command modifiers not handled in nested function
Bram Moolenaar <Bram@vim.org>
parents: 24146
diff changeset
159 int cdf_idx,
40e27d96e395 patch 8.2.2650: Vim9: command modifiers not handled in nested function
Bram Moolenaar <Bram@vim.org>
parents: 24146
diff changeset
160 partial_T *pt,
40e27d96e395 patch 8.2.2650: Vim9: command modifiers not handled in nested function
Bram Moolenaar <Bram@vim.org>
parents: 24146
diff changeset
161 int argcount_arg,
40e27d96e395 patch 8.2.2650: Vim9: command modifiers not handled in nested function
Bram Moolenaar <Bram@vim.org>
parents: 24146
diff changeset
162 ectx_T *ectx)
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
163 {
24218
40e27d96e395 patch 8.2.2650: Vim9: command modifiers not handled in nested function
Bram Moolenaar <Bram@vim.org>
parents: 24146
diff changeset
164 int argcount = argcount_arg;
40e27d96e395 patch 8.2.2650: Vim9: command modifiers not handled in nested function
Bram Moolenaar <Bram@vim.org>
parents: 24146
diff changeset
165 dfunc_T *dfunc = ((dfunc_T *)def_functions.ga_data) + cdf_idx;
40e27d96e395 patch 8.2.2650: Vim9: command modifiers not handled in nested function
Bram Moolenaar <Bram@vim.org>
parents: 24146
diff changeset
166 ufunc_T *ufunc = dfunc->df_ufunc;
40e27d96e395 patch 8.2.2650: Vim9: command modifiers not handled in nested function
Bram Moolenaar <Bram@vim.org>
parents: 24146
diff changeset
167 int arg_to_add;
40e27d96e395 patch 8.2.2650: Vim9: command modifiers not handled in nested function
Bram Moolenaar <Bram@vim.org>
parents: 24146
diff changeset
168 int vararg_count = 0;
40e27d96e395 patch 8.2.2650: Vim9: command modifiers not handled in nested function
Bram Moolenaar <Bram@vim.org>
parents: 24146
diff changeset
169 int varcount;
40e27d96e395 patch 8.2.2650: Vim9: command modifiers not handled in nested function
Bram Moolenaar <Bram@vim.org>
parents: 24146
diff changeset
170 int idx;
40e27d96e395 patch 8.2.2650: Vim9: command modifiers not handled in nested function
Bram Moolenaar <Bram@vim.org>
parents: 24146
diff changeset
171 estack_T *entry;
40e27d96e395 patch 8.2.2650: Vim9: command modifiers not handled in nested function
Bram Moolenaar <Bram@vim.org>
parents: 24146
diff changeset
172 funclocal_T *floc = NULL;
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
173
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
174 if (dfunc->df_deleted)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
175 {
23285
112fa621b127 patch 8.2.2188: Vim9: crash when calling global function from :def function
Bram Moolenaar <Bram@vim.org>
parents: 23266
diff changeset
176 // don't use ufunc->uf_name, it may have been freed
112fa621b127 patch 8.2.2188: Vim9: crash when calling global function from :def function
Bram Moolenaar <Bram@vim.org>
parents: 23266
diff changeset
177 emsg_funcname(e_func_deleted,
112fa621b127 patch 8.2.2188: Vim9: crash when calling global function from :def function
Bram Moolenaar <Bram@vim.org>
parents: 23266
diff changeset
178 dfunc->df_name == NULL ? (char_u *)"unknown" : dfunc->df_name);
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
179 return FAIL;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
180 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
181
23735
7caffd835aa1 patch 8.2.2409: Vim9: profiling only works for one function
Bram Moolenaar <Bram@vim.org>
parents: 23725
diff changeset
182 #ifdef FEAT_PROFILE
23976
03819ebd3e6d patch 8.2.2530: Vim9: not enough testing for profiling
Bram Moolenaar <Bram@vim.org>
parents: 23934
diff changeset
183 if (do_profiling == PROF_YES)
03819ebd3e6d patch 8.2.2530: Vim9: not enough testing for profiling
Bram Moolenaar <Bram@vim.org>
parents: 23934
diff changeset
184 {
03819ebd3e6d patch 8.2.2530: Vim9: not enough testing for profiling
Bram Moolenaar <Bram@vim.org>
parents: 23934
diff changeset
185 if (ga_grow(&profile_info_ga, 1) == OK)
03819ebd3e6d patch 8.2.2530: Vim9: not enough testing for profiling
Bram Moolenaar <Bram@vim.org>
parents: 23934
diff changeset
186 {
03819ebd3e6d patch 8.2.2530: Vim9: not enough testing for profiling
Bram Moolenaar <Bram@vim.org>
parents: 23934
diff changeset
187 profinfo_T *info = ((profinfo_T *)profile_info_ga.ga_data)
03819ebd3e6d patch 8.2.2530: Vim9: not enough testing for profiling
Bram Moolenaar <Bram@vim.org>
parents: 23934
diff changeset
188 + profile_info_ga.ga_len;
03819ebd3e6d patch 8.2.2530: Vim9: not enough testing for profiling
Bram Moolenaar <Bram@vim.org>
parents: 23934
diff changeset
189 ++profile_info_ga.ga_len;
03819ebd3e6d patch 8.2.2530: Vim9: not enough testing for profiling
Bram Moolenaar <Bram@vim.org>
parents: 23934
diff changeset
190 CLEAR_POINTER(info);
03819ebd3e6d patch 8.2.2530: Vim9: not enough testing for profiling
Bram Moolenaar <Bram@vim.org>
parents: 23934
diff changeset
191 profile_may_start_func(info, ufunc,
03819ebd3e6d patch 8.2.2530: Vim9: not enough testing for profiling
Bram Moolenaar <Bram@vim.org>
parents: 23934
diff changeset
192 (((dfunc_T *)def_functions.ga_data)
03819ebd3e6d patch 8.2.2530: Vim9: not enough testing for profiling
Bram Moolenaar <Bram@vim.org>
parents: 23934
diff changeset
193 + ectx->ec_dfunc_idx)->df_ufunc);
03819ebd3e6d patch 8.2.2530: Vim9: not enough testing for profiling
Bram Moolenaar <Bram@vim.org>
parents: 23934
diff changeset
194 }
03819ebd3e6d patch 8.2.2530: Vim9: not enough testing for profiling
Bram Moolenaar <Bram@vim.org>
parents: 23934
diff changeset
195
03819ebd3e6d patch 8.2.2530: Vim9: not enough testing for profiling
Bram Moolenaar <Bram@vim.org>
parents: 23934
diff changeset
196 // Profiling might be enabled/disabled along the way. This should not
03819ebd3e6d patch 8.2.2530: Vim9: not enough testing for profiling
Bram Moolenaar <Bram@vim.org>
parents: 23934
diff changeset
197 // fail, since the function was compiled before and toggling profiling
03819ebd3e6d patch 8.2.2530: Vim9: not enough testing for profiling
Bram Moolenaar <Bram@vim.org>
parents: 23934
diff changeset
198 // doesn't change any errors.
03819ebd3e6d patch 8.2.2530: Vim9: not enough testing for profiling
Bram Moolenaar <Bram@vim.org>
parents: 23934
diff changeset
199 if (func_needs_compiling(ufunc, PROFILING(ufunc))
03819ebd3e6d patch 8.2.2530: Vim9: not enough testing for profiling
Bram Moolenaar <Bram@vim.org>
parents: 23934
diff changeset
200 && compile_def_function(ufunc, FALSE, PROFILING(ufunc), NULL)
23735
7caffd835aa1 patch 8.2.2409: Vim9: profiling only works for one function
Bram Moolenaar <Bram@vim.org>
parents: 23725
diff changeset
201 == FAIL)
23976
03819ebd3e6d patch 8.2.2530: Vim9: not enough testing for profiling
Bram Moolenaar <Bram@vim.org>
parents: 23934
diff changeset
202 return FAIL;
03819ebd3e6d patch 8.2.2530: Vim9: not enough testing for profiling
Bram Moolenaar <Bram@vim.org>
parents: 23934
diff changeset
203 }
23735
7caffd835aa1 patch 8.2.2409: Vim9: profiling only works for one function
Bram Moolenaar <Bram@vim.org>
parents: 23725
diff changeset
204 #endif
7caffd835aa1 patch 8.2.2409: Vim9: profiling only works for one function
Bram Moolenaar <Bram@vim.org>
parents: 23725
diff changeset
205
19975
4e8e0ce576af patch 8.2.0543: Vim9: function with varargs does not work properly
Bram Moolenaar <Bram@vim.org>
parents: 19964
diff changeset
206 if (ufunc->uf_va_name != NULL)
4e8e0ce576af patch 8.2.0543: Vim9: function with varargs does not work properly
Bram Moolenaar <Bram@vim.org>
parents: 19964
diff changeset
207 {
19981
014daa59ba50 patch 8.2.0546: Vim9: varargs implementation is inefficient
Bram Moolenaar <Bram@vim.org>
parents: 19975
diff changeset
208 // Need to make a list out of the vararg arguments.
19975
4e8e0ce576af patch 8.2.0543: Vim9: function with varargs does not work properly
Bram Moolenaar <Bram@vim.org>
parents: 19964
diff changeset
209 // Stack at time of call with 2 varargs:
4e8e0ce576af patch 8.2.0543: Vim9: function with varargs does not work properly
Bram Moolenaar <Bram@vim.org>
parents: 19964
diff changeset
210 // normal_arg
4e8e0ce576af patch 8.2.0543: Vim9: function with varargs does not work properly
Bram Moolenaar <Bram@vim.org>
parents: 19964
diff changeset
211 // optional_arg
4e8e0ce576af patch 8.2.0543: Vim9: function with varargs does not work properly
Bram Moolenaar <Bram@vim.org>
parents: 19964
diff changeset
212 // vararg_1
4e8e0ce576af patch 8.2.0543: Vim9: function with varargs does not work properly
Bram Moolenaar <Bram@vim.org>
parents: 19964
diff changeset
213 // vararg_2
19981
014daa59ba50 patch 8.2.0546: Vim9: varargs implementation is inefficient
Bram Moolenaar <Bram@vim.org>
parents: 19975
diff changeset
214 // After creating the list:
014daa59ba50 patch 8.2.0546: Vim9: varargs implementation is inefficient
Bram Moolenaar <Bram@vim.org>
parents: 19975
diff changeset
215 // normal_arg
014daa59ba50 patch 8.2.0546: Vim9: varargs implementation is inefficient
Bram Moolenaar <Bram@vim.org>
parents: 19975
diff changeset
216 // optional_arg
014daa59ba50 patch 8.2.0546: Vim9: varargs implementation is inefficient
Bram Moolenaar <Bram@vim.org>
parents: 19975
diff changeset
217 // vararg-list
014daa59ba50 patch 8.2.0546: Vim9: varargs implementation is inefficient
Bram Moolenaar <Bram@vim.org>
parents: 19975
diff changeset
218 // With missing optional arguments we get:
19975
4e8e0ce576af patch 8.2.0543: Vim9: function with varargs does not work properly
Bram Moolenaar <Bram@vim.org>
parents: 19964
diff changeset
219 // normal_arg
19981
014daa59ba50 patch 8.2.0546: Vim9: varargs implementation is inefficient
Bram Moolenaar <Bram@vim.org>
parents: 19975
diff changeset
220 // After creating the list
014daa59ba50 patch 8.2.0546: Vim9: varargs implementation is inefficient
Bram Moolenaar <Bram@vim.org>
parents: 19975
diff changeset
221 // normal_arg
014daa59ba50 patch 8.2.0546: Vim9: varargs implementation is inefficient
Bram Moolenaar <Bram@vim.org>
parents: 19975
diff changeset
222 // (space for optional_arg)
014daa59ba50 patch 8.2.0546: Vim9: varargs implementation is inefficient
Bram Moolenaar <Bram@vim.org>
parents: 19975
diff changeset
223 // vararg-list
19975
4e8e0ce576af patch 8.2.0543: Vim9: function with varargs does not work properly
Bram Moolenaar <Bram@vim.org>
parents: 19964
diff changeset
224 vararg_count = argcount - ufunc->uf_args.ga_len;
4e8e0ce576af patch 8.2.0543: Vim9: function with varargs does not work properly
Bram Moolenaar <Bram@vim.org>
parents: 19964
diff changeset
225 if (vararg_count < 0)
4e8e0ce576af patch 8.2.0543: Vim9: function with varargs does not work properly
Bram Moolenaar <Bram@vim.org>
parents: 19964
diff changeset
226 vararg_count = 0;
4e8e0ce576af patch 8.2.0543: Vim9: function with varargs does not work properly
Bram Moolenaar <Bram@vim.org>
parents: 19964
diff changeset
227 else
4e8e0ce576af patch 8.2.0543: Vim9: function with varargs does not work properly
Bram Moolenaar <Bram@vim.org>
parents: 19964
diff changeset
228 argcount -= vararg_count;
19981
014daa59ba50 patch 8.2.0546: Vim9: varargs implementation is inefficient
Bram Moolenaar <Bram@vim.org>
parents: 19975
diff changeset
229 if (exe_newlist(vararg_count, ectx) == FAIL)
19975
4e8e0ce576af patch 8.2.0543: Vim9: function with varargs does not work properly
Bram Moolenaar <Bram@vim.org>
parents: 19964
diff changeset
230 return FAIL;
19981
014daa59ba50 patch 8.2.0546: Vim9: varargs implementation is inefficient
Bram Moolenaar <Bram@vim.org>
parents: 19975
diff changeset
231
014daa59ba50 patch 8.2.0546: Vim9: varargs implementation is inefficient
Bram Moolenaar <Bram@vim.org>
parents: 19975
diff changeset
232 vararg_count = 1;
19975
4e8e0ce576af patch 8.2.0543: Vim9: function with varargs does not work properly
Bram Moolenaar <Bram@vim.org>
parents: 19964
diff changeset
233 }
4e8e0ce576af patch 8.2.0543: Vim9: function with varargs does not work properly
Bram Moolenaar <Bram@vim.org>
parents: 19964
diff changeset
234
19981
014daa59ba50 patch 8.2.0546: Vim9: varargs implementation is inefficient
Bram Moolenaar <Bram@vim.org>
parents: 19975
diff changeset
235 arg_to_add = ufunc->uf_args.ga_len - argcount;
19975
4e8e0ce576af patch 8.2.0543: Vim9: function with varargs does not work properly
Bram Moolenaar <Bram@vim.org>
parents: 19964
diff changeset
236 if (arg_to_add < 0)
4e8e0ce576af patch 8.2.0543: Vim9: function with varargs does not work properly
Bram Moolenaar <Bram@vim.org>
parents: 19964
diff changeset
237 {
21809
15ed135796fd patch 8.2.1454: Vim9: failure invoking lambda with wrong arguments
Bram Moolenaar <Bram@vim.org>
parents: 21793
diff changeset
238 if (arg_to_add == -1)
21821
0deb6f96a5a3 patch 8.2.1460: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents: 21815
diff changeset
239 emsg(_(e_one_argument_too_many));
21809
15ed135796fd patch 8.2.1454: Vim9: failure invoking lambda with wrong arguments
Bram Moolenaar <Bram@vim.org>
parents: 21793
diff changeset
240 else
21821
0deb6f96a5a3 patch 8.2.1460: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents: 21815
diff changeset
241 semsg(_(e_nr_arguments_too_many), -arg_to_add);
19975
4e8e0ce576af patch 8.2.0543: Vim9: function with varargs does not work properly
Bram Moolenaar <Bram@vim.org>
parents: 19964
diff changeset
242 return FAIL;
4e8e0ce576af patch 8.2.0543: Vim9: function with varargs does not work properly
Bram Moolenaar <Bram@vim.org>
parents: 19964
diff changeset
243 }
22371
15003353a464 patch 8.2.1734: Vim9: cannot use a funcref for a closure twice
Bram Moolenaar <Bram@vim.org>
parents: 22324
diff changeset
244
15003353a464 patch 8.2.1734: Vim9: cannot use a funcref for a closure twice
Bram Moolenaar <Bram@vim.org>
parents: 22324
diff changeset
245 // Reserve space for:
15003353a464 patch 8.2.1734: Vim9: cannot use a funcref for a closure twice
Bram Moolenaar <Bram@vim.org>
parents: 22324
diff changeset
246 // - missing arguments
15003353a464 patch 8.2.1734: Vim9: cannot use a funcref for a closure twice
Bram Moolenaar <Bram@vim.org>
parents: 22324
diff changeset
247 // - stack frame
15003353a464 patch 8.2.1734: Vim9: cannot use a funcref for a closure twice
Bram Moolenaar <Bram@vim.org>
parents: 22324
diff changeset
248 // - local variables
15003353a464 patch 8.2.1734: Vim9: cannot use a funcref for a closure twice
Bram Moolenaar <Bram@vim.org>
parents: 22324
diff changeset
249 // - if needed: a counter for number of closures created in
15003353a464 patch 8.2.1734: Vim9: cannot use a funcref for a closure twice
Bram Moolenaar <Bram@vim.org>
parents: 22324
diff changeset
250 // ectx->ec_funcrefs.
15003353a464 patch 8.2.1734: Vim9: cannot use a funcref for a closure twice
Bram Moolenaar <Bram@vim.org>
parents: 22324
diff changeset
251 varcount = dfunc->df_varcount + dfunc->df_has_closure;
15003353a464 patch 8.2.1734: Vim9: cannot use a funcref for a closure twice
Bram Moolenaar <Bram@vim.org>
parents: 22324
diff changeset
252 if (ga_grow(&ectx->ec_stack, arg_to_add + STACK_FRAME_SIZE + varcount)
15003353a464 patch 8.2.1734: Vim9: cannot use a funcref for a closure twice
Bram Moolenaar <Bram@vim.org>
parents: 22324
diff changeset
253 == FAIL)
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
254 return FAIL;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
255
22908
54219df706b5 patch 8.2.2001: Vim9: :def function does not apply 'maxfuncdepth'
Bram Moolenaar <Bram@vim.org>
parents: 22860
diff changeset
256 // If depth of calling is getting too high, don't execute the function.
54219df706b5 patch 8.2.2001: Vim9: :def function does not apply 'maxfuncdepth'
Bram Moolenaar <Bram@vim.org>
parents: 22860
diff changeset
257 if (funcdepth_increment() == FAIL)
54219df706b5 patch 8.2.2001: Vim9: :def function does not apply 'maxfuncdepth'
Bram Moolenaar <Bram@vim.org>
parents: 22860
diff changeset
258 return FAIL;
54219df706b5 patch 8.2.2001: Vim9: :def function does not apply 'maxfuncdepth'
Bram Moolenaar <Bram@vim.org>
parents: 22860
diff changeset
259
24218
40e27d96e395 patch 8.2.2650: Vim9: command modifiers not handled in nested function
Bram Moolenaar <Bram@vim.org>
parents: 24146
diff changeset
260 // Only make a copy of funclocal if it contains something to restore.
24488
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
261 if (ectx->ec_funclocal.floc_restore_cmdmod)
24218
40e27d96e395 patch 8.2.2650: Vim9: command modifiers not handled in nested function
Bram Moolenaar <Bram@vim.org>
parents: 24146
diff changeset
262 {
40e27d96e395 patch 8.2.2650: Vim9: command modifiers not handled in nested function
Bram Moolenaar <Bram@vim.org>
parents: 24146
diff changeset
263 floc = ALLOC_ONE(funclocal_T);
40e27d96e395 patch 8.2.2650: Vim9: command modifiers not handled in nested function
Bram Moolenaar <Bram@vim.org>
parents: 24146
diff changeset
264 if (floc == NULL)
40e27d96e395 patch 8.2.2650: Vim9: command modifiers not handled in nested function
Bram Moolenaar <Bram@vim.org>
parents: 24146
diff changeset
265 return FAIL;
24488
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
266 *floc = ectx->ec_funclocal;
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
267 ectx->ec_funclocal.floc_restore_cmdmod = FALSE;
24218
40e27d96e395 patch 8.2.2650: Vim9: command modifiers not handled in nested function
Bram Moolenaar <Bram@vim.org>
parents: 24146
diff changeset
268 }
40e27d96e395 patch 8.2.2650: Vim9: command modifiers not handled in nested function
Bram Moolenaar <Bram@vim.org>
parents: 24146
diff changeset
269
19981
014daa59ba50 patch 8.2.0546: Vim9: varargs implementation is inefficient
Bram Moolenaar <Bram@vim.org>
parents: 19975
diff changeset
270 // Move the vararg-list to below the missing optional arguments.
014daa59ba50 patch 8.2.0546: Vim9: varargs implementation is inefficient
Bram Moolenaar <Bram@vim.org>
parents: 19975
diff changeset
271 if (vararg_count > 0 && arg_to_add > 0)
014daa59ba50 patch 8.2.0546: Vim9: varargs implementation is inefficient
Bram Moolenaar <Bram@vim.org>
parents: 19975
diff changeset
272 *STACK_TV_BOT(arg_to_add - 1) = *STACK_TV_BOT(-1);
19328
e99e6d794597 patch 8.2.0222: Vim9: optional function arguments don't work yet
Bram Moolenaar <Bram@vim.org>
parents: 19316
diff changeset
273
e99e6d794597 patch 8.2.0222: Vim9: optional function arguments don't work yet
Bram Moolenaar <Bram@vim.org>
parents: 19316
diff changeset
274 // Reserve space for omitted optional arguments, filled in soon.
19975
4e8e0ce576af patch 8.2.0543: Vim9: function with varargs does not work properly
Bram Moolenaar <Bram@vim.org>
parents: 19964
diff changeset
275 for (idx = 0; idx < arg_to_add; ++idx)
19981
014daa59ba50 patch 8.2.0546: Vim9: varargs implementation is inefficient
Bram Moolenaar <Bram@vim.org>
parents: 19975
diff changeset
276 STACK_TV_BOT(idx - vararg_count)->v_type = VAR_UNKNOWN;
19975
4e8e0ce576af patch 8.2.0543: Vim9: function with varargs does not work properly
Bram Moolenaar <Bram@vim.org>
parents: 19964
diff changeset
277 ectx->ec_stack.ga_len += arg_to_add;
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
278
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
279 // Store current execution state in stack frame for ISN_RETURN.
23559
64dfb69e7d46 patch 8.2.2322: Vim9: closure nested limiting to one level
Bram Moolenaar <Bram@vim.org>
parents: 23557
diff changeset
280 STACK_TV_BOT(STACK_FRAME_FUNC_OFF)->vval.v_number = ectx->ec_dfunc_idx;
64dfb69e7d46 patch 8.2.2322: Vim9: closure nested limiting to one level
Bram Moolenaar <Bram@vim.org>
parents: 23557
diff changeset
281 STACK_TV_BOT(STACK_FRAME_IIDX_OFF)->vval.v_number = ectx->ec_iidx;
24545
fe29b220eece patch 8.2.2812: Vim9: still crash when using substitute expression
Bram Moolenaar <Bram@vim.org>
parents: 24541
diff changeset
282 STACK_TV_BOT(STACK_FRAME_INSTR_OFF)->vval.v_string = (void *)ectx->ec_instr;
23559
64dfb69e7d46 patch 8.2.2322: Vim9: closure nested limiting to one level
Bram Moolenaar <Bram@vim.org>
parents: 23557
diff changeset
283 STACK_TV_BOT(STACK_FRAME_OUTER_OFF)->vval.v_string = (void *)ectx->ec_outer;
24218
40e27d96e395 patch 8.2.2650: Vim9: command modifiers not handled in nested function
Bram Moolenaar <Bram@vim.org>
parents: 24146
diff changeset
284 STACK_TV_BOT(STACK_FRAME_FUNCLOCAL_OFF)->vval.v_string = (void *)floc;
23559
64dfb69e7d46 patch 8.2.2322: Vim9: closure nested limiting to one level
Bram Moolenaar <Bram@vim.org>
parents: 23557
diff changeset
285 STACK_TV_BOT(STACK_FRAME_IDX_OFF)->vval.v_number = ectx->ec_frame_idx;
20247
e46e72aaff74 patch 8.2.0679: Vim9: incomplete support for closures
Bram Moolenaar <Bram@vim.org>
parents: 20244
diff changeset
286 ectx->ec_frame_idx = ectx->ec_stack.ga_len;
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
287
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
288 // Initialize local variables
22371
15003353a464 patch 8.2.1734: Vim9: cannot use a funcref for a closure twice
Bram Moolenaar <Bram@vim.org>
parents: 22324
diff changeset
289 for (idx = 0; idx < dfunc->df_varcount; ++idx)
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
290 STACK_TV_BOT(STACK_FRAME_SIZE + idx)->v_type = VAR_UNKNOWN;
22371
15003353a464 patch 8.2.1734: Vim9: cannot use a funcref for a closure twice
Bram Moolenaar <Bram@vim.org>
parents: 22324
diff changeset
291 if (dfunc->df_has_closure)
15003353a464 patch 8.2.1734: Vim9: cannot use a funcref for a closure twice
Bram Moolenaar <Bram@vim.org>
parents: 22324
diff changeset
292 {
15003353a464 patch 8.2.1734: Vim9: cannot use a funcref for a closure twice
Bram Moolenaar <Bram@vim.org>
parents: 22324
diff changeset
293 typval_T *tv = STACK_TV_BOT(STACK_FRAME_SIZE + dfunc->df_varcount);
15003353a464 patch 8.2.1734: Vim9: cannot use a funcref for a closure twice
Bram Moolenaar <Bram@vim.org>
parents: 22324
diff changeset
294
15003353a464 patch 8.2.1734: Vim9: cannot use a funcref for a closure twice
Bram Moolenaar <Bram@vim.org>
parents: 22324
diff changeset
295 tv->v_type = VAR_NUMBER;
15003353a464 patch 8.2.1734: Vim9: cannot use a funcref for a closure twice
Bram Moolenaar <Bram@vim.org>
parents: 22324
diff changeset
296 tv->vval.v_number = 0;
15003353a464 patch 8.2.1734: Vim9: cannot use a funcref for a closure twice
Bram Moolenaar <Bram@vim.org>
parents: 22324
diff changeset
297 }
15003353a464 patch 8.2.1734: Vim9: cannot use a funcref for a closure twice
Bram Moolenaar <Bram@vim.org>
parents: 22324
diff changeset
298 ectx->ec_stack.ga_len += STACK_FRAME_SIZE + varcount;
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
299
23699
317018f62643 patch 8.2.2391: memory leak when creating a global function with closure
Bram Moolenaar <Bram@vim.org>
parents: 23697
diff changeset
300 if (pt != NULL || ufunc->uf_partial != NULL
317018f62643 patch 8.2.2391: memory leak when creating a global function with closure
Bram Moolenaar <Bram@vim.org>
parents: 23697
diff changeset
301 || (ufunc->uf_flags & FC_CLOSURE))
23285
112fa621b127 patch 8.2.2188: Vim9: crash when calling global function from :def function
Bram Moolenaar <Bram@vim.org>
parents: 23266
diff changeset
302 {
23559
64dfb69e7d46 patch 8.2.2322: Vim9: closure nested limiting to one level
Bram Moolenaar <Bram@vim.org>
parents: 23557
diff changeset
303 outer_T *outer = ALLOC_CLEAR_ONE(outer_T);
64dfb69e7d46 patch 8.2.2322: Vim9: closure nested limiting to one level
Bram Moolenaar <Bram@vim.org>
parents: 23557
diff changeset
304
64dfb69e7d46 patch 8.2.2322: Vim9: closure nested limiting to one level
Bram Moolenaar <Bram@vim.org>
parents: 23557
diff changeset
305 if (outer == NULL)
64dfb69e7d46 patch 8.2.2322: Vim9: closure nested limiting to one level
Bram Moolenaar <Bram@vim.org>
parents: 23557
diff changeset
306 return FAIL;
64dfb69e7d46 patch 8.2.2322: Vim9: closure nested limiting to one level
Bram Moolenaar <Bram@vim.org>
parents: 23557
diff changeset
307 if (pt != NULL)
64dfb69e7d46 patch 8.2.2322: Vim9: closure nested limiting to one level
Bram Moolenaar <Bram@vim.org>
parents: 23557
diff changeset
308 {
64dfb69e7d46 patch 8.2.2322: Vim9: closure nested limiting to one level
Bram Moolenaar <Bram@vim.org>
parents: 23557
diff changeset
309 *outer = pt->pt_outer;
64dfb69e7d46 patch 8.2.2322: Vim9: closure nested limiting to one level
Bram Moolenaar <Bram@vim.org>
parents: 23557
diff changeset
310 outer->out_up_is_copy = TRUE;
64dfb69e7d46 patch 8.2.2322: Vim9: closure nested limiting to one level
Bram Moolenaar <Bram@vim.org>
parents: 23557
diff changeset
311 }
64dfb69e7d46 patch 8.2.2322: Vim9: closure nested limiting to one level
Bram Moolenaar <Bram@vim.org>
parents: 23557
diff changeset
312 else if (ufunc->uf_partial != NULL)
64dfb69e7d46 patch 8.2.2322: Vim9: closure nested limiting to one level
Bram Moolenaar <Bram@vim.org>
parents: 23557
diff changeset
313 {
64dfb69e7d46 patch 8.2.2322: Vim9: closure nested limiting to one level
Bram Moolenaar <Bram@vim.org>
parents: 23557
diff changeset
314 *outer = ufunc->uf_partial->pt_outer;
64dfb69e7d46 patch 8.2.2322: Vim9: closure nested limiting to one level
Bram Moolenaar <Bram@vim.org>
parents: 23557
diff changeset
315 outer->out_up_is_copy = TRUE;
64dfb69e7d46 patch 8.2.2322: Vim9: closure nested limiting to one level
Bram Moolenaar <Bram@vim.org>
parents: 23557
diff changeset
316 }
64dfb69e7d46 patch 8.2.2322: Vim9: closure nested limiting to one level
Bram Moolenaar <Bram@vim.org>
parents: 23557
diff changeset
317 else
64dfb69e7d46 patch 8.2.2322: Vim9: closure nested limiting to one level
Bram Moolenaar <Bram@vim.org>
parents: 23557
diff changeset
318 {
64dfb69e7d46 patch 8.2.2322: Vim9: closure nested limiting to one level
Bram Moolenaar <Bram@vim.org>
parents: 23557
diff changeset
319 outer->out_stack = &ectx->ec_stack;
64dfb69e7d46 patch 8.2.2322: Vim9: closure nested limiting to one level
Bram Moolenaar <Bram@vim.org>
parents: 23557
diff changeset
320 outer->out_frame_idx = ectx->ec_frame_idx;
64dfb69e7d46 patch 8.2.2322: Vim9: closure nested limiting to one level
Bram Moolenaar <Bram@vim.org>
parents: 23557
diff changeset
321 outer->out_up = ectx->ec_outer;
64dfb69e7d46 patch 8.2.2322: Vim9: closure nested limiting to one level
Bram Moolenaar <Bram@vim.org>
parents: 23557
diff changeset
322 }
64dfb69e7d46 patch 8.2.2322: Vim9: closure nested limiting to one level
Bram Moolenaar <Bram@vim.org>
parents: 23557
diff changeset
323 ectx->ec_outer = outer;
23557
f50ee1ae4d9b patch 8.2.2321: Vim9: cannot nest closures
Bram Moolenaar <Bram@vim.org>
parents: 23553
diff changeset
324 }
23559
64dfb69e7d46 patch 8.2.2322: Vim9: closure nested limiting to one level
Bram Moolenaar <Bram@vim.org>
parents: 23557
diff changeset
325 else
64dfb69e7d46 patch 8.2.2322: Vim9: closure nested limiting to one level
Bram Moolenaar <Bram@vim.org>
parents: 23557
diff changeset
326 ectx->ec_outer = NULL;
23285
112fa621b127 patch 8.2.2188: Vim9: crash when calling global function from :def function
Bram Moolenaar <Bram@vim.org>
parents: 23266
diff changeset
327
24146
03fc95628eb0 patch 8.2.2614: Vim9: function is deleted while executing
Bram Moolenaar <Bram@vim.org>
parents: 24128
diff changeset
328 ++ufunc->uf_calls;
03fc95628eb0 patch 8.2.2614: Vim9: function is deleted while executing
Bram Moolenaar <Bram@vim.org>
parents: 24128
diff changeset
329
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
330 // Set execution state to the start of the called function.
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
331 ectx->ec_dfunc_idx = cdf_idx;
23735
7caffd835aa1 patch 8.2.2409: Vim9: profiling only works for one function
Bram Moolenaar <Bram@vim.org>
parents: 23725
diff changeset
332 ectx->ec_instr = INSTRUCTIONS(dfunc);
23717
e3720756acdc patch 8.2.2400: Vim9: compiled functions are not profiled
Bram Moolenaar <Bram@vim.org>
parents: 23699
diff changeset
333 entry = estack_push_ufunc(ufunc, 1);
21206
caab594592cc patch 8.2.1154: Vim9: crash when using imported function
Bram Moolenaar <Bram@vim.org>
parents: 21168
diff changeset
334 if (entry != NULL)
caab594592cc patch 8.2.1154: Vim9: crash when using imported function
Bram Moolenaar <Bram@vim.org>
parents: 21168
diff changeset
335 {
caab594592cc patch 8.2.1154: Vim9: crash when using imported function
Bram Moolenaar <Bram@vim.org>
parents: 21168
diff changeset
336 // Set the script context to the script where the function was defined.
24471
baf75c8e1b7b patch 8.2.2775: Vim9: wrong line number used for some commands
Bram Moolenaar <Bram@vim.org>
parents: 24454
diff changeset
337 // Save the current context so it can be restored on return.
baf75c8e1b7b patch 8.2.2775: Vim9: wrong line number used for some commands
Bram Moolenaar <Bram@vim.org>
parents: 24454
diff changeset
338 entry->es_save_sctx = current_sctx;
baf75c8e1b7b patch 8.2.2775: Vim9: wrong line number used for some commands
Bram Moolenaar <Bram@vim.org>
parents: 24454
diff changeset
339 current_sctx = ufunc->uf_script_ctx;
21206
caab594592cc patch 8.2.1154: Vim9: crash when using imported function
Bram Moolenaar <Bram@vim.org>
parents: 21168
diff changeset
340 }
19328
e99e6d794597 patch 8.2.0222: Vim9: optional function arguments don't work yet
Bram Moolenaar <Bram@vim.org>
parents: 19316
diff changeset
341
24272
cabed216cc2f patch 8.2.2677: Vim9: cannot use only some of the default arguments
Bram Moolenaar <Bram@vim.org>
parents: 24234
diff changeset
342 // Start execution at the first instruction.
cabed216cc2f patch 8.2.2677: Vim9: cannot use only some of the default arguments
Bram Moolenaar <Bram@vim.org>
parents: 24234
diff changeset
343 ectx->ec_iidx = 0;
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
344
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
345 return OK;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
346 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
347
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
348 // Get pointer to item in the stack.
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
349 #define STACK_TV(idx) (((typval_T *)ectx->ec_stack.ga_data) + idx)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
350
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
351 /*
20247
e46e72aaff74 patch 8.2.0679: Vim9: incomplete support for closures
Bram Moolenaar <Bram@vim.org>
parents: 20244
diff changeset
352 * Used when returning from a function: Check if any closure is still
e46e72aaff74 patch 8.2.0679: Vim9: incomplete support for closures
Bram Moolenaar <Bram@vim.org>
parents: 20244
diff changeset
353 * referenced. If so then move the arguments and variables to a separate piece
e46e72aaff74 patch 8.2.0679: Vim9: incomplete support for closures
Bram Moolenaar <Bram@vim.org>
parents: 20244
diff changeset
354 * of stack to be used when the closure is called.
e46e72aaff74 patch 8.2.0679: Vim9: incomplete support for closures
Bram Moolenaar <Bram@vim.org>
parents: 20244
diff changeset
355 * When "free_arguments" is TRUE the arguments are to be freed.
e46e72aaff74 patch 8.2.0679: Vim9: incomplete support for closures
Bram Moolenaar <Bram@vim.org>
parents: 20244
diff changeset
356 * Returns FAIL when out of memory.
e46e72aaff74 patch 8.2.0679: Vim9: incomplete support for closures
Bram Moolenaar <Bram@vim.org>
parents: 20244
diff changeset
357 */
e46e72aaff74 patch 8.2.0679: Vim9: incomplete support for closures
Bram Moolenaar <Bram@vim.org>
parents: 20244
diff changeset
358 static int
e46e72aaff74 patch 8.2.0679: Vim9: incomplete support for closures
Bram Moolenaar <Bram@vim.org>
parents: 20244
diff changeset
359 handle_closure_in_use(ectx_T *ectx, int free_arguments)
e46e72aaff74 patch 8.2.0679: Vim9: incomplete support for closures
Bram Moolenaar <Bram@vim.org>
parents: 20244
diff changeset
360 {
e46e72aaff74 patch 8.2.0679: Vim9: incomplete support for closures
Bram Moolenaar <Bram@vim.org>
parents: 20244
diff changeset
361 dfunc_T *dfunc = ((dfunc_T *)def_functions.ga_data)
e46e72aaff74 patch 8.2.0679: Vim9: incomplete support for closures
Bram Moolenaar <Bram@vim.org>
parents: 20244
diff changeset
362 + ectx->ec_dfunc_idx;
22324
a4ed0de125d9 patch 8.2.1711: Vim9: leaking memory when using partial
Bram Moolenaar <Bram@vim.org>
parents: 22320
diff changeset
363 int argcount;
a4ed0de125d9 patch 8.2.1711: Vim9: leaking memory when using partial
Bram Moolenaar <Bram@vim.org>
parents: 22320
diff changeset
364 int top;
20247
e46e72aaff74 patch 8.2.0679: Vim9: incomplete support for closures
Bram Moolenaar <Bram@vim.org>
parents: 20244
diff changeset
365 int idx;
e46e72aaff74 patch 8.2.0679: Vim9: incomplete support for closures
Bram Moolenaar <Bram@vim.org>
parents: 20244
diff changeset
366 typval_T *tv;
e46e72aaff74 patch 8.2.0679: Vim9: incomplete support for closures
Bram Moolenaar <Bram@vim.org>
parents: 20244
diff changeset
367 int closure_in_use = FALSE;
22371
15003353a464 patch 8.2.1734: Vim9: cannot use a funcref for a closure twice
Bram Moolenaar <Bram@vim.org>
parents: 22324
diff changeset
368 garray_T *gap = &ectx->ec_funcrefs;
15003353a464 patch 8.2.1734: Vim9: cannot use a funcref for a closure twice
Bram Moolenaar <Bram@vim.org>
parents: 22324
diff changeset
369 varnumber_T closure_count;
20247
e46e72aaff74 patch 8.2.0679: Vim9: incomplete support for closures
Bram Moolenaar <Bram@vim.org>
parents: 20244
diff changeset
370
22324
a4ed0de125d9 patch 8.2.1711: Vim9: leaking memory when using partial
Bram Moolenaar <Bram@vim.org>
parents: 22320
diff changeset
371 if (dfunc->df_ufunc == NULL)
22371
15003353a464 patch 8.2.1734: Vim9: cannot use a funcref for a closure twice
Bram Moolenaar <Bram@vim.org>
parents: 22324
diff changeset
372 return OK; // function was freed
15003353a464 patch 8.2.1734: Vim9: cannot use a funcref for a closure twice
Bram Moolenaar <Bram@vim.org>
parents: 22324
diff changeset
373 if (dfunc->df_has_closure == 0)
15003353a464 patch 8.2.1734: Vim9: cannot use a funcref for a closure twice
Bram Moolenaar <Bram@vim.org>
parents: 22324
diff changeset
374 return OK; // no closures
15003353a464 patch 8.2.1734: Vim9: cannot use a funcref for a closure twice
Bram Moolenaar <Bram@vim.org>
parents: 22324
diff changeset
375 tv = STACK_TV(ectx->ec_frame_idx + STACK_FRAME_SIZE + dfunc->df_varcount);
15003353a464 patch 8.2.1734: Vim9: cannot use a funcref for a closure twice
Bram Moolenaar <Bram@vim.org>
parents: 22324
diff changeset
376 closure_count = tv->vval.v_number;
15003353a464 patch 8.2.1734: Vim9: cannot use a funcref for a closure twice
Bram Moolenaar <Bram@vim.org>
parents: 22324
diff changeset
377 if (closure_count == 0)
15003353a464 patch 8.2.1734: Vim9: cannot use a funcref for a closure twice
Bram Moolenaar <Bram@vim.org>
parents: 22324
diff changeset
378 return OK; // no funcrefs created
15003353a464 patch 8.2.1734: Vim9: cannot use a funcref for a closure twice
Bram Moolenaar <Bram@vim.org>
parents: 22324
diff changeset
379
22324
a4ed0de125d9 patch 8.2.1711: Vim9: leaking memory when using partial
Bram Moolenaar <Bram@vim.org>
parents: 22320
diff changeset
380 argcount = ufunc_argcount(dfunc->df_ufunc);
a4ed0de125d9 patch 8.2.1711: Vim9: leaking memory when using partial
Bram Moolenaar <Bram@vim.org>
parents: 22320
diff changeset
381 top = ectx->ec_frame_idx - argcount;
a4ed0de125d9 patch 8.2.1711: Vim9: leaking memory when using partial
Bram Moolenaar <Bram@vim.org>
parents: 22320
diff changeset
382
20247
e46e72aaff74 patch 8.2.0679: Vim9: incomplete support for closures
Bram Moolenaar <Bram@vim.org>
parents: 20244
diff changeset
383 // Check if any created closure is still in use.
22371
15003353a464 patch 8.2.1734: Vim9: cannot use a funcref for a closure twice
Bram Moolenaar <Bram@vim.org>
parents: 22324
diff changeset
384 for (idx = 0; idx < closure_count; ++idx)
20247
e46e72aaff74 patch 8.2.0679: Vim9: incomplete support for closures
Bram Moolenaar <Bram@vim.org>
parents: 20244
diff changeset
385 {
22401
df1d7a560b35 patch 8.2.1749: Vim9: crash when closure fails in nested function
Bram Moolenaar <Bram@vim.org>
parents: 22391
diff changeset
386 partial_T *pt;
df1d7a560b35 patch 8.2.1749: Vim9: crash when closure fails in nested function
Bram Moolenaar <Bram@vim.org>
parents: 22391
diff changeset
387 int off = gap->ga_len - closure_count + idx;
df1d7a560b35 patch 8.2.1749: Vim9: crash when closure fails in nested function
Bram Moolenaar <Bram@vim.org>
parents: 22391
diff changeset
388
df1d7a560b35 patch 8.2.1749: Vim9: crash when closure fails in nested function
Bram Moolenaar <Bram@vim.org>
parents: 22391
diff changeset
389 if (off < 0)
df1d7a560b35 patch 8.2.1749: Vim9: crash when closure fails in nested function
Bram Moolenaar <Bram@vim.org>
parents: 22391
diff changeset
390 continue; // count is off or already done
df1d7a560b35 patch 8.2.1749: Vim9: crash when closure fails in nested function
Bram Moolenaar <Bram@vim.org>
parents: 22391
diff changeset
391 pt = ((partial_T **)gap->ga_data)[off];
22371
15003353a464 patch 8.2.1734: Vim9: cannot use a funcref for a closure twice
Bram Moolenaar <Bram@vim.org>
parents: 22324
diff changeset
392 if (pt->pt_refcount > 1)
20257
683c2da4982b patch 8.2.0684: Vim9: memory leak when using lambda
Bram Moolenaar <Bram@vim.org>
parents: 20255
diff changeset
393 {
22371
15003353a464 patch 8.2.1734: Vim9: cannot use a funcref for a closure twice
Bram Moolenaar <Bram@vim.org>
parents: 22324
diff changeset
394 int refcount = pt->pt_refcount;
20283
934657e365e5 patch 8.2.0697: Vim9: memory leak when using nested function
Bram Moolenaar <Bram@vim.org>
parents: 20281
diff changeset
395 int i;
934657e365e5 patch 8.2.0697: Vim9: memory leak when using nested function
Bram Moolenaar <Bram@vim.org>
parents: 20281
diff changeset
396
20297
5f0611bc6377 patch 8.2.0704: Vim9: memory leak in disassemble test
Bram Moolenaar <Bram@vim.org>
parents: 20295
diff changeset
397 // A Reference in a local variables doesn't count, it gets
20283
934657e365e5 patch 8.2.0697: Vim9: memory leak when using nested function
Bram Moolenaar <Bram@vim.org>
parents: 20281
diff changeset
398 // unreferenced on return.
934657e365e5 patch 8.2.0697: Vim9: memory leak when using nested function
Bram Moolenaar <Bram@vim.org>
parents: 20281
diff changeset
399 for (i = 0; i < dfunc->df_varcount; ++i)
934657e365e5 patch 8.2.0697: Vim9: memory leak when using nested function
Bram Moolenaar <Bram@vim.org>
parents: 20281
diff changeset
400 {
934657e365e5 patch 8.2.0697: Vim9: memory leak when using nested function
Bram Moolenaar <Bram@vim.org>
parents: 20281
diff changeset
401 typval_T *stv = STACK_TV(ectx->ec_frame_idx
934657e365e5 patch 8.2.0697: Vim9: memory leak when using nested function
Bram Moolenaar <Bram@vim.org>
parents: 20281
diff changeset
402 + STACK_FRAME_SIZE + i);
22371
15003353a464 patch 8.2.1734: Vim9: cannot use a funcref for a closure twice
Bram Moolenaar <Bram@vim.org>
parents: 22324
diff changeset
403 if (stv->v_type == VAR_PARTIAL && pt == stv->vval.v_partial)
20283
934657e365e5 patch 8.2.0697: Vim9: memory leak when using nested function
Bram Moolenaar <Bram@vim.org>
parents: 20281
diff changeset
404 --refcount;
934657e365e5 patch 8.2.0697: Vim9: memory leak when using nested function
Bram Moolenaar <Bram@vim.org>
parents: 20281
diff changeset
405 }
934657e365e5 patch 8.2.0697: Vim9: memory leak when using nested function
Bram Moolenaar <Bram@vim.org>
parents: 20281
diff changeset
406 if (refcount > 1)
934657e365e5 patch 8.2.0697: Vim9: memory leak when using nested function
Bram Moolenaar <Bram@vim.org>
parents: 20281
diff changeset
407 {
934657e365e5 patch 8.2.0697: Vim9: memory leak when using nested function
Bram Moolenaar <Bram@vim.org>
parents: 20281
diff changeset
408 closure_in_use = TRUE;
934657e365e5 patch 8.2.0697: Vim9: memory leak when using nested function
Bram Moolenaar <Bram@vim.org>
parents: 20281
diff changeset
409 break;
934657e365e5 patch 8.2.0697: Vim9: memory leak when using nested function
Bram Moolenaar <Bram@vim.org>
parents: 20281
diff changeset
410 }
20257
683c2da4982b patch 8.2.0684: Vim9: memory leak when using lambda
Bram Moolenaar <Bram@vim.org>
parents: 20255
diff changeset
411 }
20247
e46e72aaff74 patch 8.2.0679: Vim9: incomplete support for closures
Bram Moolenaar <Bram@vim.org>
parents: 20244
diff changeset
412 }
e46e72aaff74 patch 8.2.0679: Vim9: incomplete support for closures
Bram Moolenaar <Bram@vim.org>
parents: 20244
diff changeset
413
e46e72aaff74 patch 8.2.0679: Vim9: incomplete support for closures
Bram Moolenaar <Bram@vim.org>
parents: 20244
diff changeset
414 if (closure_in_use)
e46e72aaff74 patch 8.2.0679: Vim9: incomplete support for closures
Bram Moolenaar <Bram@vim.org>
parents: 20244
diff changeset
415 {
e46e72aaff74 patch 8.2.0679: Vim9: incomplete support for closures
Bram Moolenaar <Bram@vim.org>
parents: 20244
diff changeset
416 funcstack_T *funcstack = ALLOC_CLEAR_ONE(funcstack_T);
e46e72aaff74 patch 8.2.0679: Vim9: incomplete support for closures
Bram Moolenaar <Bram@vim.org>
parents: 20244
diff changeset
417 typval_T *stack;
e46e72aaff74 patch 8.2.0679: Vim9: incomplete support for closures
Bram Moolenaar <Bram@vim.org>
parents: 20244
diff changeset
418
e46e72aaff74 patch 8.2.0679: Vim9: incomplete support for closures
Bram Moolenaar <Bram@vim.org>
parents: 20244
diff changeset
419 // A closure is using the arguments and/or local variables.
e46e72aaff74 patch 8.2.0679: Vim9: incomplete support for closures
Bram Moolenaar <Bram@vim.org>
parents: 20244
diff changeset
420 // Move them to the called function.
e46e72aaff74 patch 8.2.0679: Vim9: incomplete support for closures
Bram Moolenaar <Bram@vim.org>
parents: 20244
diff changeset
421 if (funcstack == NULL)
e46e72aaff74 patch 8.2.0679: Vim9: incomplete support for closures
Bram Moolenaar <Bram@vim.org>
parents: 20244
diff changeset
422 return FAIL;
22541
7d6ba4204f66 patch 8.2.1819: Vim9: Memory leak when using a closure
Bram Moolenaar <Bram@vim.org>
parents: 22527
diff changeset
423 funcstack->fs_var_offset = argcount + STACK_FRAME_SIZE;
7d6ba4204f66 patch 8.2.1819: Vim9: Memory leak when using a closure
Bram Moolenaar <Bram@vim.org>
parents: 22527
diff changeset
424 funcstack->fs_ga.ga_len = funcstack->fs_var_offset + dfunc->df_varcount;
20247
e46e72aaff74 patch 8.2.0679: Vim9: incomplete support for closures
Bram Moolenaar <Bram@vim.org>
parents: 20244
diff changeset
425 stack = ALLOC_CLEAR_MULT(typval_T, funcstack->fs_ga.ga_len);
e46e72aaff74 patch 8.2.0679: Vim9: incomplete support for closures
Bram Moolenaar <Bram@vim.org>
parents: 20244
diff changeset
426 funcstack->fs_ga.ga_data = stack;
e46e72aaff74 patch 8.2.0679: Vim9: incomplete support for closures
Bram Moolenaar <Bram@vim.org>
parents: 20244
diff changeset
427 if (stack == NULL)
e46e72aaff74 patch 8.2.0679: Vim9: incomplete support for closures
Bram Moolenaar <Bram@vim.org>
parents: 20244
diff changeset
428 {
e46e72aaff74 patch 8.2.0679: Vim9: incomplete support for closures
Bram Moolenaar <Bram@vim.org>
parents: 20244
diff changeset
429 vim_free(funcstack);
e46e72aaff74 patch 8.2.0679: Vim9: incomplete support for closures
Bram Moolenaar <Bram@vim.org>
parents: 20244
diff changeset
430 return FAIL;
e46e72aaff74 patch 8.2.0679: Vim9: incomplete support for closures
Bram Moolenaar <Bram@vim.org>
parents: 20244
diff changeset
431 }
e46e72aaff74 patch 8.2.0679: Vim9: incomplete support for closures
Bram Moolenaar <Bram@vim.org>
parents: 20244
diff changeset
432
e46e72aaff74 patch 8.2.0679: Vim9: incomplete support for closures
Bram Moolenaar <Bram@vim.org>
parents: 20244
diff changeset
433 // Move or copy the arguments.
e46e72aaff74 patch 8.2.0679: Vim9: incomplete support for closures
Bram Moolenaar <Bram@vim.org>
parents: 20244
diff changeset
434 for (idx = 0; idx < argcount; ++idx)
e46e72aaff74 patch 8.2.0679: Vim9: incomplete support for closures
Bram Moolenaar <Bram@vim.org>
parents: 20244
diff changeset
435 {
e46e72aaff74 patch 8.2.0679: Vim9: incomplete support for closures
Bram Moolenaar <Bram@vim.org>
parents: 20244
diff changeset
436 tv = STACK_TV(top + idx);
e46e72aaff74 patch 8.2.0679: Vim9: incomplete support for closures
Bram Moolenaar <Bram@vim.org>
parents: 20244
diff changeset
437 if (free_arguments)
e46e72aaff74 patch 8.2.0679: Vim9: incomplete support for closures
Bram Moolenaar <Bram@vim.org>
parents: 20244
diff changeset
438 {
e46e72aaff74 patch 8.2.0679: Vim9: incomplete support for closures
Bram Moolenaar <Bram@vim.org>
parents: 20244
diff changeset
439 *(stack + idx) = *tv;
e46e72aaff74 patch 8.2.0679: Vim9: incomplete support for closures
Bram Moolenaar <Bram@vim.org>
parents: 20244
diff changeset
440 tv->v_type = VAR_UNKNOWN;
e46e72aaff74 patch 8.2.0679: Vim9: incomplete support for closures
Bram Moolenaar <Bram@vim.org>
parents: 20244
diff changeset
441 }
e46e72aaff74 patch 8.2.0679: Vim9: incomplete support for closures
Bram Moolenaar <Bram@vim.org>
parents: 20244
diff changeset
442 else
e46e72aaff74 patch 8.2.0679: Vim9: incomplete support for closures
Bram Moolenaar <Bram@vim.org>
parents: 20244
diff changeset
443 copy_tv(tv, stack + idx);
e46e72aaff74 patch 8.2.0679: Vim9: incomplete support for closures
Bram Moolenaar <Bram@vim.org>
parents: 20244
diff changeset
444 }
e46e72aaff74 patch 8.2.0679: Vim9: incomplete support for closures
Bram Moolenaar <Bram@vim.org>
parents: 20244
diff changeset
445 // Move the local variables.
e46e72aaff74 patch 8.2.0679: Vim9: incomplete support for closures
Bram Moolenaar <Bram@vim.org>
parents: 20244
diff changeset
446 for (idx = 0; idx < dfunc->df_varcount; ++idx)
e46e72aaff74 patch 8.2.0679: Vim9: incomplete support for closures
Bram Moolenaar <Bram@vim.org>
parents: 20244
diff changeset
447 {
e46e72aaff74 patch 8.2.0679: Vim9: incomplete support for closures
Bram Moolenaar <Bram@vim.org>
parents: 20244
diff changeset
448 tv = STACK_TV(ectx->ec_frame_idx + STACK_FRAME_SIZE + idx);
20297
5f0611bc6377 patch 8.2.0704: Vim9: memory leak in disassemble test
Bram Moolenaar <Bram@vim.org>
parents: 20295
diff changeset
449
22541
7d6ba4204f66 patch 8.2.1819: Vim9: Memory leak when using a closure
Bram Moolenaar <Bram@vim.org>
parents: 22527
diff changeset
450 // A partial created for a local function, that is also used as a
7d6ba4204f66 patch 8.2.1819: Vim9: Memory leak when using a closure
Bram Moolenaar <Bram@vim.org>
parents: 22527
diff changeset
451 // local variable, has a reference count for the variable, thus
7d6ba4204f66 patch 8.2.1819: Vim9: Memory leak when using a closure
Bram Moolenaar <Bram@vim.org>
parents: 22527
diff changeset
452 // will never go down to zero. When all these refcounts are one
7d6ba4204f66 patch 8.2.1819: Vim9: Memory leak when using a closure
Bram Moolenaar <Bram@vim.org>
parents: 22527
diff changeset
453 // then the funcstack is unused. We need to count how many we have
7d6ba4204f66 patch 8.2.1819: Vim9: Memory leak when using a closure
Bram Moolenaar <Bram@vim.org>
parents: 22527
diff changeset
454 // so we need when to check.
20297
5f0611bc6377 patch 8.2.0704: Vim9: memory leak in disassemble test
Bram Moolenaar <Bram@vim.org>
parents: 20295
diff changeset
455 if (tv->v_type == VAR_PARTIAL && tv->vval.v_partial != NULL)
5f0611bc6377 patch 8.2.0704: Vim9: memory leak in disassemble test
Bram Moolenaar <Bram@vim.org>
parents: 20295
diff changeset
456 {
22541
7d6ba4204f66 patch 8.2.1819: Vim9: Memory leak when using a closure
Bram Moolenaar <Bram@vim.org>
parents: 22527
diff changeset
457 int i;
22371
15003353a464 patch 8.2.1734: Vim9: cannot use a funcref for a closure twice
Bram Moolenaar <Bram@vim.org>
parents: 22324
diff changeset
458
15003353a464 patch 8.2.1734: Vim9: cannot use a funcref for a closure twice
Bram Moolenaar <Bram@vim.org>
parents: 22324
diff changeset
459 for (i = 0; i < closure_count; ++i)
22541
7d6ba4204f66 patch 8.2.1819: Vim9: Memory leak when using a closure
Bram Moolenaar <Bram@vim.org>
parents: 22527
diff changeset
460 if (tv->vval.v_partial == ((partial_T **)gap->ga_data)[
7d6ba4204f66 patch 8.2.1819: Vim9: Memory leak when using a closure
Bram Moolenaar <Bram@vim.org>
parents: 22527
diff changeset
461 gap->ga_len - closure_count + i])
7d6ba4204f66 patch 8.2.1819: Vim9: Memory leak when using a closure
Bram Moolenaar <Bram@vim.org>
parents: 22527
diff changeset
462 ++funcstack->fs_min_refcount;
20297
5f0611bc6377 patch 8.2.0704: Vim9: memory leak in disassemble test
Bram Moolenaar <Bram@vim.org>
parents: 20295
diff changeset
463 }
5f0611bc6377 patch 8.2.0704: Vim9: memory leak in disassemble test
Bram Moolenaar <Bram@vim.org>
parents: 20295
diff changeset
464
22541
7d6ba4204f66 patch 8.2.1819: Vim9: Memory leak when using a closure
Bram Moolenaar <Bram@vim.org>
parents: 22527
diff changeset
465 *(stack + funcstack->fs_var_offset + idx) = *tv;
20247
e46e72aaff74 patch 8.2.0679: Vim9: incomplete support for closures
Bram Moolenaar <Bram@vim.org>
parents: 20244
diff changeset
466 tv->v_type = VAR_UNKNOWN;
e46e72aaff74 patch 8.2.0679: Vim9: incomplete support for closures
Bram Moolenaar <Bram@vim.org>
parents: 20244
diff changeset
467 }
e46e72aaff74 patch 8.2.0679: Vim9: incomplete support for closures
Bram Moolenaar <Bram@vim.org>
parents: 20244
diff changeset
468
22371
15003353a464 patch 8.2.1734: Vim9: cannot use a funcref for a closure twice
Bram Moolenaar <Bram@vim.org>
parents: 22324
diff changeset
469 for (idx = 0; idx < closure_count; ++idx)
20247
e46e72aaff74 patch 8.2.0679: Vim9: incomplete support for closures
Bram Moolenaar <Bram@vim.org>
parents: 20244
diff changeset
470 {
22371
15003353a464 patch 8.2.1734: Vim9: cannot use a funcref for a closure twice
Bram Moolenaar <Bram@vim.org>
parents: 22324
diff changeset
471 partial_T *pt = ((partial_T **)gap->ga_data)[gap->ga_len
15003353a464 patch 8.2.1734: Vim9: cannot use a funcref for a closure twice
Bram Moolenaar <Bram@vim.org>
parents: 22324
diff changeset
472 - closure_count + idx];
15003353a464 patch 8.2.1734: Vim9: cannot use a funcref for a closure twice
Bram Moolenaar <Bram@vim.org>
parents: 22324
diff changeset
473 if (pt->pt_refcount > 1)
20247
e46e72aaff74 patch 8.2.0679: Vim9: incomplete support for closures
Bram Moolenaar <Bram@vim.org>
parents: 20244
diff changeset
474 {
22371
15003353a464 patch 8.2.1734: Vim9: cannot use a funcref for a closure twice
Bram Moolenaar <Bram@vim.org>
parents: 22324
diff changeset
475 ++funcstack->fs_refcount;
15003353a464 patch 8.2.1734: Vim9: cannot use a funcref for a closure twice
Bram Moolenaar <Bram@vim.org>
parents: 22324
diff changeset
476 pt->pt_funcstack = funcstack;
23559
64dfb69e7d46 patch 8.2.2322: Vim9: closure nested limiting to one level
Bram Moolenaar <Bram@vim.org>
parents: 23557
diff changeset
477 pt->pt_outer.out_stack = &funcstack->fs_ga;
64dfb69e7d46 patch 8.2.2322: Vim9: closure nested limiting to one level
Bram Moolenaar <Bram@vim.org>
parents: 23557
diff changeset
478 pt->pt_outer.out_frame_idx = ectx->ec_frame_idx - top;
64dfb69e7d46 patch 8.2.2322: Vim9: closure nested limiting to one level
Bram Moolenaar <Bram@vim.org>
parents: 23557
diff changeset
479 pt->pt_outer.out_up = ectx->ec_outer;
20247
e46e72aaff74 patch 8.2.0679: Vim9: incomplete support for closures
Bram Moolenaar <Bram@vim.org>
parents: 20244
diff changeset
480 }
e46e72aaff74 patch 8.2.0679: Vim9: incomplete support for closures
Bram Moolenaar <Bram@vim.org>
parents: 20244
diff changeset
481 }
e46e72aaff74 patch 8.2.0679: Vim9: incomplete support for closures
Bram Moolenaar <Bram@vim.org>
parents: 20244
diff changeset
482 }
e46e72aaff74 patch 8.2.0679: Vim9: incomplete support for closures
Bram Moolenaar <Bram@vim.org>
parents: 20244
diff changeset
483
22371
15003353a464 patch 8.2.1734: Vim9: cannot use a funcref for a closure twice
Bram Moolenaar <Bram@vim.org>
parents: 22324
diff changeset
484 for (idx = 0; idx < closure_count; ++idx)
15003353a464 patch 8.2.1734: Vim9: cannot use a funcref for a closure twice
Bram Moolenaar <Bram@vim.org>
parents: 22324
diff changeset
485 partial_unref(((partial_T **)gap->ga_data)[gap->ga_len
15003353a464 patch 8.2.1734: Vim9: cannot use a funcref for a closure twice
Bram Moolenaar <Bram@vim.org>
parents: 22324
diff changeset
486 - closure_count + idx]);
15003353a464 patch 8.2.1734: Vim9: cannot use a funcref for a closure twice
Bram Moolenaar <Bram@vim.org>
parents: 22324
diff changeset
487 gap->ga_len -= closure_count;
15003353a464 patch 8.2.1734: Vim9: cannot use a funcref for a closure twice
Bram Moolenaar <Bram@vim.org>
parents: 22324
diff changeset
488 if (gap->ga_len == 0)
15003353a464 patch 8.2.1734: Vim9: cannot use a funcref for a closure twice
Bram Moolenaar <Bram@vim.org>
parents: 22324
diff changeset
489 ga_clear(gap);
15003353a464 patch 8.2.1734: Vim9: cannot use a funcref for a closure twice
Bram Moolenaar <Bram@vim.org>
parents: 22324
diff changeset
490
20247
e46e72aaff74 patch 8.2.0679: Vim9: incomplete support for closures
Bram Moolenaar <Bram@vim.org>
parents: 20244
diff changeset
491 return OK;
e46e72aaff74 patch 8.2.0679: Vim9: incomplete support for closures
Bram Moolenaar <Bram@vim.org>
parents: 20244
diff changeset
492 }
e46e72aaff74 patch 8.2.0679: Vim9: incomplete support for closures
Bram Moolenaar <Bram@vim.org>
parents: 20244
diff changeset
493
e46e72aaff74 patch 8.2.0679: Vim9: incomplete support for closures
Bram Moolenaar <Bram@vim.org>
parents: 20244
diff changeset
494 /*
22541
7d6ba4204f66 patch 8.2.1819: Vim9: Memory leak when using a closure
Bram Moolenaar <Bram@vim.org>
parents: 22527
diff changeset
495 * Called when a partial is freed or its reference count goes down to one. The
7d6ba4204f66 patch 8.2.1819: Vim9: Memory leak when using a closure
Bram Moolenaar <Bram@vim.org>
parents: 22527
diff changeset
496 * funcstack may be the only reference to the partials in the local variables.
7d6ba4204f66 patch 8.2.1819: Vim9: Memory leak when using a closure
Bram Moolenaar <Bram@vim.org>
parents: 22527
diff changeset
497 * Go over all of them, the funcref and can be freed if all partials
7d6ba4204f66 patch 8.2.1819: Vim9: Memory leak when using a closure
Bram Moolenaar <Bram@vim.org>
parents: 22527
diff changeset
498 * referencing the funcstack have a reference count of one.
7d6ba4204f66 patch 8.2.1819: Vim9: Memory leak when using a closure
Bram Moolenaar <Bram@vim.org>
parents: 22527
diff changeset
499 */
7d6ba4204f66 patch 8.2.1819: Vim9: Memory leak when using a closure
Bram Moolenaar <Bram@vim.org>
parents: 22527
diff changeset
500 void
7d6ba4204f66 patch 8.2.1819: Vim9: Memory leak when using a closure
Bram Moolenaar <Bram@vim.org>
parents: 22527
diff changeset
501 funcstack_check_refcount(funcstack_T *funcstack)
7d6ba4204f66 patch 8.2.1819: Vim9: Memory leak when using a closure
Bram Moolenaar <Bram@vim.org>
parents: 22527
diff changeset
502 {
7d6ba4204f66 patch 8.2.1819: Vim9: Memory leak when using a closure
Bram Moolenaar <Bram@vim.org>
parents: 22527
diff changeset
503 int i;
7d6ba4204f66 patch 8.2.1819: Vim9: Memory leak when using a closure
Bram Moolenaar <Bram@vim.org>
parents: 22527
diff changeset
504 garray_T *gap = &funcstack->fs_ga;
7d6ba4204f66 patch 8.2.1819: Vim9: Memory leak when using a closure
Bram Moolenaar <Bram@vim.org>
parents: 22527
diff changeset
505 int done = 0;
7d6ba4204f66 patch 8.2.1819: Vim9: Memory leak when using a closure
Bram Moolenaar <Bram@vim.org>
parents: 22527
diff changeset
506
7d6ba4204f66 patch 8.2.1819: Vim9: Memory leak when using a closure
Bram Moolenaar <Bram@vim.org>
parents: 22527
diff changeset
507 if (funcstack->fs_refcount > funcstack->fs_min_refcount)
7d6ba4204f66 patch 8.2.1819: Vim9: Memory leak when using a closure
Bram Moolenaar <Bram@vim.org>
parents: 22527
diff changeset
508 return;
7d6ba4204f66 patch 8.2.1819: Vim9: Memory leak when using a closure
Bram Moolenaar <Bram@vim.org>
parents: 22527
diff changeset
509 for (i = funcstack->fs_var_offset; i < gap->ga_len; ++i)
7d6ba4204f66 patch 8.2.1819: Vim9: Memory leak when using a closure
Bram Moolenaar <Bram@vim.org>
parents: 22527
diff changeset
510 {
7d6ba4204f66 patch 8.2.1819: Vim9: Memory leak when using a closure
Bram Moolenaar <Bram@vim.org>
parents: 22527
diff changeset
511 typval_T *tv = ((typval_T *)gap->ga_data) + i;
7d6ba4204f66 patch 8.2.1819: Vim9: Memory leak when using a closure
Bram Moolenaar <Bram@vim.org>
parents: 22527
diff changeset
512
7d6ba4204f66 patch 8.2.1819: Vim9: Memory leak when using a closure
Bram Moolenaar <Bram@vim.org>
parents: 22527
diff changeset
513 if (tv->v_type == VAR_PARTIAL && tv->vval.v_partial != NULL
7d6ba4204f66 patch 8.2.1819: Vim9: Memory leak when using a closure
Bram Moolenaar <Bram@vim.org>
parents: 22527
diff changeset
514 && tv->vval.v_partial->pt_funcstack == funcstack
7d6ba4204f66 patch 8.2.1819: Vim9: Memory leak when using a closure
Bram Moolenaar <Bram@vim.org>
parents: 22527
diff changeset
515 && tv->vval.v_partial->pt_refcount == 1)
7d6ba4204f66 patch 8.2.1819: Vim9: Memory leak when using a closure
Bram Moolenaar <Bram@vim.org>
parents: 22527
diff changeset
516 ++done;
7d6ba4204f66 patch 8.2.1819: Vim9: Memory leak when using a closure
Bram Moolenaar <Bram@vim.org>
parents: 22527
diff changeset
517 }
7d6ba4204f66 patch 8.2.1819: Vim9: Memory leak when using a closure
Bram Moolenaar <Bram@vim.org>
parents: 22527
diff changeset
518 if (done == funcstack->fs_min_refcount)
7d6ba4204f66 patch 8.2.1819: Vim9: Memory leak when using a closure
Bram Moolenaar <Bram@vim.org>
parents: 22527
diff changeset
519 {
7d6ba4204f66 patch 8.2.1819: Vim9: Memory leak when using a closure
Bram Moolenaar <Bram@vim.org>
parents: 22527
diff changeset
520 typval_T *stack = gap->ga_data;
7d6ba4204f66 patch 8.2.1819: Vim9: Memory leak when using a closure
Bram Moolenaar <Bram@vim.org>
parents: 22527
diff changeset
521
7d6ba4204f66 patch 8.2.1819: Vim9: Memory leak when using a closure
Bram Moolenaar <Bram@vim.org>
parents: 22527
diff changeset
522 // All partials referencing the funcstack have a reference count of
7d6ba4204f66 patch 8.2.1819: Vim9: Memory leak when using a closure
Bram Moolenaar <Bram@vim.org>
parents: 22527
diff changeset
523 // one, thus the funcstack is no longer of use.
7d6ba4204f66 patch 8.2.1819: Vim9: Memory leak when using a closure
Bram Moolenaar <Bram@vim.org>
parents: 22527
diff changeset
524 for (i = 0; i < gap->ga_len; ++i)
7d6ba4204f66 patch 8.2.1819: Vim9: Memory leak when using a closure
Bram Moolenaar <Bram@vim.org>
parents: 22527
diff changeset
525 clear_tv(stack + i);
7d6ba4204f66 patch 8.2.1819: Vim9: Memory leak when using a closure
Bram Moolenaar <Bram@vim.org>
parents: 22527
diff changeset
526 vim_free(stack);
7d6ba4204f66 patch 8.2.1819: Vim9: Memory leak when using a closure
Bram Moolenaar <Bram@vim.org>
parents: 22527
diff changeset
527 vim_free(funcstack);
7d6ba4204f66 patch 8.2.1819: Vim9: Memory leak when using a closure
Bram Moolenaar <Bram@vim.org>
parents: 22527
diff changeset
528 }
7d6ba4204f66 patch 8.2.1819: Vim9: Memory leak when using a closure
Bram Moolenaar <Bram@vim.org>
parents: 22527
diff changeset
529 }
7d6ba4204f66 patch 8.2.1819: Vim9: Memory leak when using a closure
Bram Moolenaar <Bram@vim.org>
parents: 22527
diff changeset
530
7d6ba4204f66 patch 8.2.1819: Vim9: Memory leak when using a closure
Bram Moolenaar <Bram@vim.org>
parents: 22527
diff changeset
531 /*
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
532 * Return from the current function.
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
533 */
20247
e46e72aaff74 patch 8.2.0679: Vim9: incomplete support for closures
Bram Moolenaar <Bram@vim.org>
parents: 20244
diff changeset
534 static int
24488
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
535 func_return(ectx_T *ectx)
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
536 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
537 int idx;
23009
1fa84623fc68 patch 8.2.2051: Vim9: crash when aborting a user function call
Bram Moolenaar <Bram@vim.org>
parents: 22975
diff changeset
538 int ret_idx;
20247
e46e72aaff74 patch 8.2.0679: Vim9: incomplete support for closures
Bram Moolenaar <Bram@vim.org>
parents: 20244
diff changeset
539 dfunc_T *dfunc = ((dfunc_T *)def_functions.ga_data)
e46e72aaff74 patch 8.2.0679: Vim9: incomplete support for closures
Bram Moolenaar <Bram@vim.org>
parents: 20244
diff changeset
540 + ectx->ec_dfunc_idx;
e46e72aaff74 patch 8.2.0679: Vim9: incomplete support for closures
Bram Moolenaar <Bram@vim.org>
parents: 20244
diff changeset
541 int argcount = ufunc_argcount(dfunc->df_ufunc);
e46e72aaff74 patch 8.2.0679: Vim9: incomplete support for closures
Bram Moolenaar <Bram@vim.org>
parents: 20244
diff changeset
542 int top = ectx->ec_frame_idx - argcount;
21206
caab594592cc patch 8.2.1154: Vim9: crash when using imported function
Bram Moolenaar <Bram@vim.org>
parents: 21168
diff changeset
543 estack_T *entry;
23976
03819ebd3e6d patch 8.2.2530: Vim9: not enough testing for profiling
Bram Moolenaar <Bram@vim.org>
parents: 23934
diff changeset
544 int prev_dfunc_idx = STACK_TV(ectx->ec_frame_idx
03819ebd3e6d patch 8.2.2530: Vim9: not enough testing for profiling
Bram Moolenaar <Bram@vim.org>
parents: 23934
diff changeset
545 + STACK_FRAME_FUNC_OFF)->vval.v_number;
24549
dd87d08f86de patch 8.2.2814: Vim9: unused variable
Bram Moolenaar <Bram@vim.org>
parents: 24545
diff changeset
546 funclocal_T *floc;
dd87d08f86de patch 8.2.2814: Vim9: unused variable
Bram Moolenaar <Bram@vim.org>
parents: 24545
diff changeset
547 #ifdef FEAT_PROFILE
23976
03819ebd3e6d patch 8.2.2530: Vim9: not enough testing for profiling
Bram Moolenaar <Bram@vim.org>
parents: 23934
diff changeset
548 dfunc_T *prev_dfunc = ((dfunc_T *)def_functions.ga_data)
03819ebd3e6d patch 8.2.2530: Vim9: not enough testing for profiling
Bram Moolenaar <Bram@vim.org>
parents: 23934
diff changeset
549 + prev_dfunc_idx;
24549
dd87d08f86de patch 8.2.2814: Vim9: unused variable
Bram Moolenaar <Bram@vim.org>
parents: 24545
diff changeset
550
23976
03819ebd3e6d patch 8.2.2530: Vim9: not enough testing for profiling
Bram Moolenaar <Bram@vim.org>
parents: 23934
diff changeset
551 if (do_profiling == PROF_YES)
03819ebd3e6d patch 8.2.2530: Vim9: not enough testing for profiling
Bram Moolenaar <Bram@vim.org>
parents: 23934
diff changeset
552 {
03819ebd3e6d patch 8.2.2530: Vim9: not enough testing for profiling
Bram Moolenaar <Bram@vim.org>
parents: 23934
diff changeset
553 ufunc_T *caller = prev_dfunc->df_ufunc;
03819ebd3e6d patch 8.2.2530: Vim9: not enough testing for profiling
Bram Moolenaar <Bram@vim.org>
parents: 23934
diff changeset
554
03819ebd3e6d patch 8.2.2530: Vim9: not enough testing for profiling
Bram Moolenaar <Bram@vim.org>
parents: 23934
diff changeset
555 if (dfunc->df_ufunc->uf_profiling
03819ebd3e6d patch 8.2.2530: Vim9: not enough testing for profiling
Bram Moolenaar <Bram@vim.org>
parents: 23934
diff changeset
556 || (caller != NULL && caller->uf_profiling))
03819ebd3e6d patch 8.2.2530: Vim9: not enough testing for profiling
Bram Moolenaar <Bram@vim.org>
parents: 23934
diff changeset
557 {
03819ebd3e6d patch 8.2.2530: Vim9: not enough testing for profiling
Bram Moolenaar <Bram@vim.org>
parents: 23934
diff changeset
558 profile_may_end_func(((profinfo_T *)profile_info_ga.ga_data)
03819ebd3e6d patch 8.2.2530: Vim9: not enough testing for profiling
Bram Moolenaar <Bram@vim.org>
parents: 23934
diff changeset
559 + profile_info_ga.ga_len - 1, dfunc->df_ufunc, caller);
03819ebd3e6d patch 8.2.2530: Vim9: not enough testing for profiling
Bram Moolenaar <Bram@vim.org>
parents: 23934
diff changeset
560 --profile_info_ga.ga_len;
03819ebd3e6d patch 8.2.2530: Vim9: not enough testing for profiling
Bram Moolenaar <Bram@vim.org>
parents: 23934
diff changeset
561 }
03819ebd3e6d patch 8.2.2530: Vim9: not enough testing for profiling
Bram Moolenaar <Bram@vim.org>
parents: 23934
diff changeset
562 }
03819ebd3e6d patch 8.2.2530: Vim9: not enough testing for profiling
Bram Moolenaar <Bram@vim.org>
parents: 23934
diff changeset
563 #endif
24146
03fc95628eb0 patch 8.2.2614: Vim9: function is deleted while executing
Bram Moolenaar <Bram@vim.org>
parents: 24128
diff changeset
564 // TODO: when is it safe to delete the function when it is no longer used?
03fc95628eb0 patch 8.2.2614: Vim9: function is deleted while executing
Bram Moolenaar <Bram@vim.org>
parents: 24128
diff changeset
565 --dfunc->df_ufunc->uf_calls;
03fc95628eb0 patch 8.2.2614: Vim9: function is deleted while executing
Bram Moolenaar <Bram@vim.org>
parents: 24128
diff changeset
566
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
567 // execution context goes one level up
21206
caab594592cc patch 8.2.1154: Vim9: crash when using imported function
Bram Moolenaar <Bram@vim.org>
parents: 21168
diff changeset
568 entry = estack_pop();
caab594592cc patch 8.2.1154: Vim9: crash when using imported function
Bram Moolenaar <Bram@vim.org>
parents: 21168
diff changeset
569 if (entry != NULL)
24471
baf75c8e1b7b patch 8.2.2775: Vim9: wrong line number used for some commands
Bram Moolenaar <Bram@vim.org>
parents: 24454
diff changeset
570 current_sctx = entry->es_save_sctx;
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
571
20247
e46e72aaff74 patch 8.2.0679: Vim9: incomplete support for closures
Bram Moolenaar <Bram@vim.org>
parents: 20244
diff changeset
572 if (handle_closure_in_use(ectx, TRUE) == FAIL)
e46e72aaff74 patch 8.2.0679: Vim9: incomplete support for closures
Bram Moolenaar <Bram@vim.org>
parents: 20244
diff changeset
573 return FAIL;
e46e72aaff74 patch 8.2.0679: Vim9: incomplete support for closures
Bram Moolenaar <Bram@vim.org>
parents: 20244
diff changeset
574
e46e72aaff74 patch 8.2.0679: Vim9: incomplete support for closures
Bram Moolenaar <Bram@vim.org>
parents: 20244
diff changeset
575 // Clear the arguments.
e46e72aaff74 patch 8.2.0679: Vim9: incomplete support for closures
Bram Moolenaar <Bram@vim.org>
parents: 20244
diff changeset
576 for (idx = top; idx < ectx->ec_frame_idx; ++idx)
e46e72aaff74 patch 8.2.0679: Vim9: incomplete support for closures
Bram Moolenaar <Bram@vim.org>
parents: 20244
diff changeset
577 clear_tv(STACK_TV(idx));
e46e72aaff74 patch 8.2.0679: Vim9: incomplete support for closures
Bram Moolenaar <Bram@vim.org>
parents: 20244
diff changeset
578
e46e72aaff74 patch 8.2.0679: Vim9: incomplete support for closures
Bram Moolenaar <Bram@vim.org>
parents: 20244
diff changeset
579 // Clear local variables and temp values, but not the return value.
e46e72aaff74 patch 8.2.0679: Vim9: incomplete support for closures
Bram Moolenaar <Bram@vim.org>
parents: 20244
diff changeset
580 for (idx = ectx->ec_frame_idx + STACK_FRAME_SIZE;
19328
e99e6d794597 patch 8.2.0222: Vim9: optional function arguments don't work yet
Bram Moolenaar <Bram@vim.org>
parents: 19316
diff changeset
581 idx < ectx->ec_stack.ga_len - 1; ++idx)
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
582 clear_tv(STACK_TV(idx));
19328
e99e6d794597 patch 8.2.0222: Vim9: optional function arguments don't work yet
Bram Moolenaar <Bram@vim.org>
parents: 19316
diff changeset
583
23009
1fa84623fc68 patch 8.2.2051: Vim9: crash when aborting a user function call
Bram Moolenaar <Bram@vim.org>
parents: 22975
diff changeset
584 // The return value should be on top of the stack. However, when aborting
1fa84623fc68 patch 8.2.2051: Vim9: crash when aborting a user function call
Bram Moolenaar <Bram@vim.org>
parents: 22975
diff changeset
585 // it may not be there and ec_frame_idx is the top of the stack.
1fa84623fc68 patch 8.2.2051: Vim9: crash when aborting a user function call
Bram Moolenaar <Bram@vim.org>
parents: 22975
diff changeset
586 ret_idx = ectx->ec_stack.ga_len - 1;
23559
64dfb69e7d46 patch 8.2.2322: Vim9: closure nested limiting to one level
Bram Moolenaar <Bram@vim.org>
parents: 23557
diff changeset
587 if (ret_idx == ectx->ec_frame_idx + STACK_FRAME_IDX_OFF)
23009
1fa84623fc68 patch 8.2.2051: Vim9: crash when aborting a user function call
Bram Moolenaar <Bram@vim.org>
parents: 22975
diff changeset
588 ret_idx = 0;
1fa84623fc68 patch 8.2.2051: Vim9: crash when aborting a user function call
Bram Moolenaar <Bram@vim.org>
parents: 22975
diff changeset
589
23559
64dfb69e7d46 patch 8.2.2322: Vim9: closure nested limiting to one level
Bram Moolenaar <Bram@vim.org>
parents: 23557
diff changeset
590 vim_free(ectx->ec_outer);
64dfb69e7d46 patch 8.2.2322: Vim9: closure nested limiting to one level
Bram Moolenaar <Bram@vim.org>
parents: 23557
diff changeset
591
19328
e99e6d794597 patch 8.2.0222: Vim9: optional function arguments don't work yet
Bram Moolenaar <Bram@vim.org>
parents: 19316
diff changeset
592 // Restore the previous frame.
23976
03819ebd3e6d patch 8.2.2530: Vim9: not enough testing for profiling
Bram Moolenaar <Bram@vim.org>
parents: 23934
diff changeset
593 ectx->ec_dfunc_idx = prev_dfunc_idx;
23559
64dfb69e7d46 patch 8.2.2322: Vim9: closure nested limiting to one level
Bram Moolenaar <Bram@vim.org>
parents: 23557
diff changeset
594 ectx->ec_iidx = STACK_TV(ectx->ec_frame_idx
64dfb69e7d46 patch 8.2.2322: Vim9: closure nested limiting to one level
Bram Moolenaar <Bram@vim.org>
parents: 23557
diff changeset
595 + STACK_FRAME_IIDX_OFF)->vval.v_number;
24545
fe29b220eece patch 8.2.2812: Vim9: still crash when using substitute expression
Bram Moolenaar <Bram@vim.org>
parents: 24541
diff changeset
596 ectx->ec_instr = (void *)STACK_TV(ectx->ec_frame_idx
fe29b220eece patch 8.2.2812: Vim9: still crash when using substitute expression
Bram Moolenaar <Bram@vim.org>
parents: 24541
diff changeset
597 + STACK_FRAME_INSTR_OFF)->vval.v_string;
23559
64dfb69e7d46 patch 8.2.2322: Vim9: closure nested limiting to one level
Bram Moolenaar <Bram@vim.org>
parents: 23557
diff changeset
598 ectx->ec_outer = (void *)STACK_TV(ectx->ec_frame_idx
64dfb69e7d46 patch 8.2.2322: Vim9: closure nested limiting to one level
Bram Moolenaar <Bram@vim.org>
parents: 23557
diff changeset
599 + STACK_FRAME_OUTER_OFF)->vval.v_string;
24218
40e27d96e395 patch 8.2.2650: Vim9: command modifiers not handled in nested function
Bram Moolenaar <Bram@vim.org>
parents: 24146
diff changeset
600 floc = (void *)STACK_TV(ectx->ec_frame_idx
40e27d96e395 patch 8.2.2650: Vim9: command modifiers not handled in nested function
Bram Moolenaar <Bram@vim.org>
parents: 24146
diff changeset
601 + STACK_FRAME_FUNCLOCAL_OFF)->vval.v_string;
22460
4097509ecc1e patch 8.2.1778: Vim9: returning from a partial call clears outer context
Bram Moolenaar <Bram@vim.org>
parents: 22401
diff changeset
602 // restoring ec_frame_idx must be last
23559
64dfb69e7d46 patch 8.2.2322: Vim9: closure nested limiting to one level
Bram Moolenaar <Bram@vim.org>
parents: 23557
diff changeset
603 ectx->ec_frame_idx = STACK_TV(ectx->ec_frame_idx
64dfb69e7d46 patch 8.2.2322: Vim9: closure nested limiting to one level
Bram Moolenaar <Bram@vim.org>
parents: 23557
diff changeset
604 + STACK_FRAME_IDX_OFF)->vval.v_number;
24541
df90c61c306c patch 8.2.2810: Vim9: crash when calling a function in a substitute expression
Bram Moolenaar <Bram@vim.org>
parents: 24504
diff changeset
605
24218
40e27d96e395 patch 8.2.2650: Vim9: command modifiers not handled in nested function
Bram Moolenaar <Bram@vim.org>
parents: 24146
diff changeset
606 if (floc == NULL)
24488
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
607 ectx->ec_funclocal.floc_restore_cmdmod = FALSE;
24218
40e27d96e395 patch 8.2.2650: Vim9: command modifiers not handled in nested function
Bram Moolenaar <Bram@vim.org>
parents: 24146
diff changeset
608 else
40e27d96e395 patch 8.2.2650: Vim9: command modifiers not handled in nested function
Bram Moolenaar <Bram@vim.org>
parents: 24146
diff changeset
609 {
24488
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
610 ectx->ec_funclocal = *floc;
24218
40e27d96e395 patch 8.2.2650: Vim9: command modifiers not handled in nested function
Bram Moolenaar <Bram@vim.org>
parents: 24146
diff changeset
611 vim_free(floc);
40e27d96e395 patch 8.2.2650: Vim9: command modifiers not handled in nested function
Bram Moolenaar <Bram@vim.org>
parents: 24146
diff changeset
612 }
40e27d96e395 patch 8.2.2650: Vim9: command modifiers not handled in nested function
Bram Moolenaar <Bram@vim.org>
parents: 24146
diff changeset
613
23009
1fa84623fc68 patch 8.2.2051: Vim9: crash when aborting a user function call
Bram Moolenaar <Bram@vim.org>
parents: 22975
diff changeset
614 if (ret_idx > 0)
1fa84623fc68 patch 8.2.2051: Vim9: crash when aborting a user function call
Bram Moolenaar <Bram@vim.org>
parents: 22975
diff changeset
615 {
1fa84623fc68 patch 8.2.2051: Vim9: crash when aborting a user function call
Bram Moolenaar <Bram@vim.org>
parents: 22975
diff changeset
616 // Reset the stack to the position before the call, with a spot for the
1fa84623fc68 patch 8.2.2051: Vim9: crash when aborting a user function call
Bram Moolenaar <Bram@vim.org>
parents: 22975
diff changeset
617 // return value, moved there from above the frame.
1fa84623fc68 patch 8.2.2051: Vim9: crash when aborting a user function call
Bram Moolenaar <Bram@vim.org>
parents: 22975
diff changeset
618 ectx->ec_stack.ga_len = top + 1;
1fa84623fc68 patch 8.2.2051: Vim9: crash when aborting a user function call
Bram Moolenaar <Bram@vim.org>
parents: 22975
diff changeset
619 *STACK_TV_BOT(-1) = *STACK_TV(ret_idx);
1fa84623fc68 patch 8.2.2051: Vim9: crash when aborting a user function call
Bram Moolenaar <Bram@vim.org>
parents: 22975
diff changeset
620 }
1fa84623fc68 patch 8.2.2051: Vim9: crash when aborting a user function call
Bram Moolenaar <Bram@vim.org>
parents: 22975
diff changeset
621 else
1fa84623fc68 patch 8.2.2051: Vim9: crash when aborting a user function call
Bram Moolenaar <Bram@vim.org>
parents: 22975
diff changeset
622 // Reset the stack to the position before the call.
1fa84623fc68 patch 8.2.2051: Vim9: crash when aborting a user function call
Bram Moolenaar <Bram@vim.org>
parents: 22975
diff changeset
623 ectx->ec_stack.ga_len = top;
20247
e46e72aaff74 patch 8.2.0679: Vim9: incomplete support for closures
Bram Moolenaar <Bram@vim.org>
parents: 20244
diff changeset
624
22908
54219df706b5 patch 8.2.2001: Vim9: :def function does not apply 'maxfuncdepth'
Bram Moolenaar <Bram@vim.org>
parents: 22860
diff changeset
625 funcdepth_decrement();
20247
e46e72aaff74 patch 8.2.0679: Vim9: incomplete support for closures
Bram Moolenaar <Bram@vim.org>
parents: 20244
diff changeset
626 return OK;
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
627 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
628
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
629 #undef STACK_TV
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
630
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
631 /*
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
632 * Prepare arguments and rettv for calling a builtin or user function.
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
633 */
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
634 static int
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
635 call_prepare(int argcount, typval_T *argvars, ectx_T *ectx)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
636 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
637 int idx;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
638 typval_T *tv;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
639
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
640 // Move arguments from bottom of the stack to argvars[] and add terminator.
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
641 for (idx = 0; idx < argcount; ++idx)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
642 argvars[idx] = *STACK_TV_BOT(idx - argcount);
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
643 argvars[argcount].v_type = VAR_UNKNOWN;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
644
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
645 // Result replaces the arguments on the stack.
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
646 if (argcount > 0)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
647 ectx->ec_stack.ga_len -= argcount - 1;
20409
fd1b6f4f497e patch 8.2.0759: Vim9: missing changes for performance improvements
Bram Moolenaar <Bram@vim.org>
parents: 20353
diff changeset
648 else if (GA_GROW(&ectx->ec_stack, 1) == FAIL)
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
649 return FAIL;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
650 else
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
651 ++ectx->ec_stack.ga_len;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
652
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
653 // Default return value is zero.
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
654 tv = STACK_TV_BOT(-1);
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
655 tv->v_type = VAR_NUMBER;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
656 tv->vval.v_number = 0;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
657
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
658 return OK;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
659 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
660
21303
7c50dfe302f8 patch 8.2.1202: Vim9: crash when calling a closure from a builtin function
Bram Moolenaar <Bram@vim.org>
parents: 21299
diff changeset
661 // Ugly global to avoid passing the execution context around through many
7c50dfe302f8 patch 8.2.1202: Vim9: crash when calling a closure from a builtin function
Bram Moolenaar <Bram@vim.org>
parents: 21299
diff changeset
662 // layers.
7c50dfe302f8 patch 8.2.1202: Vim9: crash when calling a closure from a builtin function
Bram Moolenaar <Bram@vim.org>
parents: 21299
diff changeset
663 static ectx_T *current_ectx = NULL;
7c50dfe302f8 patch 8.2.1202: Vim9: crash when calling a closure from a builtin function
Bram Moolenaar <Bram@vim.org>
parents: 21299
diff changeset
664
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
665 /*
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
666 * Call a builtin function by index.
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
667 */
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
668 static int
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
669 call_bfunc(int func_idx, int argcount, ectx_T *ectx)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
670 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
671 typval_T argvars[MAX_FUNC_ARGS];
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
672 int idx;
22736
56907027dba7 patch 8.2.1916: Vim9: function call is aborted even when "silent!" is used
Bram Moolenaar <Bram@vim.org>
parents: 22715
diff changeset
673 int did_emsg_before = did_emsg;
21303
7c50dfe302f8 patch 8.2.1202: Vim9: crash when calling a closure from a builtin function
Bram Moolenaar <Bram@vim.org>
parents: 21299
diff changeset
674 ectx_T *prev_ectx = current_ectx;
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
675
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
676 if (call_prepare(argcount, argvars, ectx) == FAIL)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
677 return FAIL;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
678
21303
7c50dfe302f8 patch 8.2.1202: Vim9: crash when calling a closure from a builtin function
Bram Moolenaar <Bram@vim.org>
parents: 21299
diff changeset
679 // Call the builtin function. Set "current_ectx" so that when it
7c50dfe302f8 patch 8.2.1202: Vim9: crash when calling a closure from a builtin function
Bram Moolenaar <Bram@vim.org>
parents: 21299
diff changeset
680 // recursively invokes call_def_function() a closure context can be set.
7c50dfe302f8 patch 8.2.1202: Vim9: crash when calling a closure from a builtin function
Bram Moolenaar <Bram@vim.org>
parents: 21299
diff changeset
681 current_ectx = ectx;
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
682 call_internal_func_by_idx(func_idx, argvars, STACK_TV_BOT(-1));
21303
7c50dfe302f8 patch 8.2.1202: Vim9: crash when calling a closure from a builtin function
Bram Moolenaar <Bram@vim.org>
parents: 21299
diff changeset
683 current_ectx = prev_ectx;
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
684
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
685 // Clear the arguments.
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
686 for (idx = 0; idx < argcount; ++idx)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
687 clear_tv(&argvars[idx]);
20287
ce1b73835822 patch 8.2.0699: Vim9: not all errors tested
Bram Moolenaar <Bram@vim.org>
parents: 20283
diff changeset
688
23177
cc24ac009f29 patch 8.2.2134: Vim9: get E1099 when autocmd triggered in builtin function
Bram Moolenaar <Bram@vim.org>
parents: 23156
diff changeset
689 if (did_emsg > did_emsg_before)
20287
ce1b73835822 patch 8.2.0699: Vim9: not all errors tested
Bram Moolenaar <Bram@vim.org>
parents: 20283
diff changeset
690 return FAIL;
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
691 return OK;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
692 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
693
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
694 /*
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
695 * Execute a user defined function.
23557
f50ee1ae4d9b patch 8.2.2321: Vim9: cannot nest closures
Bram Moolenaar <Bram@vim.org>
parents: 23553
diff changeset
696 * If the function is compiled this will add a stack frame and set the
f50ee1ae4d9b patch 8.2.2321: Vim9: cannot nest closures
Bram Moolenaar <Bram@vim.org>
parents: 23553
diff changeset
697 * instruction pointer at the start of the function.
f50ee1ae4d9b patch 8.2.2321: Vim9: cannot nest closures
Bram Moolenaar <Bram@vim.org>
parents: 23553
diff changeset
698 * Otherwise the function is called here.
23559
64dfb69e7d46 patch 8.2.2322: Vim9: closure nested limiting to one level
Bram Moolenaar <Bram@vim.org>
parents: 23557
diff changeset
699 * If "pt" is not null use "pt->pt_outer" for ec_outer.
19532
b8f778dda1a1 patch 8.2.0323: Vim9: calling a function that is defined later is slow
Bram Moolenaar <Bram@vim.org>
parents: 19528
diff changeset
700 * "iptr" can be used to replace the instruction with a more efficient one.
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
701 */
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
702 static int
23559
64dfb69e7d46 patch 8.2.2322: Vim9: closure nested limiting to one level
Bram Moolenaar <Bram@vim.org>
parents: 23557
diff changeset
703 call_ufunc(
64dfb69e7d46 patch 8.2.2322: Vim9: closure nested limiting to one level
Bram Moolenaar <Bram@vim.org>
parents: 23557
diff changeset
704 ufunc_T *ufunc,
64dfb69e7d46 patch 8.2.2322: Vim9: closure nested limiting to one level
Bram Moolenaar <Bram@vim.org>
parents: 23557
diff changeset
705 partial_T *pt,
64dfb69e7d46 patch 8.2.2322: Vim9: closure nested limiting to one level
Bram Moolenaar <Bram@vim.org>
parents: 23557
diff changeset
706 int argcount,
64dfb69e7d46 patch 8.2.2322: Vim9: closure nested limiting to one level
Bram Moolenaar <Bram@vim.org>
parents: 23557
diff changeset
707 ectx_T *ectx,
64dfb69e7d46 patch 8.2.2322: Vim9: closure nested limiting to one level
Bram Moolenaar <Bram@vim.org>
parents: 23557
diff changeset
708 isn_T *iptr)
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
709 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
710 typval_T argvars[MAX_FUNC_ARGS];
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
711 funcexe_T funcexe;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
712 int error;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
713 int idx;
22742
f7f2d73ff85e patch 8.2.1919: assert_fails() setting emsg_silent changes normal execution
Bram Moolenaar <Bram@vim.org>
parents: 22736
diff changeset
714 int did_emsg_before = did_emsg;
23719
1a7c2685d780 patch 8.2.2401: build fails without +profiling feature
Bram Moolenaar <Bram@vim.org>
parents: 23717
diff changeset
715 #ifdef FEAT_PROFILE
23717
e3720756acdc patch 8.2.2400: Vim9: compiled functions are not profiled
Bram Moolenaar <Bram@vim.org>
parents: 23699
diff changeset
716 int profiling = do_profiling == PROF_YES && ufunc->uf_profiling;
23719
1a7c2685d780 patch 8.2.2401: build fails without +profiling feature
Bram Moolenaar <Bram@vim.org>
parents: 23717
diff changeset
717 #else
1a7c2685d780 patch 8.2.2401: build fails without +profiling feature
Bram Moolenaar <Bram@vim.org>
parents: 23717
diff changeset
718 # define profiling FALSE
1a7c2685d780 patch 8.2.2401: build fails without +profiling feature
Bram Moolenaar <Bram@vim.org>
parents: 23717
diff changeset
719 #endif
23717
e3720756acdc patch 8.2.2400: Vim9: compiled functions are not profiled
Bram Moolenaar <Bram@vim.org>
parents: 23699
diff changeset
720
e3720756acdc patch 8.2.2400: Vim9: compiled functions are not profiled
Bram Moolenaar <Bram@vim.org>
parents: 23699
diff changeset
721 if (func_needs_compiling(ufunc, profiling)
e3720756acdc patch 8.2.2400: Vim9: compiled functions are not profiled
Bram Moolenaar <Bram@vim.org>
parents: 23699
diff changeset
722 && compile_def_function(ufunc, FALSE, profiling, NULL) == FAIL)
20528
489cb75c76b6 patch 8.2.0818: Vim9: using a discovery phase doesn't work well
Bram Moolenaar <Bram@vim.org>
parents: 20433
diff changeset
723 return FAIL;
20943
1693ca876049 patch 8.2.1023: Vim9: redefining a function uses a new index every time
Bram Moolenaar <Bram@vim.org>
parents: 20919
diff changeset
724 if (ufunc->uf_def_status == UF_COMPILED)
19532
b8f778dda1a1 patch 8.2.0323: Vim9: calling a function that is defined later is slow
Bram Moolenaar <Bram@vim.org>
parents: 19528
diff changeset
725 {
23254
4b7e996354e0 patch 8.2.2173: Vim9: get internal error when assigning to undefined variable
Bram Moolenaar <Bram@vim.org>
parents: 23252
diff changeset
726 error = check_user_func_argcount(ufunc, argcount);
23252
35583da6397e patch 8.2.2172: Vim9: number of arguments is not always checked
Bram Moolenaar <Bram@vim.org>
parents: 23249
diff changeset
727 if (error != FCERR_UNKNOWN)
35583da6397e patch 8.2.2172: Vim9: number of arguments is not always checked
Bram Moolenaar <Bram@vim.org>
parents: 23249
diff changeset
728 {
35583da6397e patch 8.2.2172: Vim9: number of arguments is not always checked
Bram Moolenaar <Bram@vim.org>
parents: 23249
diff changeset
729 if (error == FCERR_TOOMANY)
35583da6397e patch 8.2.2172: Vim9: number of arguments is not always checked
Bram Moolenaar <Bram@vim.org>
parents: 23249
diff changeset
730 semsg(_(e_toomanyarg), ufunc->uf_name);
35583da6397e patch 8.2.2172: Vim9: number of arguments is not always checked
Bram Moolenaar <Bram@vim.org>
parents: 23249
diff changeset
731 else
35583da6397e patch 8.2.2172: Vim9: number of arguments is not always checked
Bram Moolenaar <Bram@vim.org>
parents: 23249
diff changeset
732 semsg(_(e_toofewarg), ufunc->uf_name);
35583da6397e patch 8.2.2172: Vim9: number of arguments is not always checked
Bram Moolenaar <Bram@vim.org>
parents: 23249
diff changeset
733 return FAIL;
35583da6397e patch 8.2.2172: Vim9: number of arguments is not always checked
Bram Moolenaar <Bram@vim.org>
parents: 23249
diff changeset
734 }
35583da6397e patch 8.2.2172: Vim9: number of arguments is not always checked
Bram Moolenaar <Bram@vim.org>
parents: 23249
diff changeset
735
19532
b8f778dda1a1 patch 8.2.0323: Vim9: calling a function that is defined later is slow
Bram Moolenaar <Bram@vim.org>
parents: 19528
diff changeset
736 // The function has been compiled, can call it quickly. For a function
b8f778dda1a1 patch 8.2.0323: Vim9: calling a function that is defined later is slow
Bram Moolenaar <Bram@vim.org>
parents: 19528
diff changeset
737 // that was defined later: we can call it directly next time.
23285
112fa621b127 patch 8.2.2188: Vim9: crash when calling global function from :def function
Bram Moolenaar <Bram@vim.org>
parents: 23266
diff changeset
738 // TODO: what if the function was deleted and then defined again?
19532
b8f778dda1a1 patch 8.2.0323: Vim9: calling a function that is defined later is slow
Bram Moolenaar <Bram@vim.org>
parents: 19528
diff changeset
739 if (iptr != NULL)
b8f778dda1a1 patch 8.2.0323: Vim9: calling a function that is defined later is slow
Bram Moolenaar <Bram@vim.org>
parents: 19528
diff changeset
740 {
19726
ad37a198a708 patch 8.2.0419: various memory leaks in Vim9 script code
Bram Moolenaar <Bram@vim.org>
parents: 19635
diff changeset
741 delete_instr(iptr);
19532
b8f778dda1a1 patch 8.2.0323: Vim9: calling a function that is defined later is slow
Bram Moolenaar <Bram@vim.org>
parents: 19528
diff changeset
742 iptr->isn_type = ISN_DCALL;
b8f778dda1a1 patch 8.2.0323: Vim9: calling a function that is defined later is slow
Bram Moolenaar <Bram@vim.org>
parents: 19528
diff changeset
743 iptr->isn_arg.dfunc.cdf_idx = ufunc->uf_dfunc_idx;
b8f778dda1a1 patch 8.2.0323: Vim9: calling a function that is defined later is slow
Bram Moolenaar <Bram@vim.org>
parents: 19528
diff changeset
744 iptr->isn_arg.dfunc.cdf_argcount = argcount;
b8f778dda1a1 patch 8.2.0323: Vim9: calling a function that is defined later is slow
Bram Moolenaar <Bram@vim.org>
parents: 19528
diff changeset
745 }
24488
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
746 return call_dfunc(ufunc->uf_dfunc_idx, pt, argcount, ectx);
19532
b8f778dda1a1 patch 8.2.0323: Vim9: calling a function that is defined later is slow
Bram Moolenaar <Bram@vim.org>
parents: 19528
diff changeset
747 }
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
748
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
749 if (call_prepare(argcount, argvars, ectx) == FAIL)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
750 return FAIL;
20007
aadd1cae2ff5 patch 8.2.0559: clearing a struct is verbose
Bram Moolenaar <Bram@vim.org>
parents: 19981
diff changeset
751 CLEAR_FIELD(funcexe);
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
752 funcexe.evaluate = TRUE;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
753
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
754 // Call the user function. Result goes in last position on the stack.
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
755 // TODO: add selfdict if there is one
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
756 error = call_user_func_check(ufunc, argcount, argvars,
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
757 STACK_TV_BOT(-1), &funcexe, NULL);
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
758
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
759 // Clear the arguments.
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
760 for (idx = 0; idx < argcount; ++idx)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
761 clear_tv(&argvars[idx]);
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
762
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
763 if (error != FCERR_NONE)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
764 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
765 user_func_error(error, ufunc->uf_name);
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
766 return FAIL;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
767 }
22742
f7f2d73ff85e patch 8.2.1919: assert_fails() setting emsg_silent changes normal execution
Bram Moolenaar <Bram@vim.org>
parents: 22736
diff changeset
768 if (did_emsg > did_emsg_before)
21757
6c03897bcd60 patch 8.2.1428: Vim9: :def function does not abort on nested function error
Bram Moolenaar <Bram@vim.org>
parents: 21753
diff changeset
769 // Error other than from calling the function itself.
6c03897bcd60 patch 8.2.1428: Vim9: :def function does not abort on nested function error
Bram Moolenaar <Bram@vim.org>
parents: 21753
diff changeset
770 return FAIL;
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
771 return OK;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
772 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
773
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
774 /*
24220
a7a9176bb542 patch 8.2.2651: Vim9: restoring command modifiers happens after jump
Bram Moolenaar <Bram@vim.org>
parents: 24218
diff changeset
775 * If command modifiers were applied restore them.
a7a9176bb542 patch 8.2.2651: Vim9: restoring command modifiers happens after jump
Bram Moolenaar <Bram@vim.org>
parents: 24218
diff changeset
776 */
a7a9176bb542 patch 8.2.2651: Vim9: restoring command modifiers happens after jump
Bram Moolenaar <Bram@vim.org>
parents: 24218
diff changeset
777 static void
a7a9176bb542 patch 8.2.2651: Vim9: restoring command modifiers happens after jump
Bram Moolenaar <Bram@vim.org>
parents: 24218
diff changeset
778 may_restore_cmdmod(funclocal_T *funclocal)
a7a9176bb542 patch 8.2.2651: Vim9: restoring command modifiers happens after jump
Bram Moolenaar <Bram@vim.org>
parents: 24218
diff changeset
779 {
a7a9176bb542 patch 8.2.2651: Vim9: restoring command modifiers happens after jump
Bram Moolenaar <Bram@vim.org>
parents: 24218
diff changeset
780 if (funclocal->floc_restore_cmdmod)
a7a9176bb542 patch 8.2.2651: Vim9: restoring command modifiers happens after jump
Bram Moolenaar <Bram@vim.org>
parents: 24218
diff changeset
781 {
a7a9176bb542 patch 8.2.2651: Vim9: restoring command modifiers happens after jump
Bram Moolenaar <Bram@vim.org>
parents: 24218
diff changeset
782 cmdmod.cmod_filter_regmatch.regprog = NULL;
a7a9176bb542 patch 8.2.2651: Vim9: restoring command modifiers happens after jump
Bram Moolenaar <Bram@vim.org>
parents: 24218
diff changeset
783 undo_cmdmod(&cmdmod);
a7a9176bb542 patch 8.2.2651: Vim9: restoring command modifiers happens after jump
Bram Moolenaar <Bram@vim.org>
parents: 24218
diff changeset
784 cmdmod = funclocal->floc_save_cmdmod;
a7a9176bb542 patch 8.2.2651: Vim9: restoring command modifiers happens after jump
Bram Moolenaar <Bram@vim.org>
parents: 24218
diff changeset
785 funclocal->floc_restore_cmdmod = FALSE;
a7a9176bb542 patch 8.2.2651: Vim9: restoring command modifiers happens after jump
Bram Moolenaar <Bram@vim.org>
parents: 24218
diff changeset
786 }
a7a9176bb542 patch 8.2.2651: Vim9: restoring command modifiers happens after jump
Bram Moolenaar <Bram@vim.org>
parents: 24218
diff changeset
787 }
a7a9176bb542 patch 8.2.2651: Vim9: restoring command modifiers happens after jump
Bram Moolenaar <Bram@vim.org>
parents: 24218
diff changeset
788
a7a9176bb542 patch 8.2.2651: Vim9: restoring command modifiers happens after jump
Bram Moolenaar <Bram@vim.org>
parents: 24218
diff changeset
789 /*
21753
9ef7ae8ab51c patch 8.2.1426: Vim9: cannot call autoload function in :def function
Bram Moolenaar <Bram@vim.org>
parents: 21576
diff changeset
790 * Return TRUE if an error was given or CTRL-C was pressed.
9ef7ae8ab51c patch 8.2.1426: Vim9: cannot call autoload function in :def function
Bram Moolenaar <Bram@vim.org>
parents: 21576
diff changeset
791 */
9ef7ae8ab51c patch 8.2.1426: Vim9: cannot call autoload function in :def function
Bram Moolenaar <Bram@vim.org>
parents: 21576
diff changeset
792 static int
9ef7ae8ab51c patch 8.2.1426: Vim9: cannot call autoload function in :def function
Bram Moolenaar <Bram@vim.org>
parents: 21576
diff changeset
793 vim9_aborting(int prev_called_emsg)
9ef7ae8ab51c patch 8.2.1426: Vim9: cannot call autoload function in :def function
Bram Moolenaar <Bram@vim.org>
parents: 21576
diff changeset
794 {
9ef7ae8ab51c patch 8.2.1426: Vim9: cannot call autoload function in :def function
Bram Moolenaar <Bram@vim.org>
parents: 21576
diff changeset
795 return called_emsg > prev_called_emsg || got_int || did_throw;
9ef7ae8ab51c patch 8.2.1426: Vim9: cannot call autoload function in :def function
Bram Moolenaar <Bram@vim.org>
parents: 21576
diff changeset
796 }
9ef7ae8ab51c patch 8.2.1426: Vim9: cannot call autoload function in :def function
Bram Moolenaar <Bram@vim.org>
parents: 21576
diff changeset
797
9ef7ae8ab51c patch 8.2.1426: Vim9: cannot call autoload function in :def function
Bram Moolenaar <Bram@vim.org>
parents: 21576
diff changeset
798 /*
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
799 * Execute a function by "name".
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
800 * This can be a builtin function or a user function.
19532
b8f778dda1a1 patch 8.2.0323: Vim9: calling a function that is defined later is slow
Bram Moolenaar <Bram@vim.org>
parents: 19528
diff changeset
801 * "iptr" can be used to replace the instruction with a more efficient one.
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
802 * Returns FAIL if not found without an error message.
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
803 */
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
804 static int
24218
40e27d96e395 patch 8.2.2650: Vim9: command modifiers not handled in nested function
Bram Moolenaar <Bram@vim.org>
parents: 24146
diff changeset
805 call_by_name(
40e27d96e395 patch 8.2.2650: Vim9: command modifiers not handled in nested function
Bram Moolenaar <Bram@vim.org>
parents: 24146
diff changeset
806 char_u *name,
40e27d96e395 patch 8.2.2650: Vim9: command modifiers not handled in nested function
Bram Moolenaar <Bram@vim.org>
parents: 24146
diff changeset
807 int argcount,
40e27d96e395 patch 8.2.2650: Vim9: command modifiers not handled in nested function
Bram Moolenaar <Bram@vim.org>
parents: 24146
diff changeset
808 ectx_T *ectx,
40e27d96e395 patch 8.2.2650: Vim9: command modifiers not handled in nested function
Bram Moolenaar <Bram@vim.org>
parents: 24146
diff changeset
809 isn_T *iptr)
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
810 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
811 ufunc_T *ufunc;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
812
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
813 if (builtin_function(name, -1))
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
814 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
815 int func_idx = find_internal_func(name);
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
816
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
817 if (func_idx < 0)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
818 return FAIL;
21232
3f14e0d4a4dd patch 8.2.1167: Vim9: builtin function method call only supports first arg
Bram Moolenaar <Bram@vim.org>
parents: 21206
diff changeset
819 if (check_internal_func(func_idx, argcount) < 0)
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
820 return FAIL;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
821 return call_bfunc(func_idx, argcount, ectx);
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
822 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
823
20189
63cc54100ae4 patch 8.2.0650: Vim9: script function can be deleted
Bram Moolenaar <Bram@vim.org>
parents: 20172
diff changeset
824 ufunc = find_func(name, FALSE, NULL);
21753
9ef7ae8ab51c patch 8.2.1426: Vim9: cannot call autoload function in :def function
Bram Moolenaar <Bram@vim.org>
parents: 21576
diff changeset
825
9ef7ae8ab51c patch 8.2.1426: Vim9: cannot call autoload function in :def function
Bram Moolenaar <Bram@vim.org>
parents: 21576
diff changeset
826 if (ufunc == NULL)
9ef7ae8ab51c patch 8.2.1426: Vim9: cannot call autoload function in :def function
Bram Moolenaar <Bram@vim.org>
parents: 21576
diff changeset
827 {
9ef7ae8ab51c patch 8.2.1426: Vim9: cannot call autoload function in :def function
Bram Moolenaar <Bram@vim.org>
parents: 21576
diff changeset
828 int called_emsg_before = called_emsg;
9ef7ae8ab51c patch 8.2.1426: Vim9: cannot call autoload function in :def function
Bram Moolenaar <Bram@vim.org>
parents: 21576
diff changeset
829
9ef7ae8ab51c patch 8.2.1426: Vim9: cannot call autoload function in :def function
Bram Moolenaar <Bram@vim.org>
parents: 21576
diff changeset
830 if (script_autoload(name, TRUE))
9ef7ae8ab51c patch 8.2.1426: Vim9: cannot call autoload function in :def function
Bram Moolenaar <Bram@vim.org>
parents: 21576
diff changeset
831 // loaded a package, search for the function again
9ef7ae8ab51c patch 8.2.1426: Vim9: cannot call autoload function in :def function
Bram Moolenaar <Bram@vim.org>
parents: 21576
diff changeset
832 ufunc = find_func(name, FALSE, NULL);
9ef7ae8ab51c patch 8.2.1426: Vim9: cannot call autoload function in :def function
Bram Moolenaar <Bram@vim.org>
parents: 21576
diff changeset
833 if (vim9_aborting(called_emsg_before))
9ef7ae8ab51c patch 8.2.1426: Vim9: cannot call autoload function in :def function
Bram Moolenaar <Bram@vim.org>
parents: 21576
diff changeset
834 return FAIL; // bail out if loading the script caused an error
9ef7ae8ab51c patch 8.2.1426: Vim9: cannot call autoload function in :def function
Bram Moolenaar <Bram@vim.org>
parents: 21576
diff changeset
835 }
9ef7ae8ab51c patch 8.2.1426: Vim9: cannot call autoload function in :def function
Bram Moolenaar <Bram@vim.org>
parents: 21576
diff changeset
836
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
837 if (ufunc != NULL)
24065
a6aec9a89184 patch 8.2.2574: Vim9: crash when calling partial with wrong function
Bram Moolenaar <Bram@vim.org>
parents: 24014
diff changeset
838 {
a6aec9a89184 patch 8.2.2574: Vim9: crash when calling partial with wrong function
Bram Moolenaar <Bram@vim.org>
parents: 24014
diff changeset
839 if (ufunc->uf_arg_types != NULL)
a6aec9a89184 patch 8.2.2574: Vim9: crash when calling partial with wrong function
Bram Moolenaar <Bram@vim.org>
parents: 24014
diff changeset
840 {
a6aec9a89184 patch 8.2.2574: Vim9: crash when calling partial with wrong function
Bram Moolenaar <Bram@vim.org>
parents: 24014
diff changeset
841 int i;
a6aec9a89184 patch 8.2.2574: Vim9: crash when calling partial with wrong function
Bram Moolenaar <Bram@vim.org>
parents: 24014
diff changeset
842 typval_T *argv = STACK_TV_BOT(0) - argcount;
a6aec9a89184 patch 8.2.2574: Vim9: crash when calling partial with wrong function
Bram Moolenaar <Bram@vim.org>
parents: 24014
diff changeset
843
a6aec9a89184 patch 8.2.2574: Vim9: crash when calling partial with wrong function
Bram Moolenaar <Bram@vim.org>
parents: 24014
diff changeset
844 // The function can change at runtime, check that the argument
a6aec9a89184 patch 8.2.2574: Vim9: crash when calling partial with wrong function
Bram Moolenaar <Bram@vim.org>
parents: 24014
diff changeset
845 // types are correct.
a6aec9a89184 patch 8.2.2574: Vim9: crash when calling partial with wrong function
Bram Moolenaar <Bram@vim.org>
parents: 24014
diff changeset
846 for (i = 0; i < argcount; ++i)
a6aec9a89184 patch 8.2.2574: Vim9: crash when calling partial with wrong function
Bram Moolenaar <Bram@vim.org>
parents: 24014
diff changeset
847 {
24077
5006d95ef82d patch 8.2.2580: Vim9: checking vararg type may be wrong
Bram Moolenaar <Bram@vim.org>
parents: 24065
diff changeset
848 type_T *type = NULL;
5006d95ef82d patch 8.2.2580: Vim9: checking vararg type may be wrong
Bram Moolenaar <Bram@vim.org>
parents: 24065
diff changeset
849
5006d95ef82d patch 8.2.2580: Vim9: checking vararg type may be wrong
Bram Moolenaar <Bram@vim.org>
parents: 24065
diff changeset
850 if (i < ufunc->uf_args.ga_len)
5006d95ef82d patch 8.2.2580: Vim9: checking vararg type may be wrong
Bram Moolenaar <Bram@vim.org>
parents: 24065
diff changeset
851 type = ufunc->uf_arg_types[i];
5006d95ef82d patch 8.2.2580: Vim9: checking vararg type may be wrong
Bram Moolenaar <Bram@vim.org>
parents: 24065
diff changeset
852 else if (ufunc->uf_va_type != NULL)
5006d95ef82d patch 8.2.2580: Vim9: checking vararg type may be wrong
Bram Moolenaar <Bram@vim.org>
parents: 24065
diff changeset
853 type = ufunc->uf_va_type->tt_member;
24065
a6aec9a89184 patch 8.2.2574: Vim9: crash when calling partial with wrong function
Bram Moolenaar <Bram@vim.org>
parents: 24014
diff changeset
854 if (type != NULL && check_typval_arg_type(type,
a6aec9a89184 patch 8.2.2574: Vim9: crash when calling partial with wrong function
Bram Moolenaar <Bram@vim.org>
parents: 24014
diff changeset
855 &argv[i], i + 1) == FAIL)
a6aec9a89184 patch 8.2.2574: Vim9: crash when calling partial with wrong function
Bram Moolenaar <Bram@vim.org>
parents: 24014
diff changeset
856 return FAIL;
a6aec9a89184 patch 8.2.2574: Vim9: crash when calling partial with wrong function
Bram Moolenaar <Bram@vim.org>
parents: 24014
diff changeset
857 }
a6aec9a89184 patch 8.2.2574: Vim9: crash when calling partial with wrong function
Bram Moolenaar <Bram@vim.org>
parents: 24014
diff changeset
858 }
a6aec9a89184 patch 8.2.2574: Vim9: crash when calling partial with wrong function
Bram Moolenaar <Bram@vim.org>
parents: 24014
diff changeset
859
24488
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
860 return call_ufunc(ufunc, NULL, argcount, ectx, iptr);
24065
a6aec9a89184 patch 8.2.2574: Vim9: crash when calling partial with wrong function
Bram Moolenaar <Bram@vim.org>
parents: 24014
diff changeset
861 }
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
862
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
863 return FAIL;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
864 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
865
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
866 static int
24218
40e27d96e395 patch 8.2.2650: Vim9: command modifiers not handled in nested function
Bram Moolenaar <Bram@vim.org>
parents: 24146
diff changeset
867 call_partial(
40e27d96e395 patch 8.2.2650: Vim9: command modifiers not handled in nested function
Bram Moolenaar <Bram@vim.org>
parents: 24146
diff changeset
868 typval_T *tv,
40e27d96e395 patch 8.2.2650: Vim9: command modifiers not handled in nested function
Bram Moolenaar <Bram@vim.org>
parents: 24146
diff changeset
869 int argcount_arg,
40e27d96e395 patch 8.2.2650: Vim9: command modifiers not handled in nested function
Bram Moolenaar <Bram@vim.org>
parents: 24146
diff changeset
870 ectx_T *ectx)
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
871 {
21347
d636c7bbe9ab patch 8.2.1224: Vim9: arguments from partial are not used
Bram Moolenaar <Bram@vim.org>
parents: 21303
diff changeset
872 int argcount = argcount_arg;
19862
846fbbacce3a patch 8.2.0487: Vim9: compiling not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19842
diff changeset
873 char_u *name = NULL;
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
874 int called_emsg_before = called_emsg;
23582
b875bbd517a6 patch 8.2.2333: Vim9: warning for uninitialized variable
Bram Moolenaar <Bram@vim.org>
parents: 23580
diff changeset
875 int res = FAIL;
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
876
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
877 if (tv->v_type == VAR_PARTIAL)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
878 {
21347
d636c7bbe9ab patch 8.2.1224: Vim9: arguments from partial are not used
Bram Moolenaar <Bram@vim.org>
parents: 21303
diff changeset
879 partial_T *pt = tv->vval.v_partial;
d636c7bbe9ab patch 8.2.1224: Vim9: arguments from partial are not used
Bram Moolenaar <Bram@vim.org>
parents: 21303
diff changeset
880 int i;
d636c7bbe9ab patch 8.2.1224: Vim9: arguments from partial are not used
Bram Moolenaar <Bram@vim.org>
parents: 21303
diff changeset
881
d636c7bbe9ab patch 8.2.1224: Vim9: arguments from partial are not used
Bram Moolenaar <Bram@vim.org>
parents: 21303
diff changeset
882 if (pt->pt_argc > 0)
d636c7bbe9ab patch 8.2.1224: Vim9: arguments from partial are not used
Bram Moolenaar <Bram@vim.org>
parents: 21303
diff changeset
883 {
d636c7bbe9ab patch 8.2.1224: Vim9: arguments from partial are not used
Bram Moolenaar <Bram@vim.org>
parents: 21303
diff changeset
884 // Make space for arguments from the partial, shift the "argcount"
d636c7bbe9ab patch 8.2.1224: Vim9: arguments from partial are not used
Bram Moolenaar <Bram@vim.org>
parents: 21303
diff changeset
885 // arguments up.
d636c7bbe9ab patch 8.2.1224: Vim9: arguments from partial are not used
Bram Moolenaar <Bram@vim.org>
parents: 21303
diff changeset
886 if (ga_grow(&ectx->ec_stack, pt->pt_argc) == FAIL)
d636c7bbe9ab patch 8.2.1224: Vim9: arguments from partial are not used
Bram Moolenaar <Bram@vim.org>
parents: 21303
diff changeset
887 return FAIL;
d636c7bbe9ab patch 8.2.1224: Vim9: arguments from partial are not used
Bram Moolenaar <Bram@vim.org>
parents: 21303
diff changeset
888 for (i = 1; i <= argcount; ++i)
d636c7bbe9ab patch 8.2.1224: Vim9: arguments from partial are not used
Bram Moolenaar <Bram@vim.org>
parents: 21303
diff changeset
889 *STACK_TV_BOT(-i + pt->pt_argc) = *STACK_TV_BOT(-i);
d636c7bbe9ab patch 8.2.1224: Vim9: arguments from partial are not used
Bram Moolenaar <Bram@vim.org>
parents: 21303
diff changeset
890 ectx->ec_stack.ga_len += pt->pt_argc;
d636c7bbe9ab patch 8.2.1224: Vim9: arguments from partial are not used
Bram Moolenaar <Bram@vim.org>
parents: 21303
diff changeset
891 argcount += pt->pt_argc;
d636c7bbe9ab patch 8.2.1224: Vim9: arguments from partial are not used
Bram Moolenaar <Bram@vim.org>
parents: 21303
diff changeset
892
d636c7bbe9ab patch 8.2.1224: Vim9: arguments from partial are not used
Bram Moolenaar <Bram@vim.org>
parents: 21303
diff changeset
893 // copy the arguments from the partial onto the stack
d636c7bbe9ab patch 8.2.1224: Vim9: arguments from partial are not used
Bram Moolenaar <Bram@vim.org>
parents: 21303
diff changeset
894 for (i = 0; i < pt->pt_argc; ++i)
d636c7bbe9ab patch 8.2.1224: Vim9: arguments from partial are not used
Bram Moolenaar <Bram@vim.org>
parents: 21303
diff changeset
895 copy_tv(&pt->pt_argv[i], STACK_TV_BOT(-argcount + i));
d636c7bbe9ab patch 8.2.1224: Vim9: arguments from partial are not used
Bram Moolenaar <Bram@vim.org>
parents: 21303
diff changeset
896 }
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
897
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
898 if (pt->pt_func != NULL)
24488
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
899 return call_ufunc(pt->pt_func, pt, argcount, ectx, NULL);
23559
64dfb69e7d46 patch 8.2.2322: Vim9: closure nested limiting to one level
Bram Moolenaar <Bram@vim.org>
parents: 23557
diff changeset
900
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
901 name = pt->pt_name;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
902 }
19862
846fbbacce3a patch 8.2.0487: Vim9: compiling not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19842
diff changeset
903 else if (tv->v_type == VAR_FUNC)
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
904 name = tv->vval.v_string;
21983
3fe594c72d8c patch 8.2.1541: Vim9: cannot find function reference for s:Func
Bram Moolenaar <Bram@vim.org>
parents: 21969
diff changeset
905 if (name != NULL)
3fe594c72d8c patch 8.2.1541: Vim9: cannot find function reference for s:Func
Bram Moolenaar <Bram@vim.org>
parents: 21969
diff changeset
906 {
3fe594c72d8c patch 8.2.1541: Vim9: cannot find function reference for s:Func
Bram Moolenaar <Bram@vim.org>
parents: 21969
diff changeset
907 char_u fname_buf[FLEN_FIXED + 1];
3fe594c72d8c patch 8.2.1541: Vim9: cannot find function reference for s:Func
Bram Moolenaar <Bram@vim.org>
parents: 21969
diff changeset
908 char_u *tofree = NULL;
3fe594c72d8c patch 8.2.1541: Vim9: cannot find function reference for s:Func
Bram Moolenaar <Bram@vim.org>
parents: 21969
diff changeset
909 int error = FCERR_NONE;
3fe594c72d8c patch 8.2.1541: Vim9: cannot find function reference for s:Func
Bram Moolenaar <Bram@vim.org>
parents: 21969
diff changeset
910 char_u *fname;
3fe594c72d8c patch 8.2.1541: Vim9: cannot find function reference for s:Func
Bram Moolenaar <Bram@vim.org>
parents: 21969
diff changeset
911
3fe594c72d8c patch 8.2.1541: Vim9: cannot find function reference for s:Func
Bram Moolenaar <Bram@vim.org>
parents: 21969
diff changeset
912 // May need to translate <SNR>123_ to K_SNR.
3fe594c72d8c patch 8.2.1541: Vim9: cannot find function reference for s:Func
Bram Moolenaar <Bram@vim.org>
parents: 21969
diff changeset
913 fname = fname_trans_sid(name, fname_buf, &tofree, &error);
3fe594c72d8c patch 8.2.1541: Vim9: cannot find function reference for s:Func
Bram Moolenaar <Bram@vim.org>
parents: 21969
diff changeset
914 if (error != FCERR_NONE)
3fe594c72d8c patch 8.2.1541: Vim9: cannot find function reference for s:Func
Bram Moolenaar <Bram@vim.org>
parents: 21969
diff changeset
915 res = FAIL;
3fe594c72d8c patch 8.2.1541: Vim9: cannot find function reference for s:Func
Bram Moolenaar <Bram@vim.org>
parents: 21969
diff changeset
916 else
24488
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
917 res = call_by_name(fname, argcount, ectx, NULL);
21983
3fe594c72d8c patch 8.2.1541: Vim9: cannot find function reference for s:Func
Bram Moolenaar <Bram@vim.org>
parents: 21969
diff changeset
918 vim_free(tofree);
3fe594c72d8c patch 8.2.1541: Vim9: cannot find function reference for s:Func
Bram Moolenaar <Bram@vim.org>
parents: 21969
diff changeset
919 }
3fe594c72d8c patch 8.2.1541: Vim9: cannot find function reference for s:Func
Bram Moolenaar <Bram@vim.org>
parents: 21969
diff changeset
920
23582
b875bbd517a6 patch 8.2.2333: Vim9: warning for uninitialized variable
Bram Moolenaar <Bram@vim.org>
parents: 23580
diff changeset
921 if (res == FAIL)
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
922 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
923 if (called_emsg == called_emsg_before)
20287
ce1b73835822 patch 8.2.0699: Vim9: not all errors tested
Bram Moolenaar <Bram@vim.org>
parents: 20283
diff changeset
924 semsg(_(e_unknownfunc),
ce1b73835822 patch 8.2.0699: Vim9: not all errors tested
Bram Moolenaar <Bram@vim.org>
parents: 20283
diff changeset
925 name == NULL ? (char_u *)"[unknown]" : name);
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
926 return FAIL;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
927 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
928 return OK;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
929 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
930
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
931 /*
22272
eb1f5f618c75 patch 8.2.1685: Vim9: cannot declare a constant value
Bram Moolenaar <Bram@vim.org>
parents: 22262
diff changeset
932 * Check if "lock" is VAR_LOCKED or VAR_FIXED. If so give an error and return
eb1f5f618c75 patch 8.2.1685: Vim9: cannot declare a constant value
Bram Moolenaar <Bram@vim.org>
parents: 22262
diff changeset
933 * TRUE.
eb1f5f618c75 patch 8.2.1685: Vim9: cannot declare a constant value
Bram Moolenaar <Bram@vim.org>
parents: 22262
diff changeset
934 */
eb1f5f618c75 patch 8.2.1685: Vim9: cannot declare a constant value
Bram Moolenaar <Bram@vim.org>
parents: 22262
diff changeset
935 static int
eb1f5f618c75 patch 8.2.1685: Vim9: cannot declare a constant value
Bram Moolenaar <Bram@vim.org>
parents: 22262
diff changeset
936 error_if_locked(int lock, char *error)
eb1f5f618c75 patch 8.2.1685: Vim9: cannot declare a constant value
Bram Moolenaar <Bram@vim.org>
parents: 22262
diff changeset
937 {
eb1f5f618c75 patch 8.2.1685: Vim9: cannot declare a constant value
Bram Moolenaar <Bram@vim.org>
parents: 22262
diff changeset
938 if (lock & (VAR_LOCKED | VAR_FIXED))
eb1f5f618c75 patch 8.2.1685: Vim9: cannot declare a constant value
Bram Moolenaar <Bram@vim.org>
parents: 22262
diff changeset
939 {
eb1f5f618c75 patch 8.2.1685: Vim9: cannot declare a constant value
Bram Moolenaar <Bram@vim.org>
parents: 22262
diff changeset
940 emsg(_(error));
eb1f5f618c75 patch 8.2.1685: Vim9: cannot declare a constant value
Bram Moolenaar <Bram@vim.org>
parents: 22262
diff changeset
941 return TRUE;
eb1f5f618c75 patch 8.2.1685: Vim9: cannot declare a constant value
Bram Moolenaar <Bram@vim.org>
parents: 22262
diff changeset
942 }
eb1f5f618c75 patch 8.2.1685: Vim9: cannot declare a constant value
Bram Moolenaar <Bram@vim.org>
parents: 22262
diff changeset
943 return FALSE;
eb1f5f618c75 patch 8.2.1685: Vim9: cannot declare a constant value
Bram Moolenaar <Bram@vim.org>
parents: 22262
diff changeset
944 }
eb1f5f618c75 patch 8.2.1685: Vim9: cannot declare a constant value
Bram Moolenaar <Bram@vim.org>
parents: 22262
diff changeset
945
eb1f5f618c75 patch 8.2.1685: Vim9: cannot declare a constant value
Bram Moolenaar <Bram@vim.org>
parents: 22262
diff changeset
946 /*
23982
9fcd71d0db89 patch 8.2.2533: Vim9: cannot use a range with :unlet
Bram Moolenaar <Bram@vim.org>
parents: 23976
diff changeset
947 * Give an error if "tv" is not a number and return FAIL.
9fcd71d0db89 patch 8.2.2533: Vim9: cannot use a range with :unlet
Bram Moolenaar <Bram@vim.org>
parents: 23976
diff changeset
948 */
9fcd71d0db89 patch 8.2.2533: Vim9: cannot use a range with :unlet
Bram Moolenaar <Bram@vim.org>
parents: 23976
diff changeset
949 static int
9fcd71d0db89 patch 8.2.2533: Vim9: cannot use a range with :unlet
Bram Moolenaar <Bram@vim.org>
parents: 23976
diff changeset
950 check_for_number(typval_T *tv)
9fcd71d0db89 patch 8.2.2533: Vim9: cannot use a range with :unlet
Bram Moolenaar <Bram@vim.org>
parents: 23976
diff changeset
951 {
9fcd71d0db89 patch 8.2.2533: Vim9: cannot use a range with :unlet
Bram Moolenaar <Bram@vim.org>
parents: 23976
diff changeset
952 if (tv->v_type != VAR_NUMBER)
9fcd71d0db89 patch 8.2.2533: Vim9: cannot use a range with :unlet
Bram Moolenaar <Bram@vim.org>
parents: 23976
diff changeset
953 {
9fcd71d0db89 patch 8.2.2533: Vim9: cannot use a range with :unlet
Bram Moolenaar <Bram@vim.org>
parents: 23976
diff changeset
954 semsg(_(e_expected_str_but_got_str),
9fcd71d0db89 patch 8.2.2533: Vim9: cannot use a range with :unlet
Bram Moolenaar <Bram@vim.org>
parents: 23976
diff changeset
955 vartype_name(VAR_NUMBER), vartype_name(tv->v_type));
9fcd71d0db89 patch 8.2.2533: Vim9: cannot use a range with :unlet
Bram Moolenaar <Bram@vim.org>
parents: 23976
diff changeset
956 return FAIL;
9fcd71d0db89 patch 8.2.2533: Vim9: cannot use a range with :unlet
Bram Moolenaar <Bram@vim.org>
parents: 23976
diff changeset
957 }
9fcd71d0db89 patch 8.2.2533: Vim9: cannot use a range with :unlet
Bram Moolenaar <Bram@vim.org>
parents: 23976
diff changeset
958 return OK;
9fcd71d0db89 patch 8.2.2533: Vim9: cannot use a range with :unlet
Bram Moolenaar <Bram@vim.org>
parents: 23976
diff changeset
959 }
9fcd71d0db89 patch 8.2.2533: Vim9: cannot use a range with :unlet
Bram Moolenaar <Bram@vim.org>
parents: 23976
diff changeset
960
9fcd71d0db89 patch 8.2.2533: Vim9: cannot use a range with :unlet
Bram Moolenaar <Bram@vim.org>
parents: 23976
diff changeset
961 /*
19455
655631882288 patch 8.2.0285: unused error message; cannot create s:var
Bram Moolenaar <Bram@vim.org>
parents: 19449
diff changeset
962 * Store "tv" in variable "name".
655631882288 patch 8.2.0285: unused error message; cannot create s:var
Bram Moolenaar <Bram@vim.org>
parents: 19449
diff changeset
963 * This is for s: and g: variables.
655631882288 patch 8.2.0285: unused error message; cannot create s:var
Bram Moolenaar <Bram@vim.org>
parents: 19449
diff changeset
964 */
655631882288 patch 8.2.0285: unused error message; cannot create s:var
Bram Moolenaar <Bram@vim.org>
parents: 19449
diff changeset
965 static void
655631882288 patch 8.2.0285: unused error message; cannot create s:var
Bram Moolenaar <Bram@vim.org>
parents: 19449
diff changeset
966 store_var(char_u *name, typval_T *tv)
655631882288 patch 8.2.0285: unused error message; cannot create s:var
Bram Moolenaar <Bram@vim.org>
parents: 19449
diff changeset
967 {
655631882288 patch 8.2.0285: unused error message; cannot create s:var
Bram Moolenaar <Bram@vim.org>
parents: 19449
diff changeset
968 funccal_entry_T entry;
24293
bbf4b3185554 patch 8.2.2687: Vim9: cannot use "const" for global variable in :def function
Bram Moolenaar <Bram@vim.org>
parents: 24272
diff changeset
969 int flags = ASSIGN_DECL;
bbf4b3185554 patch 8.2.2687: Vim9: cannot use "const" for global variable in :def function
Bram Moolenaar <Bram@vim.org>
parents: 24272
diff changeset
970
bbf4b3185554 patch 8.2.2687: Vim9: cannot use "const" for global variable in :def function
Bram Moolenaar <Bram@vim.org>
parents: 24272
diff changeset
971 if (tv->v_lock)
bbf4b3185554 patch 8.2.2687: Vim9: cannot use "const" for global variable in :def function
Bram Moolenaar <Bram@vim.org>
parents: 24272
diff changeset
972 flags |= ASSIGN_CONST;
19455
655631882288 patch 8.2.0285: unused error message; cannot create s:var
Bram Moolenaar <Bram@vim.org>
parents: 19449
diff changeset
973 save_funccal(&entry);
24293
bbf4b3185554 patch 8.2.2687: Vim9: cannot use "const" for global variable in :def function
Bram Moolenaar <Bram@vim.org>
parents: 24272
diff changeset
974 set_var_const(name, NULL, tv, FALSE, flags, 0);
19455
655631882288 patch 8.2.0285: unused error message; cannot create s:var
Bram Moolenaar <Bram@vim.org>
parents: 19449
diff changeset
975 restore_funccal();
655631882288 patch 8.2.0285: unused error message; cannot create s:var
Bram Moolenaar <Bram@vim.org>
parents: 19449
diff changeset
976 }
655631882288 patch 8.2.0285: unused error message; cannot create s:var
Bram Moolenaar <Bram@vim.org>
parents: 19449
diff changeset
977
23227
ccbbbbed371f patch 8.2.2159: Vim9: when declaring a list it is not allocated yet
Bram Moolenaar <Bram@vim.org>
parents: 23177
diff changeset
978 /*
23266
00f7cd9b6033 patch 8.2.2179: Vim9: crash when indexing a dict with a number
Bram Moolenaar <Bram@vim.org>
parents: 23254
diff changeset
979 * Convert "tv" to a string.
00f7cd9b6033 patch 8.2.2179: Vim9: crash when indexing a dict with a number
Bram Moolenaar <Bram@vim.org>
parents: 23254
diff changeset
980 * Return FAIL if not allowed.
00f7cd9b6033 patch 8.2.2179: Vim9: crash when indexing a dict with a number
Bram Moolenaar <Bram@vim.org>
parents: 23254
diff changeset
981 */
00f7cd9b6033 patch 8.2.2179: Vim9: crash when indexing a dict with a number
Bram Moolenaar <Bram@vim.org>
parents: 23254
diff changeset
982 static int
00f7cd9b6033 patch 8.2.2179: Vim9: crash when indexing a dict with a number
Bram Moolenaar <Bram@vim.org>
parents: 23254
diff changeset
983 do_2string(typval_T *tv, int is_2string_any)
00f7cd9b6033 patch 8.2.2179: Vim9: crash when indexing a dict with a number
Bram Moolenaar <Bram@vim.org>
parents: 23254
diff changeset
984 {
00f7cd9b6033 patch 8.2.2179: Vim9: crash when indexing a dict with a number
Bram Moolenaar <Bram@vim.org>
parents: 23254
diff changeset
985 if (tv->v_type != VAR_STRING)
00f7cd9b6033 patch 8.2.2179: Vim9: crash when indexing a dict with a number
Bram Moolenaar <Bram@vim.org>
parents: 23254
diff changeset
986 {
00f7cd9b6033 patch 8.2.2179: Vim9: crash when indexing a dict with a number
Bram Moolenaar <Bram@vim.org>
parents: 23254
diff changeset
987 char_u *str;
00f7cd9b6033 patch 8.2.2179: Vim9: crash when indexing a dict with a number
Bram Moolenaar <Bram@vim.org>
parents: 23254
diff changeset
988
00f7cd9b6033 patch 8.2.2179: Vim9: crash when indexing a dict with a number
Bram Moolenaar <Bram@vim.org>
parents: 23254
diff changeset
989 if (is_2string_any)
00f7cd9b6033 patch 8.2.2179: Vim9: crash when indexing a dict with a number
Bram Moolenaar <Bram@vim.org>
parents: 23254
diff changeset
990 {
00f7cd9b6033 patch 8.2.2179: Vim9: crash when indexing a dict with a number
Bram Moolenaar <Bram@vim.org>
parents: 23254
diff changeset
991 switch (tv->v_type)
00f7cd9b6033 patch 8.2.2179: Vim9: crash when indexing a dict with a number
Bram Moolenaar <Bram@vim.org>
parents: 23254
diff changeset
992 {
00f7cd9b6033 patch 8.2.2179: Vim9: crash when indexing a dict with a number
Bram Moolenaar <Bram@vim.org>
parents: 23254
diff changeset
993 case VAR_SPECIAL:
00f7cd9b6033 patch 8.2.2179: Vim9: crash when indexing a dict with a number
Bram Moolenaar <Bram@vim.org>
parents: 23254
diff changeset
994 case VAR_BOOL:
00f7cd9b6033 patch 8.2.2179: Vim9: crash when indexing a dict with a number
Bram Moolenaar <Bram@vim.org>
parents: 23254
diff changeset
995 case VAR_NUMBER:
00f7cd9b6033 patch 8.2.2179: Vim9: crash when indexing a dict with a number
Bram Moolenaar <Bram@vim.org>
parents: 23254
diff changeset
996 case VAR_FLOAT:
00f7cd9b6033 patch 8.2.2179: Vim9: crash when indexing a dict with a number
Bram Moolenaar <Bram@vim.org>
parents: 23254
diff changeset
997 case VAR_BLOB: break;
00f7cd9b6033 patch 8.2.2179: Vim9: crash when indexing a dict with a number
Bram Moolenaar <Bram@vim.org>
parents: 23254
diff changeset
998 default: to_string_error(tv->v_type);
00f7cd9b6033 patch 8.2.2179: Vim9: crash when indexing a dict with a number
Bram Moolenaar <Bram@vim.org>
parents: 23254
diff changeset
999 return FAIL;
00f7cd9b6033 patch 8.2.2179: Vim9: crash when indexing a dict with a number
Bram Moolenaar <Bram@vim.org>
parents: 23254
diff changeset
1000 }
00f7cd9b6033 patch 8.2.2179: Vim9: crash when indexing a dict with a number
Bram Moolenaar <Bram@vim.org>
parents: 23254
diff changeset
1001 }
23788
d12ef361d9de patch 8.2.2435: setline() gives an error for some types
Bram Moolenaar <Bram@vim.org>
parents: 23735
diff changeset
1002 str = typval_tostring(tv, TRUE);
23266
00f7cd9b6033 patch 8.2.2179: Vim9: crash when indexing a dict with a number
Bram Moolenaar <Bram@vim.org>
parents: 23254
diff changeset
1003 clear_tv(tv);
00f7cd9b6033 patch 8.2.2179: Vim9: crash when indexing a dict with a number
Bram Moolenaar <Bram@vim.org>
parents: 23254
diff changeset
1004 tv->v_type = VAR_STRING;
00f7cd9b6033 patch 8.2.2179: Vim9: crash when indexing a dict with a number
Bram Moolenaar <Bram@vim.org>
parents: 23254
diff changeset
1005 tv->vval.v_string = str;
00f7cd9b6033 patch 8.2.2179: Vim9: crash when indexing a dict with a number
Bram Moolenaar <Bram@vim.org>
parents: 23254
diff changeset
1006 }
00f7cd9b6033 patch 8.2.2179: Vim9: crash when indexing a dict with a number
Bram Moolenaar <Bram@vim.org>
parents: 23254
diff changeset
1007 return OK;
00f7cd9b6033 patch 8.2.2179: Vim9: crash when indexing a dict with a number
Bram Moolenaar <Bram@vim.org>
parents: 23254
diff changeset
1008 }
00f7cd9b6033 patch 8.2.2179: Vim9: crash when indexing a dict with a number
Bram Moolenaar <Bram@vim.org>
parents: 23254
diff changeset
1009
00f7cd9b6033 patch 8.2.2179: Vim9: crash when indexing a dict with a number
Bram Moolenaar <Bram@vim.org>
parents: 23254
diff changeset
1010 /*
23227
ccbbbbed371f patch 8.2.2159: Vim9: when declaring a list it is not allocated yet
Bram Moolenaar <Bram@vim.org>
parents: 23177
diff changeset
1011 * When the value of "sv" is a null list of dict, allocate it.
ccbbbbed371f patch 8.2.2159: Vim9: when declaring a list it is not allocated yet
Bram Moolenaar <Bram@vim.org>
parents: 23177
diff changeset
1012 */
ccbbbbed371f patch 8.2.2159: Vim9: when declaring a list it is not allocated yet
Bram Moolenaar <Bram@vim.org>
parents: 23177
diff changeset
1013 static void
ccbbbbed371f patch 8.2.2159: Vim9: when declaring a list it is not allocated yet
Bram Moolenaar <Bram@vim.org>
parents: 23177
diff changeset
1014 allocate_if_null(typval_T *tv)
ccbbbbed371f patch 8.2.2159: Vim9: when declaring a list it is not allocated yet
Bram Moolenaar <Bram@vim.org>
parents: 23177
diff changeset
1015 {
ccbbbbed371f patch 8.2.2159: Vim9: when declaring a list it is not allocated yet
Bram Moolenaar <Bram@vim.org>
parents: 23177
diff changeset
1016 switch (tv->v_type)
ccbbbbed371f patch 8.2.2159: Vim9: when declaring a list it is not allocated yet
Bram Moolenaar <Bram@vim.org>
parents: 23177
diff changeset
1017 {
ccbbbbed371f patch 8.2.2159: Vim9: when declaring a list it is not allocated yet
Bram Moolenaar <Bram@vim.org>
parents: 23177
diff changeset
1018 case VAR_LIST:
ccbbbbed371f patch 8.2.2159: Vim9: when declaring a list it is not allocated yet
Bram Moolenaar <Bram@vim.org>
parents: 23177
diff changeset
1019 if (tv->vval.v_list == NULL)
23839
23d6ead591c1 patch 8.2.2461: Coverity warns for unchecked return value
Bram Moolenaar <Bram@vim.org>
parents: 23788
diff changeset
1020 (void)rettv_list_alloc(tv);
23227
ccbbbbed371f patch 8.2.2159: Vim9: when declaring a list it is not allocated yet
Bram Moolenaar <Bram@vim.org>
parents: 23177
diff changeset
1021 break;
ccbbbbed371f patch 8.2.2159: Vim9: when declaring a list it is not allocated yet
Bram Moolenaar <Bram@vim.org>
parents: 23177
diff changeset
1022 case VAR_DICT:
ccbbbbed371f patch 8.2.2159: Vim9: when declaring a list it is not allocated yet
Bram Moolenaar <Bram@vim.org>
parents: 23177
diff changeset
1023 if (tv->vval.v_dict == NULL)
23839
23d6ead591c1 patch 8.2.2461: Coverity warns for unchecked return value
Bram Moolenaar <Bram@vim.org>
parents: 23788
diff changeset
1024 (void)rettv_dict_alloc(tv);
23227
ccbbbbed371f patch 8.2.2159: Vim9: when declaring a list it is not allocated yet
Bram Moolenaar <Bram@vim.org>
parents: 23177
diff changeset
1025 break;
24482
3d5a66e478f8 patch 8.2.2781: add() silently skips when adding to null list or blob
Bram Moolenaar <Bram@vim.org>
parents: 24480
diff changeset
1026 case VAR_BLOB:
3d5a66e478f8 patch 8.2.2781: add() silently skips when adding to null list or blob
Bram Moolenaar <Bram@vim.org>
parents: 24480
diff changeset
1027 if (tv->vval.v_blob == NULL)
3d5a66e478f8 patch 8.2.2781: add() silently skips when adding to null list or blob
Bram Moolenaar <Bram@vim.org>
parents: 24480
diff changeset
1028 (void)rettv_blob_alloc(tv);
3d5a66e478f8 patch 8.2.2781: add() silently skips when adding to null list or blob
Bram Moolenaar <Bram@vim.org>
parents: 24480
diff changeset
1029 break;
23227
ccbbbbed371f patch 8.2.2159: Vim9: when declaring a list it is not allocated yet
Bram Moolenaar <Bram@vim.org>
parents: 23177
diff changeset
1030 default:
ccbbbbed371f patch 8.2.2159: Vim9: when declaring a list it is not allocated yet
Bram Moolenaar <Bram@vim.org>
parents: 23177
diff changeset
1031 break;
ccbbbbed371f patch 8.2.2159: Vim9: when declaring a list it is not allocated yet
Bram Moolenaar <Bram@vim.org>
parents: 23177
diff changeset
1032 }
ccbbbbed371f patch 8.2.2159: Vim9: when declaring a list it is not allocated yet
Bram Moolenaar <Bram@vim.org>
parents: 23177
diff changeset
1033 }
20089
7fc5d62fe2a5 patch 8.2.0600: Vim9: cannot read or write w:, t: and b: variables
Bram Moolenaar <Bram@vim.org>
parents: 20079
diff changeset
1034
23551
1bb7fa4f9b35 patch 8.2.2318: Vim9: string and list index work differently
Bram Moolenaar <Bram@vim.org>
parents: 23543
diff changeset
1035 /*
24128
fcbb1d4df15b patch 8.2.2605: Vim9: string index and slice does not include composing chars
Bram Moolenaar <Bram@vim.org>
parents: 24122
diff changeset
1036 * Return the character "str[index]" where "index" is the character index,
fcbb1d4df15b patch 8.2.2605: Vim9: string index and slice does not include composing chars
Bram Moolenaar <Bram@vim.org>
parents: 24122
diff changeset
1037 * including composing characters.
fcbb1d4df15b patch 8.2.2605: Vim9: string index and slice does not include composing chars
Bram Moolenaar <Bram@vim.org>
parents: 24122
diff changeset
1038 * If "index" is out of range NULL is returned.
23551
1bb7fa4f9b35 patch 8.2.2318: Vim9: string and list index work differently
Bram Moolenaar <Bram@vim.org>
parents: 23543
diff changeset
1039 */
1bb7fa4f9b35 patch 8.2.2318: Vim9: string and list index work differently
Bram Moolenaar <Bram@vim.org>
parents: 23543
diff changeset
1040 char_u *
1bb7fa4f9b35 patch 8.2.2318: Vim9: string and list index work differently
Bram Moolenaar <Bram@vim.org>
parents: 23543
diff changeset
1041 char_from_string(char_u *str, varnumber_T index)
1bb7fa4f9b35 patch 8.2.2318: Vim9: string and list index work differently
Bram Moolenaar <Bram@vim.org>
parents: 23543
diff changeset
1042 {
1bb7fa4f9b35 patch 8.2.2318: Vim9: string and list index work differently
Bram Moolenaar <Bram@vim.org>
parents: 23543
diff changeset
1043 size_t nbyte = 0;
1bb7fa4f9b35 patch 8.2.2318: Vim9: string and list index work differently
Bram Moolenaar <Bram@vim.org>
parents: 23543
diff changeset
1044 varnumber_T nchar = index;
1bb7fa4f9b35 patch 8.2.2318: Vim9: string and list index work differently
Bram Moolenaar <Bram@vim.org>
parents: 23543
diff changeset
1045 size_t slen;
1bb7fa4f9b35 patch 8.2.2318: Vim9: string and list index work differently
Bram Moolenaar <Bram@vim.org>
parents: 23543
diff changeset
1046
1bb7fa4f9b35 patch 8.2.2318: Vim9: string and list index work differently
Bram Moolenaar <Bram@vim.org>
parents: 23543
diff changeset
1047 if (str == NULL)
1bb7fa4f9b35 patch 8.2.2318: Vim9: string and list index work differently
Bram Moolenaar <Bram@vim.org>
parents: 23543
diff changeset
1048 return NULL;
1bb7fa4f9b35 patch 8.2.2318: Vim9: string and list index work differently
Bram Moolenaar <Bram@vim.org>
parents: 23543
diff changeset
1049 slen = STRLEN(str);
1bb7fa4f9b35 patch 8.2.2318: Vim9: string and list index work differently
Bram Moolenaar <Bram@vim.org>
parents: 23543
diff changeset
1050
24226
f49f80a0905d patch 8.2.2654: Vim9: getting a character from a string can be slow
Bram Moolenaar <Bram@vim.org>
parents: 24220
diff changeset
1051 // Do the same as for a list: a negative index counts from the end.
f49f80a0905d patch 8.2.2654: Vim9: getting a character from a string can be slow
Bram Moolenaar <Bram@vim.org>
parents: 24220
diff changeset
1052 // Optimization to check the first byte to be below 0x80 (and no composing
f49f80a0905d patch 8.2.2654: Vim9: getting a character from a string can be slow
Bram Moolenaar <Bram@vim.org>
parents: 24220
diff changeset
1053 // character follows) makes this a lot faster.
23551
1bb7fa4f9b35 patch 8.2.2318: Vim9: string and list index work differently
Bram Moolenaar <Bram@vim.org>
parents: 23543
diff changeset
1054 if (index < 0)
1bb7fa4f9b35 patch 8.2.2318: Vim9: string and list index work differently
Bram Moolenaar <Bram@vim.org>
parents: 23543
diff changeset
1055 {
1bb7fa4f9b35 patch 8.2.2318: Vim9: string and list index work differently
Bram Moolenaar <Bram@vim.org>
parents: 23543
diff changeset
1056 int clen = 0;
1bb7fa4f9b35 patch 8.2.2318: Vim9: string and list index work differently
Bram Moolenaar <Bram@vim.org>
parents: 23543
diff changeset
1057
1bb7fa4f9b35 patch 8.2.2318: Vim9: string and list index work differently
Bram Moolenaar <Bram@vim.org>
parents: 23543
diff changeset
1058 for (nbyte = 0; nbyte < slen; ++clen)
24226
f49f80a0905d patch 8.2.2654: Vim9: getting a character from a string can be slow
Bram Moolenaar <Bram@vim.org>
parents: 24220
diff changeset
1059 {
f49f80a0905d patch 8.2.2654: Vim9: getting a character from a string can be slow
Bram Moolenaar <Bram@vim.org>
parents: 24220
diff changeset
1060 if (str[nbyte] < 0x80 && str[nbyte + 1] < 0x80)
f49f80a0905d patch 8.2.2654: Vim9: getting a character from a string can be slow
Bram Moolenaar <Bram@vim.org>
parents: 24220
diff changeset
1061 ++nbyte;
f49f80a0905d patch 8.2.2654: Vim9: getting a character from a string can be slow
Bram Moolenaar <Bram@vim.org>
parents: 24220
diff changeset
1062 else if (enc_utf8)
f49f80a0905d patch 8.2.2654: Vim9: getting a character from a string can be slow
Bram Moolenaar <Bram@vim.org>
parents: 24220
diff changeset
1063 nbyte += utfc_ptr2len(str + nbyte);
f49f80a0905d patch 8.2.2654: Vim9: getting a character from a string can be slow
Bram Moolenaar <Bram@vim.org>
parents: 24220
diff changeset
1064 else
f49f80a0905d patch 8.2.2654: Vim9: getting a character from a string can be slow
Bram Moolenaar <Bram@vim.org>
parents: 24220
diff changeset
1065 nbyte += mb_ptr2len(str + nbyte);
f49f80a0905d patch 8.2.2654: Vim9: getting a character from a string can be slow
Bram Moolenaar <Bram@vim.org>
parents: 24220
diff changeset
1066 }
23551
1bb7fa4f9b35 patch 8.2.2318: Vim9: string and list index work differently
Bram Moolenaar <Bram@vim.org>
parents: 23543
diff changeset
1067 nchar = clen + index;
1bb7fa4f9b35 patch 8.2.2318: Vim9: string and list index work differently
Bram Moolenaar <Bram@vim.org>
parents: 23543
diff changeset
1068 if (nchar < 0)
1bb7fa4f9b35 patch 8.2.2318: Vim9: string and list index work differently
Bram Moolenaar <Bram@vim.org>
parents: 23543
diff changeset
1069 // unlike list: index out of range results in empty string
1bb7fa4f9b35 patch 8.2.2318: Vim9: string and list index work differently
Bram Moolenaar <Bram@vim.org>
parents: 23543
diff changeset
1070 return NULL;
1bb7fa4f9b35 patch 8.2.2318: Vim9: string and list index work differently
Bram Moolenaar <Bram@vim.org>
parents: 23543
diff changeset
1071 }
1bb7fa4f9b35 patch 8.2.2318: Vim9: string and list index work differently
Bram Moolenaar <Bram@vim.org>
parents: 23543
diff changeset
1072
1bb7fa4f9b35 patch 8.2.2318: Vim9: string and list index work differently
Bram Moolenaar <Bram@vim.org>
parents: 23543
diff changeset
1073 for (nbyte = 0; nchar > 0 && nbyte < slen; --nchar)
24226
f49f80a0905d patch 8.2.2654: Vim9: getting a character from a string can be slow
Bram Moolenaar <Bram@vim.org>
parents: 24220
diff changeset
1074 {
f49f80a0905d patch 8.2.2654: Vim9: getting a character from a string can be slow
Bram Moolenaar <Bram@vim.org>
parents: 24220
diff changeset
1075 if (str[nbyte] < 0x80 && str[nbyte + 1] < 0x80)
f49f80a0905d patch 8.2.2654: Vim9: getting a character from a string can be slow
Bram Moolenaar <Bram@vim.org>
parents: 24220
diff changeset
1076 ++nbyte;
f49f80a0905d patch 8.2.2654: Vim9: getting a character from a string can be slow
Bram Moolenaar <Bram@vim.org>
parents: 24220
diff changeset
1077 else if (enc_utf8)
f49f80a0905d patch 8.2.2654: Vim9: getting a character from a string can be slow
Bram Moolenaar <Bram@vim.org>
parents: 24220
diff changeset
1078 nbyte += utfc_ptr2len(str + nbyte);
f49f80a0905d patch 8.2.2654: Vim9: getting a character from a string can be slow
Bram Moolenaar <Bram@vim.org>
parents: 24220
diff changeset
1079 else
f49f80a0905d patch 8.2.2654: Vim9: getting a character from a string can be slow
Bram Moolenaar <Bram@vim.org>
parents: 24220
diff changeset
1080 nbyte += mb_ptr2len(str + nbyte);
f49f80a0905d patch 8.2.2654: Vim9: getting a character from a string can be slow
Bram Moolenaar <Bram@vim.org>
parents: 24220
diff changeset
1081 }
23551
1bb7fa4f9b35 patch 8.2.2318: Vim9: string and list index work differently
Bram Moolenaar <Bram@vim.org>
parents: 23543
diff changeset
1082 if (nbyte >= slen)
1bb7fa4f9b35 patch 8.2.2318: Vim9: string and list index work differently
Bram Moolenaar <Bram@vim.org>
parents: 23543
diff changeset
1083 return NULL;
24128
fcbb1d4df15b patch 8.2.2605: Vim9: string index and slice does not include composing chars
Bram Moolenaar <Bram@vim.org>
parents: 24122
diff changeset
1084 return vim_strnsave(str + nbyte, mb_ptr2len(str + nbyte));
23551
1bb7fa4f9b35 patch 8.2.2318: Vim9: string and list index work differently
Bram Moolenaar <Bram@vim.org>
parents: 23543
diff changeset
1085 }
1bb7fa4f9b35 patch 8.2.2318: Vim9: string and list index work differently
Bram Moolenaar <Bram@vim.org>
parents: 23543
diff changeset
1086
1bb7fa4f9b35 patch 8.2.2318: Vim9: string and list index work differently
Bram Moolenaar <Bram@vim.org>
parents: 23543
diff changeset
1087 /*
1bb7fa4f9b35 patch 8.2.2318: Vim9: string and list index work differently
Bram Moolenaar <Bram@vim.org>
parents: 23543
diff changeset
1088 * Get the byte index for character index "idx" in string "str" with length
24128
fcbb1d4df15b patch 8.2.2605: Vim9: string index and slice does not include composing chars
Bram Moolenaar <Bram@vim.org>
parents: 24122
diff changeset
1089 * "str_len". Composing characters are included.
23551
1bb7fa4f9b35 patch 8.2.2318: Vim9: string and list index work differently
Bram Moolenaar <Bram@vim.org>
parents: 23543
diff changeset
1090 * If going over the end return "str_len".
1bb7fa4f9b35 patch 8.2.2318: Vim9: string and list index work differently
Bram Moolenaar <Bram@vim.org>
parents: 23543
diff changeset
1091 * If "idx" is negative count from the end, -1 is the last character.
1bb7fa4f9b35 patch 8.2.2318: Vim9: string and list index work differently
Bram Moolenaar <Bram@vim.org>
parents: 23543
diff changeset
1092 * When going over the start return -1.
1bb7fa4f9b35 patch 8.2.2318: Vim9: string and list index work differently
Bram Moolenaar <Bram@vim.org>
parents: 23543
diff changeset
1093 */
1bb7fa4f9b35 patch 8.2.2318: Vim9: string and list index work differently
Bram Moolenaar <Bram@vim.org>
parents: 23543
diff changeset
1094 static long
1bb7fa4f9b35 patch 8.2.2318: Vim9: string and list index work differently
Bram Moolenaar <Bram@vim.org>
parents: 23543
diff changeset
1095 char_idx2byte(char_u *str, size_t str_len, varnumber_T idx)
1bb7fa4f9b35 patch 8.2.2318: Vim9: string and list index work differently
Bram Moolenaar <Bram@vim.org>
parents: 23543
diff changeset
1096 {
1bb7fa4f9b35 patch 8.2.2318: Vim9: string and list index work differently
Bram Moolenaar <Bram@vim.org>
parents: 23543
diff changeset
1097 varnumber_T nchar = idx;
1bb7fa4f9b35 patch 8.2.2318: Vim9: string and list index work differently
Bram Moolenaar <Bram@vim.org>
parents: 23543
diff changeset
1098 size_t nbyte = 0;
1bb7fa4f9b35 patch 8.2.2318: Vim9: string and list index work differently
Bram Moolenaar <Bram@vim.org>
parents: 23543
diff changeset
1099
1bb7fa4f9b35 patch 8.2.2318: Vim9: string and list index work differently
Bram Moolenaar <Bram@vim.org>
parents: 23543
diff changeset
1100 if (nchar >= 0)
1bb7fa4f9b35 patch 8.2.2318: Vim9: string and list index work differently
Bram Moolenaar <Bram@vim.org>
parents: 23543
diff changeset
1101 {
1bb7fa4f9b35 patch 8.2.2318: Vim9: string and list index work differently
Bram Moolenaar <Bram@vim.org>
parents: 23543
diff changeset
1102 while (nchar > 0 && nbyte < str_len)
1bb7fa4f9b35 patch 8.2.2318: Vim9: string and list index work differently
Bram Moolenaar <Bram@vim.org>
parents: 23543
diff changeset
1103 {
24128
fcbb1d4df15b patch 8.2.2605: Vim9: string index and slice does not include composing chars
Bram Moolenaar <Bram@vim.org>
parents: 24122
diff changeset
1104 nbyte += mb_ptr2len(str + nbyte);
23551
1bb7fa4f9b35 patch 8.2.2318: Vim9: string and list index work differently
Bram Moolenaar <Bram@vim.org>
parents: 23543
diff changeset
1105 --nchar;
1bb7fa4f9b35 patch 8.2.2318: Vim9: string and list index work differently
Bram Moolenaar <Bram@vim.org>
parents: 23543
diff changeset
1106 }
1bb7fa4f9b35 patch 8.2.2318: Vim9: string and list index work differently
Bram Moolenaar <Bram@vim.org>
parents: 23543
diff changeset
1107 }
1bb7fa4f9b35 patch 8.2.2318: Vim9: string and list index work differently
Bram Moolenaar <Bram@vim.org>
parents: 23543
diff changeset
1108 else
1bb7fa4f9b35 patch 8.2.2318: Vim9: string and list index work differently
Bram Moolenaar <Bram@vim.org>
parents: 23543
diff changeset
1109 {
1bb7fa4f9b35 patch 8.2.2318: Vim9: string and list index work differently
Bram Moolenaar <Bram@vim.org>
parents: 23543
diff changeset
1110 nbyte = str_len;
1bb7fa4f9b35 patch 8.2.2318: Vim9: string and list index work differently
Bram Moolenaar <Bram@vim.org>
parents: 23543
diff changeset
1111 while (nchar < 0 && nbyte > 0)
1bb7fa4f9b35 patch 8.2.2318: Vim9: string and list index work differently
Bram Moolenaar <Bram@vim.org>
parents: 23543
diff changeset
1112 {
1bb7fa4f9b35 patch 8.2.2318: Vim9: string and list index work differently
Bram Moolenaar <Bram@vim.org>
parents: 23543
diff changeset
1113 --nbyte;
1bb7fa4f9b35 patch 8.2.2318: Vim9: string and list index work differently
Bram Moolenaar <Bram@vim.org>
parents: 23543
diff changeset
1114 nbyte -= mb_head_off(str, str + nbyte);
1bb7fa4f9b35 patch 8.2.2318: Vim9: string and list index work differently
Bram Moolenaar <Bram@vim.org>
parents: 23543
diff changeset
1115 ++nchar;
1bb7fa4f9b35 patch 8.2.2318: Vim9: string and list index work differently
Bram Moolenaar <Bram@vim.org>
parents: 23543
diff changeset
1116 }
1bb7fa4f9b35 patch 8.2.2318: Vim9: string and list index work differently
Bram Moolenaar <Bram@vim.org>
parents: 23543
diff changeset
1117 if (nchar < 0)
1bb7fa4f9b35 patch 8.2.2318: Vim9: string and list index work differently
Bram Moolenaar <Bram@vim.org>
parents: 23543
diff changeset
1118 return -1;
1bb7fa4f9b35 patch 8.2.2318: Vim9: string and list index work differently
Bram Moolenaar <Bram@vim.org>
parents: 23543
diff changeset
1119 }
1bb7fa4f9b35 patch 8.2.2318: Vim9: string and list index work differently
Bram Moolenaar <Bram@vim.org>
parents: 23543
diff changeset
1120 return (long)nbyte;
1bb7fa4f9b35 patch 8.2.2318: Vim9: string and list index work differently
Bram Moolenaar <Bram@vim.org>
parents: 23543
diff changeset
1121 }
1bb7fa4f9b35 patch 8.2.2318: Vim9: string and list index work differently
Bram Moolenaar <Bram@vim.org>
parents: 23543
diff changeset
1122
1bb7fa4f9b35 patch 8.2.2318: Vim9: string and list index work differently
Bram Moolenaar <Bram@vim.org>
parents: 23543
diff changeset
1123 /*
24128
fcbb1d4df15b patch 8.2.2605: Vim9: string index and slice does not include composing chars
Bram Moolenaar <Bram@vim.org>
parents: 24122
diff changeset
1124 * Return the slice "str[first : last]" using character indexes. Composing
fcbb1d4df15b patch 8.2.2605: Vim9: string index and slice does not include composing chars
Bram Moolenaar <Bram@vim.org>
parents: 24122
diff changeset
1125 * characters are included.
23604
1816ea68c022 patch 8.2.2344: using inclusive index for slice is not always desired
Bram Moolenaar <Bram@vim.org>
parents: 23582
diff changeset
1126 * "exclusive" is TRUE for slice().
23551
1bb7fa4f9b35 patch 8.2.2318: Vim9: string and list index work differently
Bram Moolenaar <Bram@vim.org>
parents: 23543
diff changeset
1127 * Return NULL when the result is empty.
1bb7fa4f9b35 patch 8.2.2318: Vim9: string and list index work differently
Bram Moolenaar <Bram@vim.org>
parents: 23543
diff changeset
1128 */
1bb7fa4f9b35 patch 8.2.2318: Vim9: string and list index work differently
Bram Moolenaar <Bram@vim.org>
parents: 23543
diff changeset
1129 char_u *
23604
1816ea68c022 patch 8.2.2344: using inclusive index for slice is not always desired
Bram Moolenaar <Bram@vim.org>
parents: 23582
diff changeset
1130 string_slice(char_u *str, varnumber_T first, varnumber_T last, int exclusive)
23551
1bb7fa4f9b35 patch 8.2.2318: Vim9: string and list index work differently
Bram Moolenaar <Bram@vim.org>
parents: 23543
diff changeset
1131 {
1bb7fa4f9b35 patch 8.2.2318: Vim9: string and list index work differently
Bram Moolenaar <Bram@vim.org>
parents: 23543
diff changeset
1132 long start_byte, end_byte;
1bb7fa4f9b35 patch 8.2.2318: Vim9: string and list index work differently
Bram Moolenaar <Bram@vim.org>
parents: 23543
diff changeset
1133 size_t slen;
1bb7fa4f9b35 patch 8.2.2318: Vim9: string and list index work differently
Bram Moolenaar <Bram@vim.org>
parents: 23543
diff changeset
1134
1bb7fa4f9b35 patch 8.2.2318: Vim9: string and list index work differently
Bram Moolenaar <Bram@vim.org>
parents: 23543
diff changeset
1135 if (str == NULL)
1bb7fa4f9b35 patch 8.2.2318: Vim9: string and list index work differently
Bram Moolenaar <Bram@vim.org>
parents: 23543
diff changeset
1136 return NULL;
1bb7fa4f9b35 patch 8.2.2318: Vim9: string and list index work differently
Bram Moolenaar <Bram@vim.org>
parents: 23543
diff changeset
1137 slen = STRLEN(str);
1bb7fa4f9b35 patch 8.2.2318: Vim9: string and list index work differently
Bram Moolenaar <Bram@vim.org>
parents: 23543
diff changeset
1138 start_byte = char_idx2byte(str, slen, first);
1bb7fa4f9b35 patch 8.2.2318: Vim9: string and list index work differently
Bram Moolenaar <Bram@vim.org>
parents: 23543
diff changeset
1139 if (start_byte < 0)
1bb7fa4f9b35 patch 8.2.2318: Vim9: string and list index work differently
Bram Moolenaar <Bram@vim.org>
parents: 23543
diff changeset
1140 start_byte = 0; // first index very negative: use zero
23604
1816ea68c022 patch 8.2.2344: using inclusive index for slice is not always desired
Bram Moolenaar <Bram@vim.org>
parents: 23582
diff changeset
1141 if ((last == -1 && !exclusive) || last == VARNUM_MAX)
23551
1bb7fa4f9b35 patch 8.2.2318: Vim9: string and list index work differently
Bram Moolenaar <Bram@vim.org>
parents: 23543
diff changeset
1142 end_byte = (long)slen;
1bb7fa4f9b35 patch 8.2.2318: Vim9: string and list index work differently
Bram Moolenaar <Bram@vim.org>
parents: 23543
diff changeset
1143 else
1bb7fa4f9b35 patch 8.2.2318: Vim9: string and list index work differently
Bram Moolenaar <Bram@vim.org>
parents: 23543
diff changeset
1144 {
1bb7fa4f9b35 patch 8.2.2318: Vim9: string and list index work differently
Bram Moolenaar <Bram@vim.org>
parents: 23543
diff changeset
1145 end_byte = char_idx2byte(str, slen, last);
23604
1816ea68c022 patch 8.2.2344: using inclusive index for slice is not always desired
Bram Moolenaar <Bram@vim.org>
parents: 23582
diff changeset
1146 if (!exclusive && end_byte >= 0 && end_byte < (long)slen)
23551
1bb7fa4f9b35 patch 8.2.2318: Vim9: string and list index work differently
Bram Moolenaar <Bram@vim.org>
parents: 23543
diff changeset
1147 // end index is inclusive
24128
fcbb1d4df15b patch 8.2.2605: Vim9: string index and slice does not include composing chars
Bram Moolenaar <Bram@vim.org>
parents: 24122
diff changeset
1148 end_byte += mb_ptr2len(str + end_byte);
23551
1bb7fa4f9b35 patch 8.2.2318: Vim9: string and list index work differently
Bram Moolenaar <Bram@vim.org>
parents: 23543
diff changeset
1149 }
1bb7fa4f9b35 patch 8.2.2318: Vim9: string and list index work differently
Bram Moolenaar <Bram@vim.org>
parents: 23543
diff changeset
1150
1bb7fa4f9b35 patch 8.2.2318: Vim9: string and list index work differently
Bram Moolenaar <Bram@vim.org>
parents: 23543
diff changeset
1151 if (start_byte >= (long)slen || end_byte <= start_byte)
1bb7fa4f9b35 patch 8.2.2318: Vim9: string and list index work differently
Bram Moolenaar <Bram@vim.org>
parents: 23543
diff changeset
1152 return NULL;
1bb7fa4f9b35 patch 8.2.2318: Vim9: string and list index work differently
Bram Moolenaar <Bram@vim.org>
parents: 23543
diff changeset
1153 return vim_strnsave(str + start_byte, end_byte - start_byte);
1bb7fa4f9b35 patch 8.2.2318: Vim9: string and list index work differently
Bram Moolenaar <Bram@vim.org>
parents: 23543
diff changeset
1154 }
1bb7fa4f9b35 patch 8.2.2318: Vim9: string and list index work differently
Bram Moolenaar <Bram@vim.org>
parents: 23543
diff changeset
1155
23362
f181fe2150ab patch 8.2.2224: Vim9: crash if script reloaded with different variable type
Bram Moolenaar <Bram@vim.org>
parents: 23350
diff changeset
1156 static svar_T *
f181fe2150ab patch 8.2.2224: Vim9: crash if script reloaded with different variable type
Bram Moolenaar <Bram@vim.org>
parents: 23350
diff changeset
1157 get_script_svar(scriptref_T *sref, ectx_T *ectx)
f181fe2150ab patch 8.2.2224: Vim9: crash if script reloaded with different variable type
Bram Moolenaar <Bram@vim.org>
parents: 23350
diff changeset
1158 {
f181fe2150ab patch 8.2.2224: Vim9: crash if script reloaded with different variable type
Bram Moolenaar <Bram@vim.org>
parents: 23350
diff changeset
1159 scriptitem_T *si = SCRIPT_ITEM(sref->sref_sid);
f181fe2150ab patch 8.2.2224: Vim9: crash if script reloaded with different variable type
Bram Moolenaar <Bram@vim.org>
parents: 23350
diff changeset
1160 dfunc_T *dfunc = ((dfunc_T *)def_functions.ga_data)
f181fe2150ab patch 8.2.2224: Vim9: crash if script reloaded with different variable type
Bram Moolenaar <Bram@vim.org>
parents: 23350
diff changeset
1161 + ectx->ec_dfunc_idx;
f181fe2150ab patch 8.2.2224: Vim9: crash if script reloaded with different variable type
Bram Moolenaar <Bram@vim.org>
parents: 23350
diff changeset
1162 svar_T *sv;
f181fe2150ab patch 8.2.2224: Vim9: crash if script reloaded with different variable type
Bram Moolenaar <Bram@vim.org>
parents: 23350
diff changeset
1163
f181fe2150ab patch 8.2.2224: Vim9: crash if script reloaded with different variable type
Bram Moolenaar <Bram@vim.org>
parents: 23350
diff changeset
1164 if (sref->sref_seq != si->sn_script_seq)
f181fe2150ab patch 8.2.2224: Vim9: crash if script reloaded with different variable type
Bram Moolenaar <Bram@vim.org>
parents: 23350
diff changeset
1165 {
f181fe2150ab patch 8.2.2224: Vim9: crash if script reloaded with different variable type
Bram Moolenaar <Bram@vim.org>
parents: 23350
diff changeset
1166 // The script was reloaded after the function was
f181fe2150ab patch 8.2.2224: Vim9: crash if script reloaded with different variable type
Bram Moolenaar <Bram@vim.org>
parents: 23350
diff changeset
1167 // compiled, the script_idx may not be valid.
f181fe2150ab patch 8.2.2224: Vim9: crash if script reloaded with different variable type
Bram Moolenaar <Bram@vim.org>
parents: 23350
diff changeset
1168 semsg(_(e_script_variable_invalid_after_reload_in_function_str),
f181fe2150ab patch 8.2.2224: Vim9: crash if script reloaded with different variable type
Bram Moolenaar <Bram@vim.org>
parents: 23350
diff changeset
1169 dfunc->df_ufunc->uf_name_exp);
f181fe2150ab patch 8.2.2224: Vim9: crash if script reloaded with different variable type
Bram Moolenaar <Bram@vim.org>
parents: 23350
diff changeset
1170 return NULL;
f181fe2150ab patch 8.2.2224: Vim9: crash if script reloaded with different variable type
Bram Moolenaar <Bram@vim.org>
parents: 23350
diff changeset
1171 }
f181fe2150ab patch 8.2.2224: Vim9: crash if script reloaded with different variable type
Bram Moolenaar <Bram@vim.org>
parents: 23350
diff changeset
1172 sv = ((svar_T *)si->sn_var_vals.ga_data) + sref->sref_idx;
f181fe2150ab patch 8.2.2224: Vim9: crash if script reloaded with different variable type
Bram Moolenaar <Bram@vim.org>
parents: 23350
diff changeset
1173 if (!equal_type(sv->sv_type, sref->sref_type))
f181fe2150ab patch 8.2.2224: Vim9: crash if script reloaded with different variable type
Bram Moolenaar <Bram@vim.org>
parents: 23350
diff changeset
1174 {
f181fe2150ab patch 8.2.2224: Vim9: crash if script reloaded with different variable type
Bram Moolenaar <Bram@vim.org>
parents: 23350
diff changeset
1175 emsg(_(e_script_variable_type_changed));
f181fe2150ab patch 8.2.2224: Vim9: crash if script reloaded with different variable type
Bram Moolenaar <Bram@vim.org>
parents: 23350
diff changeset
1176 return NULL;
f181fe2150ab patch 8.2.2224: Vim9: crash if script reloaded with different variable type
Bram Moolenaar <Bram@vim.org>
parents: 23350
diff changeset
1177 }
f181fe2150ab patch 8.2.2224: Vim9: crash if script reloaded with different variable type
Bram Moolenaar <Bram@vim.org>
parents: 23350
diff changeset
1178 return sv;
f181fe2150ab patch 8.2.2224: Vim9: crash if script reloaded with different variable type
Bram Moolenaar <Bram@vim.org>
parents: 23350
diff changeset
1179 }
f181fe2150ab patch 8.2.2224: Vim9: crash if script reloaded with different variable type
Bram Moolenaar <Bram@vim.org>
parents: 23350
diff changeset
1180
19455
655631882288 patch 8.2.0285: unused error message; cannot create s:var
Bram Moolenaar <Bram@vim.org>
parents: 19449
diff changeset
1181 /*
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1182 * Execute a function by "name".
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1183 * This can be a builtin function, user function or a funcref.
19532
b8f778dda1a1 patch 8.2.0323: Vim9: calling a function that is defined later is slow
Bram Moolenaar <Bram@vim.org>
parents: 19528
diff changeset
1184 * "iptr" can be used to replace the instruction with a more efficient one.
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1185 */
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1186 static int
24218
40e27d96e395 patch 8.2.2650: Vim9: command modifiers not handled in nested function
Bram Moolenaar <Bram@vim.org>
parents: 24146
diff changeset
1187 call_eval_func(
40e27d96e395 patch 8.2.2650: Vim9: command modifiers not handled in nested function
Bram Moolenaar <Bram@vim.org>
parents: 24146
diff changeset
1188 char_u *name,
40e27d96e395 patch 8.2.2650: Vim9: command modifiers not handled in nested function
Bram Moolenaar <Bram@vim.org>
parents: 24146
diff changeset
1189 int argcount,
40e27d96e395 patch 8.2.2650: Vim9: command modifiers not handled in nested function
Bram Moolenaar <Bram@vim.org>
parents: 24146
diff changeset
1190 ectx_T *ectx,
40e27d96e395 patch 8.2.2650: Vim9: command modifiers not handled in nested function
Bram Moolenaar <Bram@vim.org>
parents: 24146
diff changeset
1191 isn_T *iptr)
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1192 {
21757
6c03897bcd60 patch 8.2.1428: Vim9: :def function does not abort on nested function error
Bram Moolenaar <Bram@vim.org>
parents: 21753
diff changeset
1193 int called_emsg_before = called_emsg;
6c03897bcd60 patch 8.2.1428: Vim9: :def function does not abort on nested function error
Bram Moolenaar <Bram@vim.org>
parents: 21753
diff changeset
1194 int res;
6c03897bcd60 patch 8.2.1428: Vim9: :def function does not abort on nested function error
Bram Moolenaar <Bram@vim.org>
parents: 21753
diff changeset
1195
24488
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
1196 res = call_by_name(name, argcount, ectx, iptr);
21757
6c03897bcd60 patch 8.2.1428: Vim9: :def function does not abort on nested function error
Bram Moolenaar <Bram@vim.org>
parents: 21753
diff changeset
1197 if (res == FAIL && called_emsg == called_emsg_before)
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1198 {
20140
39a18a0df429 patch 8.2.0625: Vim9: confusing error when calling unknown function
Bram Moolenaar <Bram@vim.org>
parents: 20099
diff changeset
1199 dictitem_T *v;
39a18a0df429 patch 8.2.0625: Vim9: confusing error when calling unknown function
Bram Moolenaar <Bram@vim.org>
parents: 20099
diff changeset
1200
39a18a0df429 patch 8.2.0625: Vim9: confusing error when calling unknown function
Bram Moolenaar <Bram@vim.org>
parents: 20099
diff changeset
1201 v = find_var(name, NULL, FALSE);
39a18a0df429 patch 8.2.0625: Vim9: confusing error when calling unknown function
Bram Moolenaar <Bram@vim.org>
parents: 20099
diff changeset
1202 if (v == NULL)
39a18a0df429 patch 8.2.0625: Vim9: confusing error when calling unknown function
Bram Moolenaar <Bram@vim.org>
parents: 20099
diff changeset
1203 {
39a18a0df429 patch 8.2.0625: Vim9: confusing error when calling unknown function
Bram Moolenaar <Bram@vim.org>
parents: 20099
diff changeset
1204 semsg(_(e_unknownfunc), name);
39a18a0df429 patch 8.2.0625: Vim9: confusing error when calling unknown function
Bram Moolenaar <Bram@vim.org>
parents: 20099
diff changeset
1205 return FAIL;
39a18a0df429 patch 8.2.0625: Vim9: confusing error when calling unknown function
Bram Moolenaar <Bram@vim.org>
parents: 20099
diff changeset
1206 }
39a18a0df429 patch 8.2.0625: Vim9: confusing error when calling unknown function
Bram Moolenaar <Bram@vim.org>
parents: 20099
diff changeset
1207 if (v->di_tv.v_type != VAR_PARTIAL && v->di_tv.v_type != VAR_FUNC)
39a18a0df429 patch 8.2.0625: Vim9: confusing error when calling unknown function
Bram Moolenaar <Bram@vim.org>
parents: 20099
diff changeset
1208 {
39a18a0df429 patch 8.2.0625: Vim9: confusing error when calling unknown function
Bram Moolenaar <Bram@vim.org>
parents: 20099
diff changeset
1209 semsg(_(e_unknownfunc), name);
39a18a0df429 patch 8.2.0625: Vim9: confusing error when calling unknown function
Bram Moolenaar <Bram@vim.org>
parents: 20099
diff changeset
1210 return FAIL;
39a18a0df429 patch 8.2.0625: Vim9: confusing error when calling unknown function
Bram Moolenaar <Bram@vim.org>
parents: 20099
diff changeset
1211 }
24488
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
1212 return call_partial(&v->di_tv, argcount, ectx);
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1213 }
21757
6c03897bcd60 patch 8.2.1428: Vim9: :def function does not abort on nested function error
Bram Moolenaar <Bram@vim.org>
parents: 21753
diff changeset
1214 return res;
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1215 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1216
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1217 /*
23249
43532077b5ff patch 8.2.2170: Vim9: a global function defined in a :def function fails
Bram Moolenaar <Bram@vim.org>
parents: 23233
diff changeset
1218 * When a function reference is used, fill a partial with the information
43532077b5ff patch 8.2.2170: Vim9: a global function defined in a :def function fails
Bram Moolenaar <Bram@vim.org>
parents: 23233
diff changeset
1219 * needed, especially when it is used as a closure.
43532077b5ff patch 8.2.2170: Vim9: a global function defined in a :def function fails
Bram Moolenaar <Bram@vim.org>
parents: 23233
diff changeset
1220 */
23285
112fa621b127 patch 8.2.2188: Vim9: crash when calling global function from :def function
Bram Moolenaar <Bram@vim.org>
parents: 23266
diff changeset
1221 int
23249
43532077b5ff patch 8.2.2170: Vim9: a global function defined in a :def function fails
Bram Moolenaar <Bram@vim.org>
parents: 23233
diff changeset
1222 fill_partial_and_closure(partial_T *pt, ufunc_T *ufunc, ectx_T *ectx)
43532077b5ff patch 8.2.2170: Vim9: a global function defined in a :def function fails
Bram Moolenaar <Bram@vim.org>
parents: 23233
diff changeset
1223 {
43532077b5ff patch 8.2.2170: Vim9: a global function defined in a :def function fails
Bram Moolenaar <Bram@vim.org>
parents: 23233
diff changeset
1224 pt->pt_func = ufunc;
43532077b5ff patch 8.2.2170: Vim9: a global function defined in a :def function fails
Bram Moolenaar <Bram@vim.org>
parents: 23233
diff changeset
1225 pt->pt_refcount = 1;
43532077b5ff patch 8.2.2170: Vim9: a global function defined in a :def function fails
Bram Moolenaar <Bram@vim.org>
parents: 23233
diff changeset
1226
23699
317018f62643 patch 8.2.2391: memory leak when creating a global function with closure
Bram Moolenaar <Bram@vim.org>
parents: 23697
diff changeset
1227 if (ufunc->uf_flags & FC_CLOSURE)
23249
43532077b5ff patch 8.2.2170: Vim9: a global function defined in a :def function fails
Bram Moolenaar <Bram@vim.org>
parents: 23233
diff changeset
1228 {
43532077b5ff patch 8.2.2170: Vim9: a global function defined in a :def function fails
Bram Moolenaar <Bram@vim.org>
parents: 23233
diff changeset
1229 dfunc_T *dfunc = ((dfunc_T *)def_functions.ga_data)
43532077b5ff patch 8.2.2170: Vim9: a global function defined in a :def function fails
Bram Moolenaar <Bram@vim.org>
parents: 23233
diff changeset
1230 + ectx->ec_dfunc_idx;
43532077b5ff patch 8.2.2170: Vim9: a global function defined in a :def function fails
Bram Moolenaar <Bram@vim.org>
parents: 23233
diff changeset
1231
43532077b5ff patch 8.2.2170: Vim9: a global function defined in a :def function fails
Bram Moolenaar <Bram@vim.org>
parents: 23233
diff changeset
1232 // The closure needs to find arguments and local
43532077b5ff patch 8.2.2170: Vim9: a global function defined in a :def function fails
Bram Moolenaar <Bram@vim.org>
parents: 23233
diff changeset
1233 // variables in the current stack.
23559
64dfb69e7d46 patch 8.2.2322: Vim9: closure nested limiting to one level
Bram Moolenaar <Bram@vim.org>
parents: 23557
diff changeset
1234 pt->pt_outer.out_stack = &ectx->ec_stack;
64dfb69e7d46 patch 8.2.2322: Vim9: closure nested limiting to one level
Bram Moolenaar <Bram@vim.org>
parents: 23557
diff changeset
1235 pt->pt_outer.out_frame_idx = ectx->ec_frame_idx;
64dfb69e7d46 patch 8.2.2322: Vim9: closure nested limiting to one level
Bram Moolenaar <Bram@vim.org>
parents: 23557
diff changeset
1236 pt->pt_outer.out_up = ectx->ec_outer;
64dfb69e7d46 patch 8.2.2322: Vim9: closure nested limiting to one level
Bram Moolenaar <Bram@vim.org>
parents: 23557
diff changeset
1237 pt->pt_outer.out_up_is_copy = TRUE;
23249
43532077b5ff patch 8.2.2170: Vim9: a global function defined in a :def function fails
Bram Moolenaar <Bram@vim.org>
parents: 23233
diff changeset
1238
43532077b5ff patch 8.2.2170: Vim9: a global function defined in a :def function fails
Bram Moolenaar <Bram@vim.org>
parents: 23233
diff changeset
1239 // If this function returns and the closure is still
43532077b5ff patch 8.2.2170: Vim9: a global function defined in a :def function fails
Bram Moolenaar <Bram@vim.org>
parents: 23233
diff changeset
1240 // being used, we need to make a copy of the context
43532077b5ff patch 8.2.2170: Vim9: a global function defined in a :def function fails
Bram Moolenaar <Bram@vim.org>
parents: 23233
diff changeset
1241 // (arguments and local variables). Store a reference
43532077b5ff patch 8.2.2170: Vim9: a global function defined in a :def function fails
Bram Moolenaar <Bram@vim.org>
parents: 23233
diff changeset
1242 // to the partial so we can handle that.
43532077b5ff patch 8.2.2170: Vim9: a global function defined in a :def function fails
Bram Moolenaar <Bram@vim.org>
parents: 23233
diff changeset
1243 if (ga_grow(&ectx->ec_funcrefs, 1) == FAIL)
43532077b5ff patch 8.2.2170: Vim9: a global function defined in a :def function fails
Bram Moolenaar <Bram@vim.org>
parents: 23233
diff changeset
1244 {
43532077b5ff patch 8.2.2170: Vim9: a global function defined in a :def function fails
Bram Moolenaar <Bram@vim.org>
parents: 23233
diff changeset
1245 vim_free(pt);
43532077b5ff patch 8.2.2170: Vim9: a global function defined in a :def function fails
Bram Moolenaar <Bram@vim.org>
parents: 23233
diff changeset
1246 return FAIL;
43532077b5ff patch 8.2.2170: Vim9: a global function defined in a :def function fails
Bram Moolenaar <Bram@vim.org>
parents: 23233
diff changeset
1247 }
43532077b5ff patch 8.2.2170: Vim9: a global function defined in a :def function fails
Bram Moolenaar <Bram@vim.org>
parents: 23233
diff changeset
1248 // Extra variable keeps the count of closures created
43532077b5ff patch 8.2.2170: Vim9: a global function defined in a :def function fails
Bram Moolenaar <Bram@vim.org>
parents: 23233
diff changeset
1249 // in the current function call.
43532077b5ff patch 8.2.2170: Vim9: a global function defined in a :def function fails
Bram Moolenaar <Bram@vim.org>
parents: 23233
diff changeset
1250 ++(((typval_T *)ectx->ec_stack.ga_data) + ectx->ec_frame_idx
43532077b5ff patch 8.2.2170: Vim9: a global function defined in a :def function fails
Bram Moolenaar <Bram@vim.org>
parents: 23233
diff changeset
1251 + STACK_FRAME_SIZE + dfunc->df_varcount)->vval.v_number;
43532077b5ff patch 8.2.2170: Vim9: a global function defined in a :def function fails
Bram Moolenaar <Bram@vim.org>
parents: 23233
diff changeset
1252
43532077b5ff patch 8.2.2170: Vim9: a global function defined in a :def function fails
Bram Moolenaar <Bram@vim.org>
parents: 23233
diff changeset
1253 ((partial_T **)ectx->ec_funcrefs.ga_data)
43532077b5ff patch 8.2.2170: Vim9: a global function defined in a :def function fails
Bram Moolenaar <Bram@vim.org>
parents: 23233
diff changeset
1254 [ectx->ec_funcrefs.ga_len] = pt;
43532077b5ff patch 8.2.2170: Vim9: a global function defined in a :def function fails
Bram Moolenaar <Bram@vim.org>
parents: 23233
diff changeset
1255 ++pt->pt_refcount;
43532077b5ff patch 8.2.2170: Vim9: a global function defined in a :def function fails
Bram Moolenaar <Bram@vim.org>
parents: 23233
diff changeset
1256 ++ectx->ec_funcrefs.ga_len;
43532077b5ff patch 8.2.2170: Vim9: a global function defined in a :def function fails
Bram Moolenaar <Bram@vim.org>
parents: 23233
diff changeset
1257 }
23699
317018f62643 patch 8.2.2391: memory leak when creating a global function with closure
Bram Moolenaar <Bram@vim.org>
parents: 23697
diff changeset
1258 ++ufunc->uf_refcount;
23249
43532077b5ff patch 8.2.2170: Vim9: a global function defined in a :def function fails
Bram Moolenaar <Bram@vim.org>
parents: 23233
diff changeset
1259 return OK;
43532077b5ff patch 8.2.2170: Vim9: a global function defined in a :def function fails
Bram Moolenaar <Bram@vim.org>
parents: 23233
diff changeset
1260 }
43532077b5ff patch 8.2.2170: Vim9: a global function defined in a :def function fails
Bram Moolenaar <Bram@vim.org>
parents: 23233
diff changeset
1261
24606
a4fda40e0bb9 patch 8.2.2842: Vim9: skip argument to searchpair() is not compiled
Bram Moolenaar <Bram@vim.org>
parents: 24594
diff changeset
1262 // used for v_instr of typval of VAR_INSTR
a4fda40e0bb9 patch 8.2.2842: Vim9: skip argument to searchpair() is not compiled
Bram Moolenaar <Bram@vim.org>
parents: 24594
diff changeset
1263 struct instr_S {
a4fda40e0bb9 patch 8.2.2842: Vim9: skip argument to searchpair() is not compiled
Bram Moolenaar <Bram@vim.org>
parents: 24594
diff changeset
1264 ectx_T *instr_ectx;
a4fda40e0bb9 patch 8.2.2842: Vim9: skip argument to searchpair() is not compiled
Bram Moolenaar <Bram@vim.org>
parents: 24594
diff changeset
1265 isn_T *instr_instr;
a4fda40e0bb9 patch 8.2.2842: Vim9: skip argument to searchpair() is not compiled
Bram Moolenaar <Bram@vim.org>
parents: 24594
diff changeset
1266 };
a4fda40e0bb9 patch 8.2.2842: Vim9: skip argument to searchpair() is not compiled
Bram Moolenaar <Bram@vim.org>
parents: 24594
diff changeset
1267
24488
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
1268 // used for substitute_instr
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
1269 typedef struct subs_expr_S {
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
1270 ectx_T *subs_ectx;
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
1271 isn_T *subs_instr;
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
1272 int subs_status;
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
1273 } subs_expr_T;
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1274
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1275 // Get pointer to item in the stack.
24488
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
1276 #define STACK_TV(idx) (((typval_T *)ectx->ec_stack.ga_data) + idx)
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1277
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1278 // Get pointer to item at the bottom of the stack, -1 is the bottom.
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1279 #undef STACK_TV_BOT
24488
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
1280 #define STACK_TV_BOT(idx) (((typval_T *)ectx->ec_stack.ga_data) + ectx->ec_stack.ga_len + idx)
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1281
19975
4e8e0ce576af patch 8.2.0543: Vim9: function with varargs does not work properly
Bram Moolenaar <Bram@vim.org>
parents: 19964
diff changeset
1282 // Get pointer to a local variable on the stack. Negative for arguments.
24488
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
1283 #define STACK_TV_VAR(idx) (((typval_T *)ectx->ec_stack.ga_data) + ectx->ec_frame_idx + STACK_FRAME_SIZE + idx)
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
1284
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
1285 /*
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
1286 * Execute instructions in execution context "ectx".
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
1287 * Return OK or FAIL;
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
1288 */
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
1289 static int
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
1290 exec_instructions(ectx_T *ectx)
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
1291 {
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
1292 int breakcheck_count = 0;
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
1293 typval_T *tv;
23917
4b417b776b95 patch 8.2.2501: not always clear where an error is reported
Bram Moolenaar <Bram@vim.org>
parents: 23839
diff changeset
1294
24272
cabed216cc2f patch 8.2.2677: Vim9: cannot use only some of the default arguments
Bram Moolenaar <Bram@vim.org>
parents: 24234
diff changeset
1295 // Start execution at the first instruction.
24488
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
1296 ectx->ec_iidx = 0;
19328
e99e6d794597 patch 8.2.0222: Vim9: optional function arguments don't work yet
Bram Moolenaar <Bram@vim.org>
parents: 19316
diff changeset
1297
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1298 for (;;)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1299 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1300 isn_T *iptr;
19726
ad37a198a708 patch 8.2.0419: various memory leaks in Vim9 script code
Bram Moolenaar <Bram@vim.org>
parents: 19635
diff changeset
1301
20409
fd1b6f4f497e patch 8.2.0759: Vim9: missing changes for performance improvements
Bram Moolenaar <Bram@vim.org>
parents: 20353
diff changeset
1302 if (++breakcheck_count >= 100)
fd1b6f4f497e patch 8.2.0759: Vim9: missing changes for performance improvements
Bram Moolenaar <Bram@vim.org>
parents: 20353
diff changeset
1303 {
fd1b6f4f497e patch 8.2.0759: Vim9: missing changes for performance improvements
Bram Moolenaar <Bram@vim.org>
parents: 20353
diff changeset
1304 line_breakcheck();
fd1b6f4f497e patch 8.2.0759: Vim9: missing changes for performance improvements
Bram Moolenaar <Bram@vim.org>
parents: 20353
diff changeset
1305 breakcheck_count = 0;
fd1b6f4f497e patch 8.2.0759: Vim9: missing changes for performance improvements
Bram Moolenaar <Bram@vim.org>
parents: 20353
diff changeset
1306 }
19726
ad37a198a708 patch 8.2.0419: various memory leaks in Vim9 script code
Bram Moolenaar <Bram@vim.org>
parents: 19635
diff changeset
1307 if (got_int)
ad37a198a708 patch 8.2.0419: various memory leaks in Vim9 script code
Bram Moolenaar <Bram@vim.org>
parents: 19635
diff changeset
1308 {
ad37a198a708 patch 8.2.0419: various memory leaks in Vim9 script code
Bram Moolenaar <Bram@vim.org>
parents: 19635
diff changeset
1309 // Turn CTRL-C into an exception.
ad37a198a708 patch 8.2.0419: various memory leaks in Vim9 script code
Bram Moolenaar <Bram@vim.org>
parents: 19635
diff changeset
1310 got_int = FALSE;
19736
4174c4da6ff7 patch 8.2.0424: checking for wrong return value
Bram Moolenaar <Bram@vim.org>
parents: 19726
diff changeset
1311 if (throw_exception("Vim:Interrupt", ET_INTERRUPT, NULL) == FAIL)
24488
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
1312 return FAIL;
19726
ad37a198a708 patch 8.2.0419: various memory leaks in Vim9 script code
Bram Moolenaar <Bram@vim.org>
parents: 19635
diff changeset
1313 did_throw = TRUE;
ad37a198a708 patch 8.2.0419: various memory leaks in Vim9 script code
Bram Moolenaar <Bram@vim.org>
parents: 19635
diff changeset
1314 }
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1315
20079
336483164ca6 patch 8.2.0595: Vim9: not all commands using ends_excmd() tested
Bram Moolenaar <Bram@vim.org>
parents: 20021
diff changeset
1316 if (did_emsg && msg_list != NULL && *msg_list != NULL)
336483164ca6 patch 8.2.0595: Vim9: not all commands using ends_excmd() tested
Bram Moolenaar <Bram@vim.org>
parents: 20021
diff changeset
1317 {
336483164ca6 patch 8.2.0595: Vim9: not all commands using ends_excmd() tested
Bram Moolenaar <Bram@vim.org>
parents: 20021
diff changeset
1318 // Turn an error message into an exception.
336483164ca6 patch 8.2.0595: Vim9: not all commands using ends_excmd() tested
Bram Moolenaar <Bram@vim.org>
parents: 20021
diff changeset
1319 did_emsg = FALSE;
336483164ca6 patch 8.2.0595: Vim9: not all commands using ends_excmd() tested
Bram Moolenaar <Bram@vim.org>
parents: 20021
diff changeset
1320 if (throw_exception(*msg_list, ET_ERROR, NULL) == FAIL)
24488
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
1321 return FAIL;
20079
336483164ca6 patch 8.2.0595: Vim9: not all commands using ends_excmd() tested
Bram Moolenaar <Bram@vim.org>
parents: 20021
diff changeset
1322 did_throw = TRUE;
336483164ca6 patch 8.2.0595: Vim9: not all commands using ends_excmd() tested
Bram Moolenaar <Bram@vim.org>
parents: 20021
diff changeset
1323 *msg_list = NULL;
336483164ca6 patch 8.2.0595: Vim9: not all commands using ends_excmd() tested
Bram Moolenaar <Bram@vim.org>
parents: 20021
diff changeset
1324 }
336483164ca6 patch 8.2.0595: Vim9: not all commands using ends_excmd() tested
Bram Moolenaar <Bram@vim.org>
parents: 20021
diff changeset
1325
24488
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
1326 if (did_throw && !ectx->ec_in_catch)
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1327 {
24488
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
1328 garray_T *trystack = &ectx->ec_trystack;
19726
ad37a198a708 patch 8.2.0419: various memory leaks in Vim9 script code
Bram Moolenaar <Bram@vim.org>
parents: 19635
diff changeset
1329 trycmd_T *trycmd = NULL;
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1330
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1331 // An exception jumps to the first catch, finally, or returns from
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1332 // the current function.
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1333 if (trystack->ga_len > 0)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1334 trycmd = ((trycmd_T *)trystack->ga_data) + trystack->ga_len - 1;
24488
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
1335 if (trycmd != NULL && trycmd->tcd_frame_idx == ectx->ec_frame_idx)
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1336 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1337 // jump to ":catch" or ":finally"
24488
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
1338 ectx->ec_in_catch = TRUE;
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
1339 ectx->ec_iidx = trycmd->tcd_catch_idx;
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1340 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1341 else
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1342 {
21787
837e6a429950 patch 8.2.1443: Vim9: crash when interrupting a nested :def function
Bram Moolenaar <Bram@vim.org>
parents: 21771
diff changeset
1343 // Not inside try or need to return from current functions.
837e6a429950 patch 8.2.1443: Vim9: crash when interrupting a nested :def function
Bram Moolenaar <Bram@vim.org>
parents: 21771
diff changeset
1344 // Push a dummy return value.
24488
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
1345 if (GA_GROW(&ectx->ec_stack, 1) == FAIL)
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
1346 return FAIL;
21787
837e6a429950 patch 8.2.1443: Vim9: crash when interrupting a nested :def function
Bram Moolenaar <Bram@vim.org>
parents: 21771
diff changeset
1347 tv = STACK_TV_BOT(0);
837e6a429950 patch 8.2.1443: Vim9: crash when interrupting a nested :def function
Bram Moolenaar <Bram@vim.org>
parents: 21771
diff changeset
1348 tv->v_type = VAR_NUMBER;
837e6a429950 patch 8.2.1443: Vim9: crash when interrupting a nested :def function
Bram Moolenaar <Bram@vim.org>
parents: 21771
diff changeset
1349 tv->vval.v_number = 0;
24488
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
1350 ++ectx->ec_stack.ga_len;
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
1351 if (ectx->ec_frame_idx == ectx->ec_initial_frame_idx)
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1352 {
21787
837e6a429950 patch 8.2.1443: Vim9: crash when interrupting a nested :def function
Bram Moolenaar <Bram@vim.org>
parents: 21771
diff changeset
1353 // At the toplevel we are done.
19445
6e27e1ffa2a6 patch 8.2.0280: Vim9: throw in :def function not caught higher up
Bram Moolenaar <Bram@vim.org>
parents: 19411
diff changeset
1354 need_rethrow = TRUE;
24488
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
1355 if (handle_closure_in_use(ectx, FALSE) == FAIL)
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
1356 return FAIL;
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1357 goto done;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1358 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1359
24488
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
1360 if (func_return(ectx) == FAIL)
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
1361 return FAIL;
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1362 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1363 continue;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1364 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1365
24488
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
1366 iptr = &ectx->ec_instr[ectx->ec_iidx++];
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1367 switch (iptr->isn_type)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1368 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1369 // execute Ex command line
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1370 case ISN_EXEC:
22810
2d05dd71aac3 patch 8.2.1953: Vim9: extra "unknown" error after other error
Bram Moolenaar <Bram@vim.org>
parents: 22808
diff changeset
1371 {
23580
dc3b7a31c29f patch 8.2.2332: Vim9: missing :endif not reported when using :windo
Bram Moolenaar <Bram@vim.org>
parents: 23569
diff changeset
1372 source_cookie_T cookie;
dc3b7a31c29f patch 8.2.2332: Vim9: missing :endif not reported when using :windo
Bram Moolenaar <Bram@vim.org>
parents: 23569
diff changeset
1373
22810
2d05dd71aac3 patch 8.2.1953: Vim9: extra "unknown" error after other error
Bram Moolenaar <Bram@vim.org>
parents: 22808
diff changeset
1374 SOURCING_LNUM = iptr->isn_lnum;
23580
dc3b7a31c29f patch 8.2.2332: Vim9: missing :endif not reported when using :windo
Bram Moolenaar <Bram@vim.org>
parents: 23569
diff changeset
1375 // Pass getsourceline to get an error for a missing ":end"
dc3b7a31c29f patch 8.2.2332: Vim9: missing :endif not reported when using :windo
Bram Moolenaar <Bram@vim.org>
parents: 23569
diff changeset
1376 // command.
dc3b7a31c29f patch 8.2.2332: Vim9: missing :endif not reported when using :windo
Bram Moolenaar <Bram@vim.org>
parents: 23569
diff changeset
1377 CLEAR_FIELD(cookie);
dc3b7a31c29f patch 8.2.2332: Vim9: missing :endif not reported when using :windo
Bram Moolenaar <Bram@vim.org>
parents: 23569
diff changeset
1378 cookie.sourcing_lnum = iptr->isn_lnum - 1;
dc3b7a31c29f patch 8.2.2332: Vim9: missing :endif not reported when using :windo
Bram Moolenaar <Bram@vim.org>
parents: 23569
diff changeset
1379 if (do_cmdline(iptr->isn_arg.string,
dc3b7a31c29f patch 8.2.2332: Vim9: missing :endif not reported when using :windo
Bram Moolenaar <Bram@vim.org>
parents: 23569
diff changeset
1380 getsourceline, &cookie,
dc3b7a31c29f patch 8.2.2332: Vim9: missing :endif not reported when using :windo
Bram Moolenaar <Bram@vim.org>
parents: 23569
diff changeset
1381 DOCMD_VERBOSE|DOCMD_NOWAIT|DOCMD_KEYTYPED)
dc3b7a31c29f patch 8.2.2332: Vim9: missing :endif not reported when using :windo
Bram Moolenaar <Bram@vim.org>
parents: 23569
diff changeset
1382 == FAIL
dc3b7a31c29f patch 8.2.2332: Vim9: missing :endif not reported when using :windo
Bram Moolenaar <Bram@vim.org>
parents: 23569
diff changeset
1383 || did_emsg)
22948
707b90980de5 patch 8.2.2021: Vim9: get E1099 when autocommand resets did_emsg
Bram Moolenaar <Bram@vim.org>
parents: 22908
diff changeset
1384 goto on_error;
22810
2d05dd71aac3 patch 8.2.1953: Vim9: extra "unknown" error after other error
Bram Moolenaar <Bram@vim.org>
parents: 22808
diff changeset
1385 }
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1386 break;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1387
24606
a4fda40e0bb9 patch 8.2.2842: Vim9: skip argument to searchpair() is not compiled
Bram Moolenaar <Bram@vim.org>
parents: 24594
diff changeset
1388 // push typeval VAR_INSTR with instructions to be executed
a4fda40e0bb9 patch 8.2.2842: Vim9: skip argument to searchpair() is not compiled
Bram Moolenaar <Bram@vim.org>
parents: 24594
diff changeset
1389 case ISN_INSTR:
a4fda40e0bb9 patch 8.2.2842: Vim9: skip argument to searchpair() is not compiled
Bram Moolenaar <Bram@vim.org>
parents: 24594
diff changeset
1390 {
a4fda40e0bb9 patch 8.2.2842: Vim9: skip argument to searchpair() is not compiled
Bram Moolenaar <Bram@vim.org>
parents: 24594
diff changeset
1391 if (GA_GROW(&ectx->ec_stack, 1) == FAIL)
a4fda40e0bb9 patch 8.2.2842: Vim9: skip argument to searchpair() is not compiled
Bram Moolenaar <Bram@vim.org>
parents: 24594
diff changeset
1392 return FAIL;
a4fda40e0bb9 patch 8.2.2842: Vim9: skip argument to searchpair() is not compiled
Bram Moolenaar <Bram@vim.org>
parents: 24594
diff changeset
1393 tv = STACK_TV_BOT(0);
a4fda40e0bb9 patch 8.2.2842: Vim9: skip argument to searchpair() is not compiled
Bram Moolenaar <Bram@vim.org>
parents: 24594
diff changeset
1394 tv->vval.v_instr = ALLOC_ONE(instr_T);
a4fda40e0bb9 patch 8.2.2842: Vim9: skip argument to searchpair() is not compiled
Bram Moolenaar <Bram@vim.org>
parents: 24594
diff changeset
1395 if (tv->vval.v_instr == NULL)
a4fda40e0bb9 patch 8.2.2842: Vim9: skip argument to searchpair() is not compiled
Bram Moolenaar <Bram@vim.org>
parents: 24594
diff changeset
1396 goto on_error;
a4fda40e0bb9 patch 8.2.2842: Vim9: skip argument to searchpair() is not compiled
Bram Moolenaar <Bram@vim.org>
parents: 24594
diff changeset
1397 ++ectx->ec_stack.ga_len;
a4fda40e0bb9 patch 8.2.2842: Vim9: skip argument to searchpair() is not compiled
Bram Moolenaar <Bram@vim.org>
parents: 24594
diff changeset
1398
a4fda40e0bb9 patch 8.2.2842: Vim9: skip argument to searchpair() is not compiled
Bram Moolenaar <Bram@vim.org>
parents: 24594
diff changeset
1399 tv->v_type = VAR_INSTR;
a4fda40e0bb9 patch 8.2.2842: Vim9: skip argument to searchpair() is not compiled
Bram Moolenaar <Bram@vim.org>
parents: 24594
diff changeset
1400 tv->vval.v_instr->instr_ectx = ectx;
a4fda40e0bb9 patch 8.2.2842: Vim9: skip argument to searchpair() is not compiled
Bram Moolenaar <Bram@vim.org>
parents: 24594
diff changeset
1401 tv->vval.v_instr->instr_instr = iptr->isn_arg.instr;
a4fda40e0bb9 patch 8.2.2842: Vim9: skip argument to searchpair() is not compiled
Bram Moolenaar <Bram@vim.org>
parents: 24594
diff changeset
1402 }
a4fda40e0bb9 patch 8.2.2842: Vim9: skip argument to searchpair() is not compiled
Bram Moolenaar <Bram@vim.org>
parents: 24594
diff changeset
1403 break;
a4fda40e0bb9 patch 8.2.2842: Vim9: skip argument to searchpair() is not compiled
Bram Moolenaar <Bram@vim.org>
parents: 24594
diff changeset
1404
24488
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
1405 // execute :substitute with an expression
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
1406 case ISN_SUBSTITUTE:
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
1407 {
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
1408 subs_T *subs = &iptr->isn_arg.subs;
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
1409 source_cookie_T cookie;
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
1410 struct subs_expr_S *save_instr = substitute_instr;
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
1411 struct subs_expr_S subs_instr;
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
1412 int res;
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
1413
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
1414 subs_instr.subs_ectx = ectx;
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
1415 subs_instr.subs_instr = subs->subs_instr;
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
1416 subs_instr.subs_status = OK;
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
1417 substitute_instr = &subs_instr;
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
1418
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
1419 SOURCING_LNUM = iptr->isn_lnum;
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
1420 // This is very much like ISN_EXEC
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
1421 CLEAR_FIELD(cookie);
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
1422 cookie.sourcing_lnum = iptr->isn_lnum - 1;
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
1423 res = do_cmdline(subs->subs_cmd,
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
1424 getsourceline, &cookie,
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
1425 DOCMD_VERBOSE|DOCMD_NOWAIT|DOCMD_KEYTYPED);
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
1426 substitute_instr = save_instr;
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
1427
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
1428 if (res == FAIL || did_emsg
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
1429 || subs_instr.subs_status == FAIL)
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
1430 goto on_error;
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
1431 }
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
1432 break;
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
1433
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
1434 case ISN_FINISH:
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
1435 goto done;
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
1436
24490
08050e45bd06 patch 8.2.2785: Vim9: cannot redirect to local variable
Bram Moolenaar <Bram@vim.org>
parents: 24488
diff changeset
1437 case ISN_REDIRSTART:
08050e45bd06 patch 8.2.2785: Vim9: cannot redirect to local variable
Bram Moolenaar <Bram@vim.org>
parents: 24488
diff changeset
1438 // create a dummy entry for var_redir_str()
08050e45bd06 patch 8.2.2785: Vim9: cannot redirect to local variable
Bram Moolenaar <Bram@vim.org>
parents: 24488
diff changeset
1439 if (alloc_redir_lval() == FAIL)
08050e45bd06 patch 8.2.2785: Vim9: cannot redirect to local variable
Bram Moolenaar <Bram@vim.org>
parents: 24488
diff changeset
1440 goto on_error;
08050e45bd06 patch 8.2.2785: Vim9: cannot redirect to local variable
Bram Moolenaar <Bram@vim.org>
parents: 24488
diff changeset
1441
08050e45bd06 patch 8.2.2785: Vim9: cannot redirect to local variable
Bram Moolenaar <Bram@vim.org>
parents: 24488
diff changeset
1442 // The output is stored in growarray "redir_ga" until
08050e45bd06 patch 8.2.2785: Vim9: cannot redirect to local variable
Bram Moolenaar <Bram@vim.org>
parents: 24488
diff changeset
1443 // redirection ends.
08050e45bd06 patch 8.2.2785: Vim9: cannot redirect to local variable
Bram Moolenaar <Bram@vim.org>
parents: 24488
diff changeset
1444 init_redir_ga();
08050e45bd06 patch 8.2.2785: Vim9: cannot redirect to local variable
Bram Moolenaar <Bram@vim.org>
parents: 24488
diff changeset
1445 redir_vname = 1;
08050e45bd06 patch 8.2.2785: Vim9: cannot redirect to local variable
Bram Moolenaar <Bram@vim.org>
parents: 24488
diff changeset
1446 break;
08050e45bd06 patch 8.2.2785: Vim9: cannot redirect to local variable
Bram Moolenaar <Bram@vim.org>
parents: 24488
diff changeset
1447
08050e45bd06 patch 8.2.2785: Vim9: cannot redirect to local variable
Bram Moolenaar <Bram@vim.org>
parents: 24488
diff changeset
1448 case ISN_REDIREND:
08050e45bd06 patch 8.2.2785: Vim9: cannot redirect to local variable
Bram Moolenaar <Bram@vim.org>
parents: 24488
diff changeset
1449 {
08050e45bd06 patch 8.2.2785: Vim9: cannot redirect to local variable
Bram Moolenaar <Bram@vim.org>
parents: 24488
diff changeset
1450 char_u *res = get_clear_redir_ga();
08050e45bd06 patch 8.2.2785: Vim9: cannot redirect to local variable
Bram Moolenaar <Bram@vim.org>
parents: 24488
diff changeset
1451
08050e45bd06 patch 8.2.2785: Vim9: cannot redirect to local variable
Bram Moolenaar <Bram@vim.org>
parents: 24488
diff changeset
1452 // End redirection, put redirected text on the stack.
08050e45bd06 patch 8.2.2785: Vim9: cannot redirect to local variable
Bram Moolenaar <Bram@vim.org>
parents: 24488
diff changeset
1453 clear_redir_lval();
08050e45bd06 patch 8.2.2785: Vim9: cannot redirect to local variable
Bram Moolenaar <Bram@vim.org>
parents: 24488
diff changeset
1454 redir_vname = 0;
08050e45bd06 patch 8.2.2785: Vim9: cannot redirect to local variable
Bram Moolenaar <Bram@vim.org>
parents: 24488
diff changeset
1455
08050e45bd06 patch 8.2.2785: Vim9: cannot redirect to local variable
Bram Moolenaar <Bram@vim.org>
parents: 24488
diff changeset
1456 if (GA_GROW(&ectx->ec_stack, 1) == FAIL)
08050e45bd06 patch 8.2.2785: Vim9: cannot redirect to local variable
Bram Moolenaar <Bram@vim.org>
parents: 24488
diff changeset
1457 {
08050e45bd06 patch 8.2.2785: Vim9: cannot redirect to local variable
Bram Moolenaar <Bram@vim.org>
parents: 24488
diff changeset
1458 vim_free(res);
08050e45bd06 patch 8.2.2785: Vim9: cannot redirect to local variable
Bram Moolenaar <Bram@vim.org>
parents: 24488
diff changeset
1459 return FAIL;
08050e45bd06 patch 8.2.2785: Vim9: cannot redirect to local variable
Bram Moolenaar <Bram@vim.org>
parents: 24488
diff changeset
1460 }
08050e45bd06 patch 8.2.2785: Vim9: cannot redirect to local variable
Bram Moolenaar <Bram@vim.org>
parents: 24488
diff changeset
1461 tv = STACK_TV_BOT(0);
08050e45bd06 patch 8.2.2785: Vim9: cannot redirect to local variable
Bram Moolenaar <Bram@vim.org>
parents: 24488
diff changeset
1462 tv->v_type = VAR_STRING;
08050e45bd06 patch 8.2.2785: Vim9: cannot redirect to local variable
Bram Moolenaar <Bram@vim.org>
parents: 24488
diff changeset
1463 tv->vval.v_string = res;
08050e45bd06 patch 8.2.2785: Vim9: cannot redirect to local variable
Bram Moolenaar <Bram@vim.org>
parents: 24488
diff changeset
1464 ++ectx->ec_stack.ga_len;
08050e45bd06 patch 8.2.2785: Vim9: cannot redirect to local variable
Bram Moolenaar <Bram@vim.org>
parents: 24488
diff changeset
1465 }
08050e45bd06 patch 8.2.2785: Vim9: cannot redirect to local variable
Bram Moolenaar <Bram@vim.org>
parents: 24488
diff changeset
1466 break;
08050e45bd06 patch 8.2.2785: Vim9: cannot redirect to local variable
Bram Moolenaar <Bram@vim.org>
parents: 24488
diff changeset
1467
24590
2818f846f099 patch 8.2.2834: Vim9: :cexpr does not work with local variables
Bram Moolenaar <Bram@vim.org>
parents: 24549
diff changeset
1468 case ISN_CEXPR_AUCMD:
24594
5c456a88f651 patch 8.2.2836: build failure without the +quickfix feature
Bram Moolenaar <Bram@vim.org>
parents: 24590
diff changeset
1469 #ifdef FEAT_QUICKFIX
24590
2818f846f099 patch 8.2.2834: Vim9: :cexpr does not work with local variables
Bram Moolenaar <Bram@vim.org>
parents: 24549
diff changeset
1470 if (trigger_cexpr_autocmd(iptr->isn_arg.number) == FAIL)
2818f846f099 patch 8.2.2834: Vim9: :cexpr does not work with local variables
Bram Moolenaar <Bram@vim.org>
parents: 24549
diff changeset
1471 goto on_error;
24594
5c456a88f651 patch 8.2.2836: build failure without the +quickfix feature
Bram Moolenaar <Bram@vim.org>
parents: 24590
diff changeset
1472 #endif
24590
2818f846f099 patch 8.2.2834: Vim9: :cexpr does not work with local variables
Bram Moolenaar <Bram@vim.org>
parents: 24549
diff changeset
1473 break;
2818f846f099 patch 8.2.2834: Vim9: :cexpr does not work with local variables
Bram Moolenaar <Bram@vim.org>
parents: 24549
diff changeset
1474
2818f846f099 patch 8.2.2834: Vim9: :cexpr does not work with local variables
Bram Moolenaar <Bram@vim.org>
parents: 24549
diff changeset
1475 case ISN_CEXPR_CORE:
24594
5c456a88f651 patch 8.2.2836: build failure without the +quickfix feature
Bram Moolenaar <Bram@vim.org>
parents: 24590
diff changeset
1476 #ifdef FEAT_QUICKFIX
24590
2818f846f099 patch 8.2.2834: Vim9: :cexpr does not work with local variables
Bram Moolenaar <Bram@vim.org>
parents: 24549
diff changeset
1477 {
2818f846f099 patch 8.2.2834: Vim9: :cexpr does not work with local variables
Bram Moolenaar <Bram@vim.org>
parents: 24549
diff changeset
1478 exarg_T ea;
2818f846f099 patch 8.2.2834: Vim9: :cexpr does not work with local variables
Bram Moolenaar <Bram@vim.org>
parents: 24549
diff changeset
1479 int res;
2818f846f099 patch 8.2.2834: Vim9: :cexpr does not work with local variables
Bram Moolenaar <Bram@vim.org>
parents: 24549
diff changeset
1480
2818f846f099 patch 8.2.2834: Vim9: :cexpr does not work with local variables
Bram Moolenaar <Bram@vim.org>
parents: 24549
diff changeset
1481 CLEAR_FIELD(ea);
2818f846f099 patch 8.2.2834: Vim9: :cexpr does not work with local variables
Bram Moolenaar <Bram@vim.org>
parents: 24549
diff changeset
1482 ea.cmdidx = iptr->isn_arg.cexpr.cexpr_ref->cer_cmdidx;
2818f846f099 patch 8.2.2834: Vim9: :cexpr does not work with local variables
Bram Moolenaar <Bram@vim.org>
parents: 24549
diff changeset
1483 ea.forceit = iptr->isn_arg.cexpr.cexpr_ref->cer_forceit;
2818f846f099 patch 8.2.2834: Vim9: :cexpr does not work with local variables
Bram Moolenaar <Bram@vim.org>
parents: 24549
diff changeset
1484 ea.cmdlinep = &iptr->isn_arg.cexpr.cexpr_ref->cer_cmdline;
2818f846f099 patch 8.2.2834: Vim9: :cexpr does not work with local variables
Bram Moolenaar <Bram@vim.org>
parents: 24549
diff changeset
1485 --ectx->ec_stack.ga_len;
2818f846f099 patch 8.2.2834: Vim9: :cexpr does not work with local variables
Bram Moolenaar <Bram@vim.org>
parents: 24549
diff changeset
1486 tv = STACK_TV_BOT(0);
2818f846f099 patch 8.2.2834: Vim9: :cexpr does not work with local variables
Bram Moolenaar <Bram@vim.org>
parents: 24549
diff changeset
1487 res = cexpr_core(&ea, tv);
2818f846f099 patch 8.2.2834: Vim9: :cexpr does not work with local variables
Bram Moolenaar <Bram@vim.org>
parents: 24549
diff changeset
1488 clear_tv(tv);
2818f846f099 patch 8.2.2834: Vim9: :cexpr does not work with local variables
Bram Moolenaar <Bram@vim.org>
parents: 24549
diff changeset
1489 if (res == FAIL)
2818f846f099 patch 8.2.2834: Vim9: :cexpr does not work with local variables
Bram Moolenaar <Bram@vim.org>
parents: 24549
diff changeset
1490 goto on_error;
2818f846f099 patch 8.2.2834: Vim9: :cexpr does not work with local variables
Bram Moolenaar <Bram@vim.org>
parents: 24549
diff changeset
1491 }
24594
5c456a88f651 patch 8.2.2836: build failure without the +quickfix feature
Bram Moolenaar <Bram@vim.org>
parents: 24590
diff changeset
1492 #endif
24590
2818f846f099 patch 8.2.2834: Vim9: :cexpr does not work with local variables
Bram Moolenaar <Bram@vim.org>
parents: 24549
diff changeset
1493 break;
2818f846f099 patch 8.2.2834: Vim9: :cexpr does not work with local variables
Bram Moolenaar <Bram@vim.org>
parents: 24549
diff changeset
1494
20170
0612c64a2b87 patch 8.2.0640: Vim9: expanding does not work
Bram Moolenaar <Bram@vim.org>
parents: 20142
diff changeset
1495 // execute Ex command from pieces on the stack
0612c64a2b87 patch 8.2.0640: Vim9: expanding does not work
Bram Moolenaar <Bram@vim.org>
parents: 20142
diff changeset
1496 case ISN_EXECCONCAT:
0612c64a2b87 patch 8.2.0640: Vim9: expanding does not work
Bram Moolenaar <Bram@vim.org>
parents: 20142
diff changeset
1497 {
0612c64a2b87 patch 8.2.0640: Vim9: expanding does not work
Bram Moolenaar <Bram@vim.org>
parents: 20142
diff changeset
1498 int count = iptr->isn_arg.number;
20225
eaaee0dfa435 patch 8.2.0668: compiler warning for int/size_t usage
Bram Moolenaar <Bram@vim.org>
parents: 20189
diff changeset
1499 size_t len = 0;
20170
0612c64a2b87 patch 8.2.0640: Vim9: expanding does not work
Bram Moolenaar <Bram@vim.org>
parents: 20142
diff changeset
1500 int pass;
0612c64a2b87 patch 8.2.0640: Vim9: expanding does not work
Bram Moolenaar <Bram@vim.org>
parents: 20142
diff changeset
1501 int i;
0612c64a2b87 patch 8.2.0640: Vim9: expanding does not work
Bram Moolenaar <Bram@vim.org>
parents: 20142
diff changeset
1502 char_u *cmd = NULL;
0612c64a2b87 patch 8.2.0640: Vim9: expanding does not work
Bram Moolenaar <Bram@vim.org>
parents: 20142
diff changeset
1503 char_u *str;
0612c64a2b87 patch 8.2.0640: Vim9: expanding does not work
Bram Moolenaar <Bram@vim.org>
parents: 20142
diff changeset
1504
0612c64a2b87 patch 8.2.0640: Vim9: expanding does not work
Bram Moolenaar <Bram@vim.org>
parents: 20142
diff changeset
1505 for (pass = 1; pass <= 2; ++pass)
0612c64a2b87 patch 8.2.0640: Vim9: expanding does not work
Bram Moolenaar <Bram@vim.org>
parents: 20142
diff changeset
1506 {
0612c64a2b87 patch 8.2.0640: Vim9: expanding does not work
Bram Moolenaar <Bram@vim.org>
parents: 20142
diff changeset
1507 for (i = 0; i < count; ++i)
0612c64a2b87 patch 8.2.0640: Vim9: expanding does not work
Bram Moolenaar <Bram@vim.org>
parents: 20142
diff changeset
1508 {
0612c64a2b87 patch 8.2.0640: Vim9: expanding does not work
Bram Moolenaar <Bram@vim.org>
parents: 20142
diff changeset
1509 tv = STACK_TV_BOT(i - count);
0612c64a2b87 patch 8.2.0640: Vim9: expanding does not work
Bram Moolenaar <Bram@vim.org>
parents: 20142
diff changeset
1510 str = tv->vval.v_string;
0612c64a2b87 patch 8.2.0640: Vim9: expanding does not work
Bram Moolenaar <Bram@vim.org>
parents: 20142
diff changeset
1511 if (str != NULL && *str != NUL)
0612c64a2b87 patch 8.2.0640: Vim9: expanding does not work
Bram Moolenaar <Bram@vim.org>
parents: 20142
diff changeset
1512 {
0612c64a2b87 patch 8.2.0640: Vim9: expanding does not work
Bram Moolenaar <Bram@vim.org>
parents: 20142
diff changeset
1513 if (pass == 2)
0612c64a2b87 patch 8.2.0640: Vim9: expanding does not work
Bram Moolenaar <Bram@vim.org>
parents: 20142
diff changeset
1514 STRCPY(cmd + len, str);
0612c64a2b87 patch 8.2.0640: Vim9: expanding does not work
Bram Moolenaar <Bram@vim.org>
parents: 20142
diff changeset
1515 len += STRLEN(str);
0612c64a2b87 patch 8.2.0640: Vim9: expanding does not work
Bram Moolenaar <Bram@vim.org>
parents: 20142
diff changeset
1516 }
0612c64a2b87 patch 8.2.0640: Vim9: expanding does not work
Bram Moolenaar <Bram@vim.org>
parents: 20142
diff changeset
1517 if (pass == 2)
0612c64a2b87 patch 8.2.0640: Vim9: expanding does not work
Bram Moolenaar <Bram@vim.org>
parents: 20142
diff changeset
1518 clear_tv(tv);
0612c64a2b87 patch 8.2.0640: Vim9: expanding does not work
Bram Moolenaar <Bram@vim.org>
parents: 20142
diff changeset
1519 }
0612c64a2b87 patch 8.2.0640: Vim9: expanding does not work
Bram Moolenaar <Bram@vim.org>
parents: 20142
diff changeset
1520 if (pass == 1)
0612c64a2b87 patch 8.2.0640: Vim9: expanding does not work
Bram Moolenaar <Bram@vim.org>
parents: 20142
diff changeset
1521 {
0612c64a2b87 patch 8.2.0640: Vim9: expanding does not work
Bram Moolenaar <Bram@vim.org>
parents: 20142
diff changeset
1522 cmd = alloc(len + 1);
0612c64a2b87 patch 8.2.0640: Vim9: expanding does not work
Bram Moolenaar <Bram@vim.org>
parents: 20142
diff changeset
1523 if (cmd == NULL)
24488
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
1524 return FAIL;
20170
0612c64a2b87 patch 8.2.0640: Vim9: expanding does not work
Bram Moolenaar <Bram@vim.org>
parents: 20142
diff changeset
1525 len = 0;
0612c64a2b87 patch 8.2.0640: Vim9: expanding does not work
Bram Moolenaar <Bram@vim.org>
parents: 20142
diff changeset
1526 }
0612c64a2b87 patch 8.2.0640: Vim9: expanding does not work
Bram Moolenaar <Bram@vim.org>
parents: 20142
diff changeset
1527 }
0612c64a2b87 patch 8.2.0640: Vim9: expanding does not work
Bram Moolenaar <Bram@vim.org>
parents: 20142
diff changeset
1528
20172
1d84eaed0ec8 patch 8.2.0641: Vim9: not expanded in :hardcopy and syn-include
Bram Moolenaar <Bram@vim.org>
parents: 20170
diff changeset
1529 SOURCING_LNUM = iptr->isn_lnum;
20170
0612c64a2b87 patch 8.2.0640: Vim9: expanding does not work
Bram Moolenaar <Bram@vim.org>
parents: 20142
diff changeset
1530 do_cmdline_cmd(cmd);
0612c64a2b87 patch 8.2.0640: Vim9: expanding does not work
Bram Moolenaar <Bram@vim.org>
parents: 20142
diff changeset
1531 vim_free(cmd);
0612c64a2b87 patch 8.2.0640: Vim9: expanding does not work
Bram Moolenaar <Bram@vim.org>
parents: 20142
diff changeset
1532 }
0612c64a2b87 patch 8.2.0640: Vim9: expanding does not work
Bram Moolenaar <Bram@vim.org>
parents: 20142
diff changeset
1533 break;
0612c64a2b87 patch 8.2.0640: Vim9: expanding does not work
Bram Moolenaar <Bram@vim.org>
parents: 20142
diff changeset
1534
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1535 // execute :echo {string} ...
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1536 case ISN_ECHO:
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1537 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1538 int count = iptr->isn_arg.echo.echo_count;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1539 int atstart = TRUE;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1540 int needclr = TRUE;
24488
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
1541 int idx;
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1542
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1543 for (idx = 0; idx < count; ++idx)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1544 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1545 tv = STACK_TV_BOT(idx - count);
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1546 echo_one(tv, iptr->isn_arg.echo.echo_with_white,
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1547 &atstart, &needclr);
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1548 clear_tv(tv);
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1549 }
19463
798fce18d049 patch 8.2.0289: Vim9: :echo did not clear the rest of the line
Bram Moolenaar <Bram@vim.org>
parents: 19459
diff changeset
1550 if (needclr)
798fce18d049 patch 8.2.0289: Vim9: :echo did not clear the rest of the line
Bram Moolenaar <Bram@vim.org>
parents: 19459
diff changeset
1551 msg_clr_eos();
24488
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
1552 ectx->ec_stack.ga_len -= count;
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1553 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1554 break;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1555
20142
fe8d0a4344df patch 8.2.0626: Vim9: wrong syntax of function in Vim9 script
Bram Moolenaar <Bram@vim.org>
parents: 20140
diff changeset
1556 // :execute {string} ...
fe8d0a4344df patch 8.2.0626: Vim9: wrong syntax of function in Vim9 script
Bram Moolenaar <Bram@vim.org>
parents: 20140
diff changeset
1557 // :echomsg {string} ...
fe8d0a4344df patch 8.2.0626: Vim9: wrong syntax of function in Vim9 script
Bram Moolenaar <Bram@vim.org>
parents: 20140
diff changeset
1558 // :echoerr {string} ...
19528
3b026343f398 patch 8.2.0321: Vim9: ":execute" does not work yet
Bram Moolenaar <Bram@vim.org>
parents: 19463
diff changeset
1559 case ISN_EXECUTE:
20142
fe8d0a4344df patch 8.2.0626: Vim9: wrong syntax of function in Vim9 script
Bram Moolenaar <Bram@vim.org>
parents: 20140
diff changeset
1560 case ISN_ECHOMSG:
fe8d0a4344df patch 8.2.0626: Vim9: wrong syntax of function in Vim9 script
Bram Moolenaar <Bram@vim.org>
parents: 20140
diff changeset
1561 case ISN_ECHOERR:
19528
3b026343f398 patch 8.2.0321: Vim9: ":execute" does not work yet
Bram Moolenaar <Bram@vim.org>
parents: 19463
diff changeset
1562 {
3b026343f398 patch 8.2.0321: Vim9: ":execute" does not work yet
Bram Moolenaar <Bram@vim.org>
parents: 19463
diff changeset
1563 int count = iptr->isn_arg.number;
3b026343f398 patch 8.2.0321: Vim9: ":execute" does not work yet
Bram Moolenaar <Bram@vim.org>
parents: 19463
diff changeset
1564 garray_T ga;
3b026343f398 patch 8.2.0321: Vim9: ":execute" does not work yet
Bram Moolenaar <Bram@vim.org>
parents: 19463
diff changeset
1565 char_u buf[NUMBUFLEN];
3b026343f398 patch 8.2.0321: Vim9: ":execute" does not work yet
Bram Moolenaar <Bram@vim.org>
parents: 19463
diff changeset
1566 char_u *p;
3b026343f398 patch 8.2.0321: Vim9: ":execute" does not work yet
Bram Moolenaar <Bram@vim.org>
parents: 19463
diff changeset
1567 int len;
3b026343f398 patch 8.2.0321: Vim9: ":execute" does not work yet
Bram Moolenaar <Bram@vim.org>
parents: 19463
diff changeset
1568 int failed = FALSE;
24488
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
1569 int idx;
19528
3b026343f398 patch 8.2.0321: Vim9: ":execute" does not work yet
Bram Moolenaar <Bram@vim.org>
parents: 19463
diff changeset
1570
3b026343f398 patch 8.2.0321: Vim9: ":execute" does not work yet
Bram Moolenaar <Bram@vim.org>
parents: 19463
diff changeset
1571 ga_init2(&ga, 1, 80);
3b026343f398 patch 8.2.0321: Vim9: ":execute" does not work yet
Bram Moolenaar <Bram@vim.org>
parents: 19463
diff changeset
1572 for (idx = 0; idx < count; ++idx)
3b026343f398 patch 8.2.0321: Vim9: ":execute" does not work yet
Bram Moolenaar <Bram@vim.org>
parents: 19463
diff changeset
1573 {
3b026343f398 patch 8.2.0321: Vim9: ":execute" does not work yet
Bram Moolenaar <Bram@vim.org>
parents: 19463
diff changeset
1574 tv = STACK_TV_BOT(idx - count);
21835
b530ead4265a patch 8.2.1467: Vim9: :echomsg doesn't like a dict argument
Bram Moolenaar <Bram@vim.org>
parents: 21833
diff changeset
1575 if (iptr->isn_type == ISN_EXECUTE)
19528
3b026343f398 patch 8.2.0321: Vim9: ":execute" does not work yet
Bram Moolenaar <Bram@vim.org>
parents: 19463
diff changeset
1576 {
21835
b530ead4265a patch 8.2.1467: Vim9: :echomsg doesn't like a dict argument
Bram Moolenaar <Bram@vim.org>
parents: 21833
diff changeset
1577 if (tv->v_type == VAR_CHANNEL
b530ead4265a patch 8.2.1467: Vim9: :echomsg doesn't like a dict argument
Bram Moolenaar <Bram@vim.org>
parents: 21833
diff changeset
1578 || tv->v_type == VAR_JOB)
b530ead4265a patch 8.2.1467: Vim9: :echomsg doesn't like a dict argument
Bram Moolenaar <Bram@vim.org>
parents: 21833
diff changeset
1579 {
b530ead4265a patch 8.2.1467: Vim9: :echomsg doesn't like a dict argument
Bram Moolenaar <Bram@vim.org>
parents: 21833
diff changeset
1580 SOURCING_LNUM = iptr->isn_lnum;
24614
07b3d21a8b4b patch 8.2.2846: Vim9: "echo Func()" does not give an error for using void
Bram Moolenaar <Bram@vim.org>
parents: 24606
diff changeset
1581 semsg(_(e_using_invalid_value_as_string_str),
07b3d21a8b4b patch 8.2.2846: Vim9: "echo Func()" does not give an error for using void
Bram Moolenaar <Bram@vim.org>
parents: 24606
diff changeset
1582 vartype_name(tv->v_type));
21835
b530ead4265a patch 8.2.1467: Vim9: :echomsg doesn't like a dict argument
Bram Moolenaar <Bram@vim.org>
parents: 21833
diff changeset
1583 break;
b530ead4265a patch 8.2.1467: Vim9: :echomsg doesn't like a dict argument
Bram Moolenaar <Bram@vim.org>
parents: 21833
diff changeset
1584 }
b530ead4265a patch 8.2.1467: Vim9: :echomsg doesn't like a dict argument
Bram Moolenaar <Bram@vim.org>
parents: 21833
diff changeset
1585 else
b530ead4265a patch 8.2.1467: Vim9: :echomsg doesn't like a dict argument
Bram Moolenaar <Bram@vim.org>
parents: 21833
diff changeset
1586 p = tv_get_string_buf(tv, buf);
19528
3b026343f398 patch 8.2.0321: Vim9: ":execute" does not work yet
Bram Moolenaar <Bram@vim.org>
parents: 19463
diff changeset
1587 }
3b026343f398 patch 8.2.0321: Vim9: ":execute" does not work yet
Bram Moolenaar <Bram@vim.org>
parents: 19463
diff changeset
1588 else
21835
b530ead4265a patch 8.2.1467: Vim9: :echomsg doesn't like a dict argument
Bram Moolenaar <Bram@vim.org>
parents: 21833
diff changeset
1589 p = tv_stringify(tv, buf);
19528
3b026343f398 patch 8.2.0321: Vim9: ":execute" does not work yet
Bram Moolenaar <Bram@vim.org>
parents: 19463
diff changeset
1590
3b026343f398 patch 8.2.0321: Vim9: ":execute" does not work yet
Bram Moolenaar <Bram@vim.org>
parents: 19463
diff changeset
1591 len = (int)STRLEN(p);
3b026343f398 patch 8.2.0321: Vim9: ":execute" does not work yet
Bram Moolenaar <Bram@vim.org>
parents: 19463
diff changeset
1592 if (ga_grow(&ga, len + 2) == FAIL)
3b026343f398 patch 8.2.0321: Vim9: ":execute" does not work yet
Bram Moolenaar <Bram@vim.org>
parents: 19463
diff changeset
1593 failed = TRUE;
3b026343f398 patch 8.2.0321: Vim9: ":execute" does not work yet
Bram Moolenaar <Bram@vim.org>
parents: 19463
diff changeset
1594 else
3b026343f398 patch 8.2.0321: Vim9: ":execute" does not work yet
Bram Moolenaar <Bram@vim.org>
parents: 19463
diff changeset
1595 {
3b026343f398 patch 8.2.0321: Vim9: ":execute" does not work yet
Bram Moolenaar <Bram@vim.org>
parents: 19463
diff changeset
1596 if (ga.ga_len > 0)
3b026343f398 patch 8.2.0321: Vim9: ":execute" does not work yet
Bram Moolenaar <Bram@vim.org>
parents: 19463
diff changeset
1597 ((char_u *)(ga.ga_data))[ga.ga_len++] = ' ';
3b026343f398 patch 8.2.0321: Vim9: ":execute" does not work yet
Bram Moolenaar <Bram@vim.org>
parents: 19463
diff changeset
1598 STRCPY((char_u *)(ga.ga_data) + ga.ga_len, p);
3b026343f398 patch 8.2.0321: Vim9: ":execute" does not work yet
Bram Moolenaar <Bram@vim.org>
parents: 19463
diff changeset
1599 ga.ga_len += len;
3b026343f398 patch 8.2.0321: Vim9: ":execute" does not work yet
Bram Moolenaar <Bram@vim.org>
parents: 19463
diff changeset
1600 }
3b026343f398 patch 8.2.0321: Vim9: ":execute" does not work yet
Bram Moolenaar <Bram@vim.org>
parents: 19463
diff changeset
1601 clear_tv(tv);
3b026343f398 patch 8.2.0321: Vim9: ":execute" does not work yet
Bram Moolenaar <Bram@vim.org>
parents: 19463
diff changeset
1602 }
24488
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
1603 ectx->ec_stack.ga_len -= count;
21835
b530ead4265a patch 8.2.1467: Vim9: :echomsg doesn't like a dict argument
Bram Moolenaar <Bram@vim.org>
parents: 21833
diff changeset
1604 if (failed)
22952
629472e2e4c5 patch 8.2.2023: Vim: memory leak when :execute fails
Bram Moolenaar <Bram@vim.org>
parents: 22948
diff changeset
1605 {
629472e2e4c5 patch 8.2.2023: Vim: memory leak when :execute fails
Bram Moolenaar <Bram@vim.org>
parents: 22948
diff changeset
1606 ga_clear(&ga);
21835
b530ead4265a patch 8.2.1467: Vim9: :echomsg doesn't like a dict argument
Bram Moolenaar <Bram@vim.org>
parents: 21833
diff changeset
1607 goto on_error;
22952
629472e2e4c5 patch 8.2.2023: Vim: memory leak when :execute fails
Bram Moolenaar <Bram@vim.org>
parents: 22948
diff changeset
1608 }
21835
b530ead4265a patch 8.2.1467: Vim9: :echomsg doesn't like a dict argument
Bram Moolenaar <Bram@vim.org>
parents: 21833
diff changeset
1609
b530ead4265a patch 8.2.1467: Vim9: :echomsg doesn't like a dict argument
Bram Moolenaar <Bram@vim.org>
parents: 21833
diff changeset
1610 if (ga.ga_data != NULL)
20142
fe8d0a4344df patch 8.2.0626: Vim9: wrong syntax of function in Vim9 script
Bram Moolenaar <Bram@vim.org>
parents: 20140
diff changeset
1611 {
fe8d0a4344df patch 8.2.0626: Vim9: wrong syntax of function in Vim9 script
Bram Moolenaar <Bram@vim.org>
parents: 20140
diff changeset
1612 if (iptr->isn_type == ISN_EXECUTE)
21933
5edd776d886d patch 8.2.1516: Vim9: error for :exe has wrong line number
Bram Moolenaar <Bram@vim.org>
parents: 21863
diff changeset
1613 {
5edd776d886d patch 8.2.1516: Vim9: error for :exe has wrong line number
Bram Moolenaar <Bram@vim.org>
parents: 21863
diff changeset
1614 SOURCING_LNUM = iptr->isn_lnum;
20142
fe8d0a4344df patch 8.2.0626: Vim9: wrong syntax of function in Vim9 script
Bram Moolenaar <Bram@vim.org>
parents: 20140
diff changeset
1615 do_cmdline_cmd((char_u *)ga.ga_data);
22948
707b90980de5 patch 8.2.2021: Vim9: get E1099 when autocommand resets did_emsg
Bram Moolenaar <Bram@vim.org>
parents: 22908
diff changeset
1616 if (did_emsg)
22952
629472e2e4c5 patch 8.2.2023: Vim: memory leak when :execute fails
Bram Moolenaar <Bram@vim.org>
parents: 22948
diff changeset
1617 {
629472e2e4c5 patch 8.2.2023: Vim: memory leak when :execute fails
Bram Moolenaar <Bram@vim.org>
parents: 22948
diff changeset
1618 ga_clear(&ga);
22948
707b90980de5 patch 8.2.2021: Vim9: get E1099 when autocommand resets did_emsg
Bram Moolenaar <Bram@vim.org>
parents: 22908
diff changeset
1619 goto on_error;
22952
629472e2e4c5 patch 8.2.2023: Vim: memory leak when :execute fails
Bram Moolenaar <Bram@vim.org>
parents: 22948
diff changeset
1620 }
21933
5edd776d886d patch 8.2.1516: Vim9: error for :exe has wrong line number
Bram Moolenaar <Bram@vim.org>
parents: 21863
diff changeset
1621 }
20142
fe8d0a4344df patch 8.2.0626: Vim9: wrong syntax of function in Vim9 script
Bram Moolenaar <Bram@vim.org>
parents: 20140
diff changeset
1622 else
fe8d0a4344df patch 8.2.0626: Vim9: wrong syntax of function in Vim9 script
Bram Moolenaar <Bram@vim.org>
parents: 20140
diff changeset
1623 {
fe8d0a4344df patch 8.2.0626: Vim9: wrong syntax of function in Vim9 script
Bram Moolenaar <Bram@vim.org>
parents: 20140
diff changeset
1624 msg_sb_eol();
fe8d0a4344df patch 8.2.0626: Vim9: wrong syntax of function in Vim9 script
Bram Moolenaar <Bram@vim.org>
parents: 20140
diff changeset
1625 if (iptr->isn_type == ISN_ECHOMSG)
fe8d0a4344df patch 8.2.0626: Vim9: wrong syntax of function in Vim9 script
Bram Moolenaar <Bram@vim.org>
parents: 20140
diff changeset
1626 {
fe8d0a4344df patch 8.2.0626: Vim9: wrong syntax of function in Vim9 script
Bram Moolenaar <Bram@vim.org>
parents: 20140
diff changeset
1627 msg_attr(ga.ga_data, echo_attr);
fe8d0a4344df patch 8.2.0626: Vim9: wrong syntax of function in Vim9 script
Bram Moolenaar <Bram@vim.org>
parents: 20140
diff changeset
1628 out_flush();
fe8d0a4344df patch 8.2.0626: Vim9: wrong syntax of function in Vim9 script
Bram Moolenaar <Bram@vim.org>
parents: 20140
diff changeset
1629 }
fe8d0a4344df patch 8.2.0626: Vim9: wrong syntax of function in Vim9 script
Bram Moolenaar <Bram@vim.org>
parents: 20140
diff changeset
1630 else
fe8d0a4344df patch 8.2.0626: Vim9: wrong syntax of function in Vim9 script
Bram Moolenaar <Bram@vim.org>
parents: 20140
diff changeset
1631 {
fe8d0a4344df patch 8.2.0626: Vim9: wrong syntax of function in Vim9 script
Bram Moolenaar <Bram@vim.org>
parents: 20140
diff changeset
1632 SOURCING_LNUM = iptr->isn_lnum;
fe8d0a4344df patch 8.2.0626: Vim9: wrong syntax of function in Vim9 script
Bram Moolenaar <Bram@vim.org>
parents: 20140
diff changeset
1633 emsg(ga.ga_data);
fe8d0a4344df patch 8.2.0626: Vim9: wrong syntax of function in Vim9 script
Bram Moolenaar <Bram@vim.org>
parents: 20140
diff changeset
1634 }
fe8d0a4344df patch 8.2.0626: Vim9: wrong syntax of function in Vim9 script
Bram Moolenaar <Bram@vim.org>
parents: 20140
diff changeset
1635 }
fe8d0a4344df patch 8.2.0626: Vim9: wrong syntax of function in Vim9 script
Bram Moolenaar <Bram@vim.org>
parents: 20140
diff changeset
1636 }
19528
3b026343f398 patch 8.2.0321: Vim9: ":execute" does not work yet
Bram Moolenaar <Bram@vim.org>
parents: 19463
diff changeset
1637 ga_clear(&ga);
3b026343f398 patch 8.2.0321: Vim9: ":execute" does not work yet
Bram Moolenaar <Bram@vim.org>
parents: 19463
diff changeset
1638 }
3b026343f398 patch 8.2.0321: Vim9: ":execute" does not work yet
Bram Moolenaar <Bram@vim.org>
parents: 19463
diff changeset
1639 break;
3b026343f398 patch 8.2.0321: Vim9: ":execute" does not work yet
Bram Moolenaar <Bram@vim.org>
parents: 19463
diff changeset
1640
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1641 // load local variable or argument
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1642 case ISN_LOAD:
24488
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
1643 if (GA_GROW(&ectx->ec_stack, 1) == FAIL)
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
1644 return FAIL;
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1645 copy_tv(STACK_TV_VAR(iptr->isn_arg.number), STACK_TV_BOT(0));
24488
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
1646 ++ectx->ec_stack.ga_len;
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1647 break;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1648
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1649 // load v: variable
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1650 case ISN_LOADV:
24488
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
1651 if (GA_GROW(&ectx->ec_stack, 1) == FAIL)
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
1652 return FAIL;
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1653 copy_tv(get_vim_var_tv(iptr->isn_arg.number), STACK_TV_BOT(0));
24488
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
1654 ++ectx->ec_stack.ga_len;
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1655 break;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1656
19283
9dc843109c97 patch 8.2.0200: Vim9 script commands not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19281
diff changeset
1657 // load s: variable in Vim9 script
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1658 case ISN_LOADSCRIPT:
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1659 {
23330
e8eb4fd44902 patch 8.2.2208: Vim9: after reloading a script variable index may be invalid
Bram Moolenaar <Bram@vim.org>
parents: 23295
diff changeset
1660 scriptref_T *sref = iptr->isn_arg.script.scriptref;
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1661 svar_T *sv;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1662
24488
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
1663 sv = get_script_svar(sref, ectx);
23362
f181fe2150ab patch 8.2.2224: Vim9: crash if script reloaded with different variable type
Bram Moolenaar <Bram@vim.org>
parents: 23350
diff changeset
1664 if (sv == NULL)
24488
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
1665 return FAIL;
23227
ccbbbbed371f patch 8.2.2159: Vim9: when declaring a list it is not allocated yet
Bram Moolenaar <Bram@vim.org>
parents: 23177
diff changeset
1666 allocate_if_null(sv->sv_tv);
24488
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
1667 if (GA_GROW(&ectx->ec_stack, 1) == FAIL)
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
1668 return FAIL;
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1669 copy_tv(sv->sv_tv, STACK_TV_BOT(0));
24488
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
1670 ++ectx->ec_stack.ga_len;
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1671 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1672 break;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1673
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1674 // load s: variable in old script
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1675 case ISN_LOADS:
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1676 {
19283
9dc843109c97 patch 8.2.0200: Vim9 script commands not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19281
diff changeset
1677 hashtab_T *ht = &SCRIPT_VARS(
9dc843109c97 patch 8.2.0200: Vim9 script commands not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19281
diff changeset
1678 iptr->isn_arg.loadstore.ls_sid);
9dc843109c97 patch 8.2.0200: Vim9 script commands not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19281
diff changeset
1679 char_u *name = iptr->isn_arg.loadstore.ls_name;
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1680 dictitem_T *di = find_var_in_ht(ht, 0, name, TRUE);
19455
655631882288 patch 8.2.0285: unused error message; cannot create s:var
Bram Moolenaar <Bram@vim.org>
parents: 19449
diff changeset
1681
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1682 if (di == NULL)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1683 {
21793
0706bd071fa3 patch 8.2.1446: Vim9: line number in error message is not correct
Bram Moolenaar <Bram@vim.org>
parents: 21789
diff changeset
1684 SOURCING_LNUM = iptr->isn_lnum;
21821
0deb6f96a5a3 patch 8.2.1460: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents: 21815
diff changeset
1685 semsg(_(e_undefined_variable_str), name);
21365
fca850f4d603 patch 8.2.1233: Vim9: various errors not caught by try/catch
Bram Moolenaar <Bram@vim.org>
parents: 21359
diff changeset
1686 goto on_error;
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1687 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1688 else
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1689 {
24488
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
1690 if (GA_GROW(&ectx->ec_stack, 1) == FAIL)
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
1691 return FAIL;
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1692 copy_tv(&di->di_tv, STACK_TV_BOT(0));
24488
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
1693 ++ectx->ec_stack.ga_len;
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1694 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1695 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1696 break;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1697
20089
7fc5d62fe2a5 patch 8.2.0600: Vim9: cannot read or write w:, t: and b: variables
Bram Moolenaar <Bram@vim.org>
parents: 20079
diff changeset
1698 // load g:/b:/w:/t: variable
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1699 case ISN_LOADG:
20089
7fc5d62fe2a5 patch 8.2.0600: Vim9: cannot read or write w:, t: and b: variables
Bram Moolenaar <Bram@vim.org>
parents: 20079
diff changeset
1700 case ISN_LOADB:
7fc5d62fe2a5 patch 8.2.0600: Vim9: cannot read or write w:, t: and b: variables
Bram Moolenaar <Bram@vim.org>
parents: 20079
diff changeset
1701 case ISN_LOADW:
7fc5d62fe2a5 patch 8.2.0600: Vim9: cannot read or write w:, t: and b: variables
Bram Moolenaar <Bram@vim.org>
parents: 20079
diff changeset
1702 case ISN_LOADT:
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1703 {
20089
7fc5d62fe2a5 patch 8.2.0600: Vim9: cannot read or write w:, t: and b: variables
Bram Moolenaar <Bram@vim.org>
parents: 20079
diff changeset
1704 dictitem_T *di = NULL;
7fc5d62fe2a5 patch 8.2.0600: Vim9: cannot read or write w:, t: and b: variables
Bram Moolenaar <Bram@vim.org>
parents: 20079
diff changeset
1705 hashtab_T *ht = NULL;
7fc5d62fe2a5 patch 8.2.0600: Vim9: cannot read or write w:, t: and b: variables
Bram Moolenaar <Bram@vim.org>
parents: 20079
diff changeset
1706 char namespace;
21399
5cb6e676defd patch 8.2.1250: Vim9: cannot use the g:, b:, t: and w: namespaces
Bram Moolenaar <Bram@vim.org>
parents: 21393
diff changeset
1707
20089
7fc5d62fe2a5 patch 8.2.0600: Vim9: cannot read or write w:, t: and b: variables
Bram Moolenaar <Bram@vim.org>
parents: 20079
diff changeset
1708 switch (iptr->isn_type)
7fc5d62fe2a5 patch 8.2.0600: Vim9: cannot read or write w:, t: and b: variables
Bram Moolenaar <Bram@vim.org>
parents: 20079
diff changeset
1709 {
7fc5d62fe2a5 patch 8.2.0600: Vim9: cannot read or write w:, t: and b: variables
Bram Moolenaar <Bram@vim.org>
parents: 20079
diff changeset
1710 case ISN_LOADG:
7fc5d62fe2a5 patch 8.2.0600: Vim9: cannot read or write w:, t: and b: variables
Bram Moolenaar <Bram@vim.org>
parents: 20079
diff changeset
1711 ht = get_globvar_ht();
7fc5d62fe2a5 patch 8.2.0600: Vim9: cannot read or write w:, t: and b: variables
Bram Moolenaar <Bram@vim.org>
parents: 20079
diff changeset
1712 namespace = 'g';
7fc5d62fe2a5 patch 8.2.0600: Vim9: cannot read or write w:, t: and b: variables
Bram Moolenaar <Bram@vim.org>
parents: 20079
diff changeset
1713 break;
7fc5d62fe2a5 patch 8.2.0600: Vim9: cannot read or write w:, t: and b: variables
Bram Moolenaar <Bram@vim.org>
parents: 20079
diff changeset
1714 case ISN_LOADB:
7fc5d62fe2a5 patch 8.2.0600: Vim9: cannot read or write w:, t: and b: variables
Bram Moolenaar <Bram@vim.org>
parents: 20079
diff changeset
1715 ht = &curbuf->b_vars->dv_hashtab;
7fc5d62fe2a5 patch 8.2.0600: Vim9: cannot read or write w:, t: and b: variables
Bram Moolenaar <Bram@vim.org>
parents: 20079
diff changeset
1716 namespace = 'b';
7fc5d62fe2a5 patch 8.2.0600: Vim9: cannot read or write w:, t: and b: variables
Bram Moolenaar <Bram@vim.org>
parents: 20079
diff changeset
1717 break;
7fc5d62fe2a5 patch 8.2.0600: Vim9: cannot read or write w:, t: and b: variables
Bram Moolenaar <Bram@vim.org>
parents: 20079
diff changeset
1718 case ISN_LOADW:
7fc5d62fe2a5 patch 8.2.0600: Vim9: cannot read or write w:, t: and b: variables
Bram Moolenaar <Bram@vim.org>
parents: 20079
diff changeset
1719 ht = &curwin->w_vars->dv_hashtab;
7fc5d62fe2a5 patch 8.2.0600: Vim9: cannot read or write w:, t: and b: variables
Bram Moolenaar <Bram@vim.org>
parents: 20079
diff changeset
1720 namespace = 'w';
7fc5d62fe2a5 patch 8.2.0600: Vim9: cannot read or write w:, t: and b: variables
Bram Moolenaar <Bram@vim.org>
parents: 20079
diff changeset
1721 break;
7fc5d62fe2a5 patch 8.2.0600: Vim9: cannot read or write w:, t: and b: variables
Bram Moolenaar <Bram@vim.org>
parents: 20079
diff changeset
1722 case ISN_LOADT:
7fc5d62fe2a5 patch 8.2.0600: Vim9: cannot read or write w:, t: and b: variables
Bram Moolenaar <Bram@vim.org>
parents: 20079
diff changeset
1723 ht = &curtab->tp_vars->dv_hashtab;
7fc5d62fe2a5 patch 8.2.0600: Vim9: cannot read or write w:, t: and b: variables
Bram Moolenaar <Bram@vim.org>
parents: 20079
diff changeset
1724 namespace = 't';
7fc5d62fe2a5 patch 8.2.0600: Vim9: cannot read or write w:, t: and b: variables
Bram Moolenaar <Bram@vim.org>
parents: 20079
diff changeset
1725 break;
7fc5d62fe2a5 patch 8.2.0600: Vim9: cannot read or write w:, t: and b: variables
Bram Moolenaar <Bram@vim.org>
parents: 20079
diff changeset
1726 default: // Cannot reach here
24488
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
1727 return FAIL;
20089
7fc5d62fe2a5 patch 8.2.0600: Vim9: cannot read or write w:, t: and b: variables
Bram Moolenaar <Bram@vim.org>
parents: 20079
diff changeset
1728 }
7fc5d62fe2a5 patch 8.2.0600: Vim9: cannot read or write w:, t: and b: variables
Bram Moolenaar <Bram@vim.org>
parents: 20079
diff changeset
1729 di = find_var_in_ht(ht, 0, iptr->isn_arg.string, TRUE);
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1730
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1731 if (di == NULL)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1732 {
21793
0706bd071fa3 patch 8.2.1446: Vim9: line number in error message is not correct
Bram Moolenaar <Bram@vim.org>
parents: 21789
diff changeset
1733 SOURCING_LNUM = iptr->isn_lnum;
21821
0deb6f96a5a3 patch 8.2.1460: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents: 21815
diff changeset
1734 semsg(_(e_undefined_variable_char_str),
20089
7fc5d62fe2a5 patch 8.2.0600: Vim9: cannot read or write w:, t: and b: variables
Bram Moolenaar <Bram@vim.org>
parents: 20079
diff changeset
1735 namespace, iptr->isn_arg.string);
21365
fca850f4d603 patch 8.2.1233: Vim9: various errors not caught by try/catch
Bram Moolenaar <Bram@vim.org>
parents: 21359
diff changeset
1736 goto on_error;
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1737 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1738 else
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1739 {
24488
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
1740 if (GA_GROW(&ectx->ec_stack, 1) == FAIL)
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
1741 return FAIL;
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1742 copy_tv(&di->di_tv, STACK_TV_BOT(0));
24488
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
1743 ++ectx->ec_stack.ga_len;
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1744 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1745 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1746 break;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1747
23233
657216220293 patch 8.2.2162: Vim9: Cannot load or store autoload variables
Bram Moolenaar <Bram@vim.org>
parents: 23229
diff changeset
1748 // load autoload variable
657216220293 patch 8.2.2162: Vim9: Cannot load or store autoload variables
Bram Moolenaar <Bram@vim.org>
parents: 23229
diff changeset
1749 case ISN_LOADAUTO:
657216220293 patch 8.2.2162: Vim9: Cannot load or store autoload variables
Bram Moolenaar <Bram@vim.org>
parents: 23229
diff changeset
1750 {
657216220293 patch 8.2.2162: Vim9: Cannot load or store autoload variables
Bram Moolenaar <Bram@vim.org>
parents: 23229
diff changeset
1751 char_u *name = iptr->isn_arg.string;
657216220293 patch 8.2.2162: Vim9: Cannot load or store autoload variables
Bram Moolenaar <Bram@vim.org>
parents: 23229
diff changeset
1752
24488
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
1753 if (GA_GROW(&ectx->ec_stack, 1) == FAIL)
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
1754 return FAIL;
23233
657216220293 patch 8.2.2162: Vim9: Cannot load or store autoload variables
Bram Moolenaar <Bram@vim.org>
parents: 23229
diff changeset
1755 SOURCING_LNUM = iptr->isn_lnum;
23454
5e6a5ccf5dcb patch 8.2.2270: warning for size_t to int conversion
Bram Moolenaar <Bram@vim.org>
parents: 23450
diff changeset
1756 if (eval_variable(name, (int)STRLEN(name),
24112
0346a59ed5bf patch 8.2.2597: Vim9: "import * as" does not work at script level
Bram Moolenaar <Bram@vim.org>
parents: 24077
diff changeset
1757 STACK_TV_BOT(0), NULL, EVAL_VAR_VERBOSE) == FAIL)
23233
657216220293 patch 8.2.2162: Vim9: Cannot load or store autoload variables
Bram Moolenaar <Bram@vim.org>
parents: 23229
diff changeset
1758 goto on_error;
24488
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
1759 ++ectx->ec_stack.ga_len;
23233
657216220293 patch 8.2.2162: Vim9: Cannot load or store autoload variables
Bram Moolenaar <Bram@vim.org>
parents: 23229
diff changeset
1760 }
657216220293 patch 8.2.2162: Vim9: Cannot load or store autoload variables
Bram Moolenaar <Bram@vim.org>
parents: 23229
diff changeset
1761 break;
657216220293 patch 8.2.2162: Vim9: Cannot load or store autoload variables
Bram Moolenaar <Bram@vim.org>
parents: 23229
diff changeset
1762
21399
5cb6e676defd patch 8.2.1250: Vim9: cannot use the g:, b:, t: and w: namespaces
Bram Moolenaar <Bram@vim.org>
parents: 21393
diff changeset
1763 // load g:/b:/w:/t: namespace
5cb6e676defd patch 8.2.1250: Vim9: cannot use the g:, b:, t: and w: namespaces
Bram Moolenaar <Bram@vim.org>
parents: 21393
diff changeset
1764 case ISN_LOADGDICT:
5cb6e676defd patch 8.2.1250: Vim9: cannot use the g:, b:, t: and w: namespaces
Bram Moolenaar <Bram@vim.org>
parents: 21393
diff changeset
1765 case ISN_LOADBDICT:
5cb6e676defd patch 8.2.1250: Vim9: cannot use the g:, b:, t: and w: namespaces
Bram Moolenaar <Bram@vim.org>
parents: 21393
diff changeset
1766 case ISN_LOADWDICT:
5cb6e676defd patch 8.2.1250: Vim9: cannot use the g:, b:, t: and w: namespaces
Bram Moolenaar <Bram@vim.org>
parents: 21393
diff changeset
1767 case ISN_LOADTDICT:
5cb6e676defd patch 8.2.1250: Vim9: cannot use the g:, b:, t: and w: namespaces
Bram Moolenaar <Bram@vim.org>
parents: 21393
diff changeset
1768 {
5cb6e676defd patch 8.2.1250: Vim9: cannot use the g:, b:, t: and w: namespaces
Bram Moolenaar <Bram@vim.org>
parents: 21393
diff changeset
1769 dict_T *d = NULL;
5cb6e676defd patch 8.2.1250: Vim9: cannot use the g:, b:, t: and w: namespaces
Bram Moolenaar <Bram@vim.org>
parents: 21393
diff changeset
1770
5cb6e676defd patch 8.2.1250: Vim9: cannot use the g:, b:, t: and w: namespaces
Bram Moolenaar <Bram@vim.org>
parents: 21393
diff changeset
1771 switch (iptr->isn_type)
5cb6e676defd patch 8.2.1250: Vim9: cannot use the g:, b:, t: and w: namespaces
Bram Moolenaar <Bram@vim.org>
parents: 21393
diff changeset
1772 {
21401
aa7675a4a0cd patch 8.2.1251: Vim9: warning for pointer usage, test failure undetected
Bram Moolenaar <Bram@vim.org>
parents: 21399
diff changeset
1773 case ISN_LOADGDICT: d = get_globvar_dict(); break;
aa7675a4a0cd patch 8.2.1251: Vim9: warning for pointer usage, test failure undetected
Bram Moolenaar <Bram@vim.org>
parents: 21399
diff changeset
1774 case ISN_LOADBDICT: d = curbuf->b_vars; break;
aa7675a4a0cd patch 8.2.1251: Vim9: warning for pointer usage, test failure undetected
Bram Moolenaar <Bram@vim.org>
parents: 21399
diff changeset
1775 case ISN_LOADWDICT: d = curwin->w_vars; break;
aa7675a4a0cd patch 8.2.1251: Vim9: warning for pointer usage, test failure undetected
Bram Moolenaar <Bram@vim.org>
parents: 21399
diff changeset
1776 case ISN_LOADTDICT: d = curtab->tp_vars; break;
21399
5cb6e676defd patch 8.2.1250: Vim9: cannot use the g:, b:, t: and w: namespaces
Bram Moolenaar <Bram@vim.org>
parents: 21393
diff changeset
1777 default: // Cannot reach here
24488
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
1778 return FAIL;
21399
5cb6e676defd patch 8.2.1250: Vim9: cannot use the g:, b:, t: and w: namespaces
Bram Moolenaar <Bram@vim.org>
parents: 21393
diff changeset
1779 }
24488
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
1780 if (GA_GROW(&ectx->ec_stack, 1) == FAIL)
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
1781 return FAIL;
21399
5cb6e676defd patch 8.2.1250: Vim9: cannot use the g:, b:, t: and w: namespaces
Bram Moolenaar <Bram@vim.org>
parents: 21393
diff changeset
1782 tv = STACK_TV_BOT(0);
5cb6e676defd patch 8.2.1250: Vim9: cannot use the g:, b:, t: and w: namespaces
Bram Moolenaar <Bram@vim.org>
parents: 21393
diff changeset
1783 tv->v_type = VAR_DICT;
5cb6e676defd patch 8.2.1250: Vim9: cannot use the g:, b:, t: and w: namespaces
Bram Moolenaar <Bram@vim.org>
parents: 21393
diff changeset
1784 tv->v_lock = 0;
5cb6e676defd patch 8.2.1250: Vim9: cannot use the g:, b:, t: and w: namespaces
Bram Moolenaar <Bram@vim.org>
parents: 21393
diff changeset
1785 tv->vval.v_dict = d;
24014
e45b2e28e45e patch 8.2.2549: crash after using "g:" in a for loop
Bram Moolenaar <Bram@vim.org>
parents: 24002
diff changeset
1786 ++d->dv_refcount;
24488
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
1787 ++ectx->ec_stack.ga_len;
21399
5cb6e676defd patch 8.2.1250: Vim9: cannot use the g:, b:, t: and w: namespaces
Bram Moolenaar <Bram@vim.org>
parents: 21393
diff changeset
1788 }
5cb6e676defd patch 8.2.1250: Vim9: cannot use the g:, b:, t: and w: namespaces
Bram Moolenaar <Bram@vim.org>
parents: 21393
diff changeset
1789 break;
5cb6e676defd patch 8.2.1250: Vim9: cannot use the g:, b:, t: and w: namespaces
Bram Moolenaar <Bram@vim.org>
parents: 21393
diff changeset
1790
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1791 // load &option
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1792 case ISN_LOADOPT:
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1793 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1794 typval_T optval;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1795 char_u *name = iptr->isn_arg.string;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1796
19872
8a7bede7b138 patch 8.2.0492: Vim9: some error messages not tested
Bram Moolenaar <Bram@vim.org>
parents: 19862
diff changeset
1797 // This is not expected to fail, name is checked during
8a7bede7b138 patch 8.2.0492: Vim9: some error messages not tested
Bram Moolenaar <Bram@vim.org>
parents: 19862
diff changeset
1798 // compilation: don't set SOURCING_LNUM.
24488
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
1799 if (GA_GROW(&ectx->ec_stack, 1) == FAIL)
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
1800 return FAIL;
21120
4d844a65183d patch 8.2.1111: inconsistent naming of get_list_tv() and eval_dict()
Bram Moolenaar <Bram@vim.org>
parents: 20943
diff changeset
1801 if (eval_option(&name, &optval, TRUE) == FAIL)
24488
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
1802 return FAIL;
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1803 *STACK_TV_BOT(0) = optval;
24488
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
1804 ++ectx->ec_stack.ga_len;
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1805 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1806 break;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1807
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1808 // load $ENV
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1809 case ISN_LOADENV:
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1810 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1811 typval_T optval;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1812 char_u *name = iptr->isn_arg.string;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1813
24488
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
1814 if (GA_GROW(&ectx->ec_stack, 1) == FAIL)
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
1815 return FAIL;
19455
655631882288 patch 8.2.0285: unused error message; cannot create s:var
Bram Moolenaar <Bram@vim.org>
parents: 19449
diff changeset
1816 // name is always valid, checked when compiling
21120
4d844a65183d patch 8.2.1111: inconsistent naming of get_list_tv() and eval_dict()
Bram Moolenaar <Bram@vim.org>
parents: 20943
diff changeset
1817 (void)eval_env_var(&name, &optval, TRUE);
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1818 *STACK_TV_BOT(0) = optval;
24488
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
1819 ++ectx->ec_stack.ga_len;
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1820 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1821 break;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1822
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1823 // load @register
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1824 case ISN_LOADREG:
24488
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
1825 if (GA_GROW(&ectx->ec_stack, 1) == FAIL)
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
1826 return FAIL;
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1827 tv = STACK_TV_BOT(0);
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1828 tv->v_type = VAR_STRING;
21399
5cb6e676defd patch 8.2.1250: Vim9: cannot use the g:, b:, t: and w: namespaces
Bram Moolenaar <Bram@vim.org>
parents: 21393
diff changeset
1829 tv->v_lock = 0;
22612
b08f435d5b86 patch 8.2.1854: Vim9: crash when throwing exception for NULL string
Bram Moolenaar <Bram@vim.org>
parents: 22596
diff changeset
1830 // This may result in NULL, which should be equivalent to an
b08f435d5b86 patch 8.2.1854: Vim9: crash when throwing exception for NULL string
Bram Moolenaar <Bram@vim.org>
parents: 22596
diff changeset
1831 // empty string.
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1832 tv->vval.v_string = get_reg_contents(
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1833 iptr->isn_arg.number, GREG_EXPR_SRC);
24488
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
1834 ++ectx->ec_stack.ga_len;
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1835 break;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1836
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1837 // store local variable
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1838 case ISN_STORE:
24488
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
1839 --ectx->ec_stack.ga_len;
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1840 tv = STACK_TV_VAR(iptr->isn_arg.number);
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1841 clear_tv(tv);
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1842 *tv = *STACK_TV_BOT(0);
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1843 break;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1844
19283
9dc843109c97 patch 8.2.0200: Vim9 script commands not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19281
diff changeset
1845 // store s: variable in old script
9dc843109c97 patch 8.2.0200: Vim9 script commands not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19281
diff changeset
1846 case ISN_STORES:
9dc843109c97 patch 8.2.0200: Vim9 script commands not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19281
diff changeset
1847 {
9dc843109c97 patch 8.2.0200: Vim9 script commands not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19281
diff changeset
1848 hashtab_T *ht = &SCRIPT_VARS(
9dc843109c97 patch 8.2.0200: Vim9 script commands not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19281
diff changeset
1849 iptr->isn_arg.loadstore.ls_sid);
9dc843109c97 patch 8.2.0200: Vim9 script commands not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19281
diff changeset
1850 char_u *name = iptr->isn_arg.loadstore.ls_name;
19455
655631882288 patch 8.2.0285: unused error message; cannot create s:var
Bram Moolenaar <Bram@vim.org>
parents: 19449
diff changeset
1851 dictitem_T *di = find_var_in_ht(ht, 0, name + 2, TRUE);
19283
9dc843109c97 patch 8.2.0200: Vim9 script commands not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19281
diff changeset
1852
24488
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
1853 --ectx->ec_stack.ga_len;
19283
9dc843109c97 patch 8.2.0200: Vim9 script commands not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19281
diff changeset
1854 if (di == NULL)
19912
d4fa9db88d16 patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents: 19874
diff changeset
1855 store_var(name, STACK_TV_BOT(0));
19455
655631882288 patch 8.2.0285: unused error message; cannot create s:var
Bram Moolenaar <Bram@vim.org>
parents: 19449
diff changeset
1856 else
19283
9dc843109c97 patch 8.2.0200: Vim9 script commands not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19281
diff changeset
1857 {
24305
c88d0b5c5a42 patch 8.2.2693: Vim9: locked script variable can be changed
Bram Moolenaar <Bram@vim.org>
parents: 24303
diff changeset
1858 SOURCING_LNUM = iptr->isn_lnum;
c88d0b5c5a42 patch 8.2.2693: Vim9: locked script variable can be changed
Bram Moolenaar <Bram@vim.org>
parents: 24303
diff changeset
1859 if (var_check_permission(di, name) == FAIL)
24325
52a0e187264b patch 8.2.2703: Vim9: memory leak when failing on locked variable
Bram Moolenaar <Bram@vim.org>
parents: 24305
diff changeset
1860 {
52a0e187264b patch 8.2.2703: Vim9: memory leak when failing on locked variable
Bram Moolenaar <Bram@vim.org>
parents: 24305
diff changeset
1861 clear_tv(STACK_TV_BOT(0));
24305
c88d0b5c5a42 patch 8.2.2693: Vim9: locked script variable can be changed
Bram Moolenaar <Bram@vim.org>
parents: 24303
diff changeset
1862 goto on_error;
24325
52a0e187264b patch 8.2.2703: Vim9: memory leak when failing on locked variable
Bram Moolenaar <Bram@vim.org>
parents: 24305
diff changeset
1863 }
19455
655631882288 patch 8.2.0285: unused error message; cannot create s:var
Bram Moolenaar <Bram@vim.org>
parents: 19449
diff changeset
1864 clear_tv(&di->di_tv);
655631882288 patch 8.2.0285: unused error message; cannot create s:var
Bram Moolenaar <Bram@vim.org>
parents: 19449
diff changeset
1865 di->di_tv = *STACK_TV_BOT(0);
19283
9dc843109c97 patch 8.2.0200: Vim9 script commands not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19281
diff changeset
1866 }
9dc843109c97 patch 8.2.0200: Vim9 script commands not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19281
diff changeset
1867 }
9dc843109c97 patch 8.2.0200: Vim9 script commands not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19281
diff changeset
1868 break;
9dc843109c97 patch 8.2.0200: Vim9 script commands not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19281
diff changeset
1869
9dc843109c97 patch 8.2.0200: Vim9 script commands not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19281
diff changeset
1870 // store script-local variable in Vim9 script
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1871 case ISN_STORESCRIPT:
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1872 {
23362
f181fe2150ab patch 8.2.2224: Vim9: crash if script reloaded with different variable type
Bram Moolenaar <Bram@vim.org>
parents: 23350
diff changeset
1873 scriptref_T *sref = iptr->isn_arg.script.scriptref;
f181fe2150ab patch 8.2.2224: Vim9: crash if script reloaded with different variable type
Bram Moolenaar <Bram@vim.org>
parents: 23350
diff changeset
1874 svar_T *sv;
f181fe2150ab patch 8.2.2224: Vim9: crash if script reloaded with different variable type
Bram Moolenaar <Bram@vim.org>
parents: 23350
diff changeset
1875
24488
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
1876 sv = get_script_svar(sref, ectx);
23362
f181fe2150ab patch 8.2.2224: Vim9: crash if script reloaded with different variable type
Bram Moolenaar <Bram@vim.org>
parents: 23350
diff changeset
1877 if (sv == NULL)
24488
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
1878 return FAIL;
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
1879 --ectx->ec_stack.ga_len;
24303
17b49af76766 patch 8.2.2692: Vim9: locked script variable can be changed
Bram Moolenaar <Bram@vim.org>
parents: 24293
diff changeset
1880
17b49af76766 patch 8.2.2692: Vim9: locked script variable can be changed
Bram Moolenaar <Bram@vim.org>
parents: 24293
diff changeset
1881 // "const" and "final" are checked at compile time, locking
17b49af76766 patch 8.2.2692: Vim9: locked script variable can be changed
Bram Moolenaar <Bram@vim.org>
parents: 24293
diff changeset
1882 // the value needs to be checked here.
17b49af76766 patch 8.2.2692: Vim9: locked script variable can be changed
Bram Moolenaar <Bram@vim.org>
parents: 24293
diff changeset
1883 SOURCING_LNUM = iptr->isn_lnum;
17b49af76766 patch 8.2.2692: Vim9: locked script variable can be changed
Bram Moolenaar <Bram@vim.org>
parents: 24293
diff changeset
1884 if (value_check_lock(sv->sv_tv->v_lock, sv->sv_name, FALSE))
24325
52a0e187264b patch 8.2.2703: Vim9: memory leak when failing on locked variable
Bram Moolenaar <Bram@vim.org>
parents: 24305
diff changeset
1885 {
52a0e187264b patch 8.2.2703: Vim9: memory leak when failing on locked variable
Bram Moolenaar <Bram@vim.org>
parents: 24305
diff changeset
1886 clear_tv(STACK_TV_BOT(0));
24303
17b49af76766 patch 8.2.2692: Vim9: locked script variable can be changed
Bram Moolenaar <Bram@vim.org>
parents: 24293
diff changeset
1887 goto on_error;
24325
52a0e187264b patch 8.2.2703: Vim9: memory leak when failing on locked variable
Bram Moolenaar <Bram@vim.org>
parents: 24305
diff changeset
1888 }
24303
17b49af76766 patch 8.2.2692: Vim9: locked script variable can be changed
Bram Moolenaar <Bram@vim.org>
parents: 24293
diff changeset
1889
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1890 clear_tv(sv->sv_tv);
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1891 *sv->sv_tv = *STACK_TV_BOT(0);
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1892 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1893 break;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1894
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1895 // store option
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1896 case ISN_STOREOPT:
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1897 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1898 long n = 0;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1899 char_u *s = NULL;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1900 char *msg;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1901
24488
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
1902 --ectx->ec_stack.ga_len;
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1903 tv = STACK_TV_BOT(0);
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1904 if (tv->v_type == VAR_STRING)
19219
89931701e033 patch 8.2.0168: Coverity warning for assigning NULL to an option
Bram Moolenaar <Bram@vim.org>
parents: 19217
diff changeset
1905 {
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1906 s = tv->vval.v_string;
19219
89931701e033 patch 8.2.0168: Coverity warning for assigning NULL to an option
Bram Moolenaar <Bram@vim.org>
parents: 19217
diff changeset
1907 if (s == NULL)
89931701e033 patch 8.2.0168: Coverity warning for assigning NULL to an option
Bram Moolenaar <Bram@vim.org>
parents: 19217
diff changeset
1908 s = (char_u *)"";
89931701e033 patch 8.2.0168: Coverity warning for assigning NULL to an option
Bram Moolenaar <Bram@vim.org>
parents: 19217
diff changeset
1909 }
20419
d54dfb5f12db patch 8.2.0764: Vim9: assigning to option not fully tested
Bram Moolenaar <Bram@vim.org>
parents: 20411
diff changeset
1910 else
d54dfb5f12db patch 8.2.0764: Vim9: assigning to option not fully tested
Bram Moolenaar <Bram@vim.org>
parents: 20411
diff changeset
1911 // must be VAR_NUMBER, CHECKTYPE makes sure
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1912 n = tv->vval.v_number;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1913 msg = set_option_value(iptr->isn_arg.storeopt.so_name,
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1914 n, s, iptr->isn_arg.storeopt.so_flags);
20427
0ab8f8880a33 patch 8.2.0768: Vim9: memory leak in script test
Bram Moolenaar <Bram@vim.org>
parents: 20419
diff changeset
1915 clear_tv(tv);
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1916 if (msg != NULL)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1917 {
21793
0706bd071fa3 patch 8.2.1446: Vim9: line number in error message is not correct
Bram Moolenaar <Bram@vim.org>
parents: 21789
diff changeset
1918 SOURCING_LNUM = iptr->isn_lnum;
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1919 emsg(_(msg));
21371
8e1081ede3b8 patch 8.2.1236: Vim9: a few errors not caught by try/catch
Bram Moolenaar <Bram@vim.org>
parents: 21365
diff changeset
1920 goto on_error;
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1921 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1922 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1923 break;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1924
19283
9dc843109c97 patch 8.2.0200: Vim9 script commands not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19281
diff changeset
1925 // store $ENV
9dc843109c97 patch 8.2.0200: Vim9 script commands not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19281
diff changeset
1926 case ISN_STOREENV:
24488
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
1927 --ectx->ec_stack.ga_len;
19726
ad37a198a708 patch 8.2.0419: various memory leaks in Vim9 script code
Bram Moolenaar <Bram@vim.org>
parents: 19635
diff changeset
1928 tv = STACK_TV_BOT(0);
ad37a198a708 patch 8.2.0419: various memory leaks in Vim9 script code
Bram Moolenaar <Bram@vim.org>
parents: 19635
diff changeset
1929 vim_setenv_ext(iptr->isn_arg.string, tv_get_string(tv));
ad37a198a708 patch 8.2.0419: various memory leaks in Vim9 script code
Bram Moolenaar <Bram@vim.org>
parents: 19635
diff changeset
1930 clear_tv(tv);
19283
9dc843109c97 patch 8.2.0200: Vim9 script commands not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19281
diff changeset
1931 break;
9dc843109c97 patch 8.2.0200: Vim9 script commands not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19281
diff changeset
1932
9dc843109c97 patch 8.2.0200: Vim9 script commands not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19281
diff changeset
1933 // store @r
9dc843109c97 patch 8.2.0200: Vim9 script commands not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19281
diff changeset
1934 case ISN_STOREREG:
9dc843109c97 patch 8.2.0200: Vim9 script commands not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19281
diff changeset
1935 {
9dc843109c97 patch 8.2.0200: Vim9 script commands not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19281
diff changeset
1936 int reg = iptr->isn_arg.number;
9dc843109c97 patch 8.2.0200: Vim9 script commands not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19281
diff changeset
1937
24488
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
1938 --ectx->ec_stack.ga_len;
19449
f8408ba21982 patch 8.2.0282: Vim9: setting number option not tested
Bram Moolenaar <Bram@vim.org>
parents: 19445
diff changeset
1939 tv = STACK_TV_BOT(0);
19283
9dc843109c97 patch 8.2.0200: Vim9 script commands not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19281
diff changeset
1940 write_reg_contents(reg == '@' ? '"' : reg,
19449
f8408ba21982 patch 8.2.0282: Vim9: setting number option not tested
Bram Moolenaar <Bram@vim.org>
parents: 19445
diff changeset
1941 tv_get_string(tv), -1, FALSE);
f8408ba21982 patch 8.2.0282: Vim9: setting number option not tested
Bram Moolenaar <Bram@vim.org>
parents: 19445
diff changeset
1942 clear_tv(tv);
19283
9dc843109c97 patch 8.2.0200: Vim9 script commands not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19281
diff changeset
1943 }
9dc843109c97 patch 8.2.0200: Vim9 script commands not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19281
diff changeset
1944 break;
9dc843109c97 patch 8.2.0200: Vim9 script commands not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19281
diff changeset
1945
9dc843109c97 patch 8.2.0200: Vim9 script commands not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19281
diff changeset
1946 // store v: variable
9dc843109c97 patch 8.2.0200: Vim9 script commands not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19281
diff changeset
1947 case ISN_STOREV:
24488
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
1948 --ectx->ec_stack.ga_len;
19283
9dc843109c97 patch 8.2.0200: Vim9 script commands not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19281
diff changeset
1949 if (set_vim_var_tv(iptr->isn_arg.number, STACK_TV_BOT(0))
9dc843109c97 patch 8.2.0200: Vim9 script commands not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19281
diff changeset
1950 == FAIL)
21371
8e1081ede3b8 patch 8.2.1236: Vim9: a few errors not caught by try/catch
Bram Moolenaar <Bram@vim.org>
parents: 21365
diff changeset
1951 // should not happen, type is checked when compiling
8e1081ede3b8 patch 8.2.1236: Vim9: a few errors not caught by try/catch
Bram Moolenaar <Bram@vim.org>
parents: 21365
diff changeset
1952 goto on_error;
19283
9dc843109c97 patch 8.2.0200: Vim9 script commands not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19281
diff changeset
1953 break;
9dc843109c97 patch 8.2.0200: Vim9 script commands not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19281
diff changeset
1954
20089
7fc5d62fe2a5 patch 8.2.0600: Vim9: cannot read or write w:, t: and b: variables
Bram Moolenaar <Bram@vim.org>
parents: 20079
diff changeset
1955 // store g:/b:/w:/t: variable
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1956 case ISN_STOREG:
20089
7fc5d62fe2a5 patch 8.2.0600: Vim9: cannot read or write w:, t: and b: variables
Bram Moolenaar <Bram@vim.org>
parents: 20079
diff changeset
1957 case ISN_STOREB:
7fc5d62fe2a5 patch 8.2.0600: Vim9: cannot read or write w:, t: and b: variables
Bram Moolenaar <Bram@vim.org>
parents: 20079
diff changeset
1958 case ISN_STOREW:
7fc5d62fe2a5 patch 8.2.0600: Vim9: cannot read or write w:, t: and b: variables
Bram Moolenaar <Bram@vim.org>
parents: 20079
diff changeset
1959 case ISN_STORET:
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1960 {
23295
d9ae7dd3a0f2 patch 8.2.2193: Vim9: can change constant in :def function
Bram Moolenaar <Bram@vim.org>
parents: 23285
diff changeset
1961 dictitem_T *di;
d9ae7dd3a0f2 patch 8.2.2193: Vim9: can change constant in :def function
Bram Moolenaar <Bram@vim.org>
parents: 23285
diff changeset
1962 hashtab_T *ht;
d9ae7dd3a0f2 patch 8.2.2193: Vim9: can change constant in :def function
Bram Moolenaar <Bram@vim.org>
parents: 23285
diff changeset
1963 char_u *name = iptr->isn_arg.string + 2;
d9ae7dd3a0f2 patch 8.2.2193: Vim9: can change constant in :def function
Bram Moolenaar <Bram@vim.org>
parents: 23285
diff changeset
1964
20089
7fc5d62fe2a5 patch 8.2.0600: Vim9: cannot read or write w:, t: and b: variables
Bram Moolenaar <Bram@vim.org>
parents: 20079
diff changeset
1965 switch (iptr->isn_type)
7fc5d62fe2a5 patch 8.2.0600: Vim9: cannot read or write w:, t: and b: variables
Bram Moolenaar <Bram@vim.org>
parents: 20079
diff changeset
1966 {
7fc5d62fe2a5 patch 8.2.0600: Vim9: cannot read or write w:, t: and b: variables
Bram Moolenaar <Bram@vim.org>
parents: 20079
diff changeset
1967 case ISN_STOREG:
7fc5d62fe2a5 patch 8.2.0600: Vim9: cannot read or write w:, t: and b: variables
Bram Moolenaar <Bram@vim.org>
parents: 20079
diff changeset
1968 ht = get_globvar_ht();
7fc5d62fe2a5 patch 8.2.0600: Vim9: cannot read or write w:, t: and b: variables
Bram Moolenaar <Bram@vim.org>
parents: 20079
diff changeset
1969 break;
7fc5d62fe2a5 patch 8.2.0600: Vim9: cannot read or write w:, t: and b: variables
Bram Moolenaar <Bram@vim.org>
parents: 20079
diff changeset
1970 case ISN_STOREB:
7fc5d62fe2a5 patch 8.2.0600: Vim9: cannot read or write w:, t: and b: variables
Bram Moolenaar <Bram@vim.org>
parents: 20079
diff changeset
1971 ht = &curbuf->b_vars->dv_hashtab;
7fc5d62fe2a5 patch 8.2.0600: Vim9: cannot read or write w:, t: and b: variables
Bram Moolenaar <Bram@vim.org>
parents: 20079
diff changeset
1972 break;
7fc5d62fe2a5 patch 8.2.0600: Vim9: cannot read or write w:, t: and b: variables
Bram Moolenaar <Bram@vim.org>
parents: 20079
diff changeset
1973 case ISN_STOREW:
7fc5d62fe2a5 patch 8.2.0600: Vim9: cannot read or write w:, t: and b: variables
Bram Moolenaar <Bram@vim.org>
parents: 20079
diff changeset
1974 ht = &curwin->w_vars->dv_hashtab;
7fc5d62fe2a5 patch 8.2.0600: Vim9: cannot read or write w:, t: and b: variables
Bram Moolenaar <Bram@vim.org>
parents: 20079
diff changeset
1975 break;
7fc5d62fe2a5 patch 8.2.0600: Vim9: cannot read or write w:, t: and b: variables
Bram Moolenaar <Bram@vim.org>
parents: 20079
diff changeset
1976 case ISN_STORET:
7fc5d62fe2a5 patch 8.2.0600: Vim9: cannot read or write w:, t: and b: variables
Bram Moolenaar <Bram@vim.org>
parents: 20079
diff changeset
1977 ht = &curtab->tp_vars->dv_hashtab;
7fc5d62fe2a5 patch 8.2.0600: Vim9: cannot read or write w:, t: and b: variables
Bram Moolenaar <Bram@vim.org>
parents: 20079
diff changeset
1978 break;
7fc5d62fe2a5 patch 8.2.0600: Vim9: cannot read or write w:, t: and b: variables
Bram Moolenaar <Bram@vim.org>
parents: 20079
diff changeset
1979 default: // Cannot reach here
24488
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
1980 return FAIL;
20089
7fc5d62fe2a5 patch 8.2.0600: Vim9: cannot read or write w:, t: and b: variables
Bram Moolenaar <Bram@vim.org>
parents: 20079
diff changeset
1981 }
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1982
24488
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
1983 --ectx->ec_stack.ga_len;
23295
d9ae7dd3a0f2 patch 8.2.2193: Vim9: can change constant in :def function
Bram Moolenaar <Bram@vim.org>
parents: 23285
diff changeset
1984 di = find_var_in_ht(ht, 0, name, TRUE);
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1985 if (di == NULL)
19455
655631882288 patch 8.2.0285: unused error message; cannot create s:var
Bram Moolenaar <Bram@vim.org>
parents: 19449
diff changeset
1986 store_var(iptr->isn_arg.string, STACK_TV_BOT(0));
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1987 else
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1988 {
23295
d9ae7dd3a0f2 patch 8.2.2193: Vim9: can change constant in :def function
Bram Moolenaar <Bram@vim.org>
parents: 23285
diff changeset
1989 SOURCING_LNUM = iptr->isn_lnum;
d9ae7dd3a0f2 patch 8.2.2193: Vim9: can change constant in :def function
Bram Moolenaar <Bram@vim.org>
parents: 23285
diff changeset
1990 if (var_check_permission(di, name) == FAIL)
d9ae7dd3a0f2 patch 8.2.2193: Vim9: can change constant in :def function
Bram Moolenaar <Bram@vim.org>
parents: 23285
diff changeset
1991 goto on_error;
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1992 clear_tv(&di->di_tv);
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1993 di->di_tv = *STACK_TV_BOT(0);
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1994 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1995 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1996 break;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1997
23233
657216220293 patch 8.2.2162: Vim9: Cannot load or store autoload variables
Bram Moolenaar <Bram@vim.org>
parents: 23229
diff changeset
1998 // store an autoload variable
657216220293 patch 8.2.2162: Vim9: Cannot load or store autoload variables
Bram Moolenaar <Bram@vim.org>
parents: 23229
diff changeset
1999 case ISN_STOREAUTO:
657216220293 patch 8.2.2162: Vim9: Cannot load or store autoload variables
Bram Moolenaar <Bram@vim.org>
parents: 23229
diff changeset
2000 SOURCING_LNUM = iptr->isn_lnum;
657216220293 patch 8.2.2162: Vim9: Cannot load or store autoload variables
Bram Moolenaar <Bram@vim.org>
parents: 23229
diff changeset
2001 set_var(iptr->isn_arg.string, STACK_TV_BOT(-1), TRUE);
657216220293 patch 8.2.2162: Vim9: Cannot load or store autoload variables
Bram Moolenaar <Bram@vim.org>
parents: 23229
diff changeset
2002 clear_tv(STACK_TV_BOT(-1));
24488
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
2003 --ectx->ec_stack.ga_len;
23233
657216220293 patch 8.2.2162: Vim9: Cannot load or store autoload variables
Bram Moolenaar <Bram@vim.org>
parents: 23229
diff changeset
2004 break;
657216220293 patch 8.2.2162: Vim9: Cannot load or store autoload variables
Bram Moolenaar <Bram@vim.org>
parents: 23229
diff changeset
2005
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2006 // store number in local variable
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2007 case ISN_STORENR:
19597
1098989a90ee patch 8.2.0355: Vim9: str_val is confusing, it's a number
Bram Moolenaar <Bram@vim.org>
parents: 19572
diff changeset
2008 tv = STACK_TV_VAR(iptr->isn_arg.storenr.stnr_idx);
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2009 clear_tv(tv);
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2010 tv->v_type = VAR_NUMBER;
19597
1098989a90ee patch 8.2.0355: Vim9: str_val is confusing, it's a number
Bram Moolenaar <Bram@vim.org>
parents: 19572
diff changeset
2011 tv->vval.v_number = iptr->isn_arg.storenr.stnr_val;
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2012 break;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2013
23266
00f7cd9b6033 patch 8.2.2179: Vim9: crash when indexing a dict with a number
Bram Moolenaar <Bram@vim.org>
parents: 23254
diff changeset
2014 // store value in list or dict variable
00f7cd9b6033 patch 8.2.2179: Vim9: crash when indexing a dict with a number
Bram Moolenaar <Bram@vim.org>
parents: 23254
diff changeset
2015 case ISN_STOREINDEX:
20349
e29b2ec8d4d2 patch 8.2.0730: Vim9: Assignment to dict member does not work
Bram Moolenaar <Bram@vim.org>
parents: 20341
diff changeset
2016 {
23266
00f7cd9b6033 patch 8.2.2179: Vim9: crash when indexing a dict with a number
Bram Moolenaar <Bram@vim.org>
parents: 23254
diff changeset
2017 vartype_T dest_type = iptr->isn_arg.vartype;
20349
e29b2ec8d4d2 patch 8.2.0730: Vim9: Assignment to dict member does not work
Bram Moolenaar <Bram@vim.org>
parents: 20341
diff changeset
2018 typval_T *tv_idx = STACK_TV_BOT(-2);
23266
00f7cd9b6033 patch 8.2.2179: Vim9: crash when indexing a dict with a number
Bram Moolenaar <Bram@vim.org>
parents: 23254
diff changeset
2019 typval_T *tv_dest = STACK_TV_BOT(-1);
00f7cd9b6033 patch 8.2.2179: Vim9: crash when indexing a dict with a number
Bram Moolenaar <Bram@vim.org>
parents: 23254
diff changeset
2020 int status = OK;
00f7cd9b6033 patch 8.2.2179: Vim9: crash when indexing a dict with a number
Bram Moolenaar <Bram@vim.org>
parents: 23254
diff changeset
2021
23517
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23513
diff changeset
2022 // Stack contains:
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23513
diff changeset
2023 // -3 value to be stored
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23513
diff changeset
2024 // -2 index
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23513
diff changeset
2025 // -1 dict or list
23266
00f7cd9b6033 patch 8.2.2179: Vim9: crash when indexing a dict with a number
Bram Moolenaar <Bram@vim.org>
parents: 23254
diff changeset
2026 tv = STACK_TV_BOT(-3);
22272
eb1f5f618c75 patch 8.2.1685: Vim9: cannot declare a constant value
Bram Moolenaar <Bram@vim.org>
parents: 22262
diff changeset
2027 SOURCING_LNUM = iptr->isn_lnum;
23266
00f7cd9b6033 patch 8.2.2179: Vim9: crash when indexing a dict with a number
Bram Moolenaar <Bram@vim.org>
parents: 23254
diff changeset
2028 if (dest_type == VAR_ANY)
00f7cd9b6033 patch 8.2.2179: Vim9: crash when indexing a dict with a number
Bram Moolenaar <Bram@vim.org>
parents: 23254
diff changeset
2029 {
00f7cd9b6033 patch 8.2.2179: Vim9: crash when indexing a dict with a number
Bram Moolenaar <Bram@vim.org>
parents: 23254
diff changeset
2030 dest_type = tv_dest->v_type;
00f7cd9b6033 patch 8.2.2179: Vim9: crash when indexing a dict with a number
Bram Moolenaar <Bram@vim.org>
parents: 23254
diff changeset
2031 if (dest_type == VAR_DICT)
00f7cd9b6033 patch 8.2.2179: Vim9: crash when indexing a dict with a number
Bram Moolenaar <Bram@vim.org>
parents: 23254
diff changeset
2032 status = do_2string(tv_idx, TRUE);
00f7cd9b6033 patch 8.2.2179: Vim9: crash when indexing a dict with a number
Bram Moolenaar <Bram@vim.org>
parents: 23254
diff changeset
2033 else if (dest_type == VAR_LIST
00f7cd9b6033 patch 8.2.2179: Vim9: crash when indexing a dict with a number
Bram Moolenaar <Bram@vim.org>
parents: 23254
diff changeset
2034 && tv_idx->v_type != VAR_NUMBER)
00f7cd9b6033 patch 8.2.2179: Vim9: crash when indexing a dict with a number
Bram Moolenaar <Bram@vim.org>
parents: 23254
diff changeset
2035 {
00f7cd9b6033 patch 8.2.2179: Vim9: crash when indexing a dict with a number
Bram Moolenaar <Bram@vim.org>
parents: 23254
diff changeset
2036 emsg(_(e_number_exp));
00f7cd9b6033 patch 8.2.2179: Vim9: crash when indexing a dict with a number
Bram Moolenaar <Bram@vim.org>
parents: 23254
diff changeset
2037 status = FAIL;
00f7cd9b6033 patch 8.2.2179: Vim9: crash when indexing a dict with a number
Bram Moolenaar <Bram@vim.org>
parents: 23254
diff changeset
2038 }
00f7cd9b6033 patch 8.2.2179: Vim9: crash when indexing a dict with a number
Bram Moolenaar <Bram@vim.org>
parents: 23254
diff changeset
2039 }
00f7cd9b6033 patch 8.2.2179: Vim9: crash when indexing a dict with a number
Bram Moolenaar <Bram@vim.org>
parents: 23254
diff changeset
2040 else if (dest_type != tv_dest->v_type)
00f7cd9b6033 patch 8.2.2179: Vim9: crash when indexing a dict with a number
Bram Moolenaar <Bram@vim.org>
parents: 23254
diff changeset
2041 {
00f7cd9b6033 patch 8.2.2179: Vim9: crash when indexing a dict with a number
Bram Moolenaar <Bram@vim.org>
parents: 23254
diff changeset
2042 // just in case, should be OK
00f7cd9b6033 patch 8.2.2179: Vim9: crash when indexing a dict with a number
Bram Moolenaar <Bram@vim.org>
parents: 23254
diff changeset
2043 semsg(_(e_expected_str_but_got_str),
00f7cd9b6033 patch 8.2.2179: Vim9: crash when indexing a dict with a number
Bram Moolenaar <Bram@vim.org>
parents: 23254
diff changeset
2044 vartype_name(dest_type),
00f7cd9b6033 patch 8.2.2179: Vim9: crash when indexing a dict with a number
Bram Moolenaar <Bram@vim.org>
parents: 23254
diff changeset
2045 vartype_name(tv_dest->v_type));
00f7cd9b6033 patch 8.2.2179: Vim9: crash when indexing a dict with a number
Bram Moolenaar <Bram@vim.org>
parents: 23254
diff changeset
2046 status = FAIL;
00f7cd9b6033 patch 8.2.2179: Vim9: crash when indexing a dict with a number
Bram Moolenaar <Bram@vim.org>
parents: 23254
diff changeset
2047 }
00f7cd9b6033 patch 8.2.2179: Vim9: crash when indexing a dict with a number
Bram Moolenaar <Bram@vim.org>
parents: 23254
diff changeset
2048
00f7cd9b6033 patch 8.2.2179: Vim9: crash when indexing a dict with a number
Bram Moolenaar <Bram@vim.org>
parents: 23254
diff changeset
2049 if (status == OK && dest_type == VAR_LIST)
20349
e29b2ec8d4d2 patch 8.2.0730: Vim9: Assignment to dict member does not work
Bram Moolenaar <Bram@vim.org>
parents: 20341
diff changeset
2050 {
23650
83a69ada0274 patch 8.2.2367: test failures on some less often used systems
Bram Moolenaar <Bram@vim.org>
parents: 23628
diff changeset
2051 long lidx = (long)tv_idx->vval.v_number;
83a69ada0274 patch 8.2.2367: test failures on some less often used systems
Bram Moolenaar <Bram@vim.org>
parents: 23628
diff changeset
2052 list_T *list = tv_dest->vval.v_list;
23266
00f7cd9b6033 patch 8.2.2179: Vim9: crash when indexing a dict with a number
Bram Moolenaar <Bram@vim.org>
parents: 23254
diff changeset
2053
00f7cd9b6033 patch 8.2.2179: Vim9: crash when indexing a dict with a number
Bram Moolenaar <Bram@vim.org>
parents: 23254
diff changeset
2054 if (list == NULL)
00f7cd9b6033 patch 8.2.2179: Vim9: crash when indexing a dict with a number
Bram Moolenaar <Bram@vim.org>
parents: 23254
diff changeset
2055 {
00f7cd9b6033 patch 8.2.2179: Vim9: crash when indexing a dict with a number
Bram Moolenaar <Bram@vim.org>
parents: 23254
diff changeset
2056 emsg(_(e_list_not_set));
00f7cd9b6033 patch 8.2.2179: Vim9: crash when indexing a dict with a number
Bram Moolenaar <Bram@vim.org>
parents: 23254
diff changeset
2057 goto on_error;
00f7cd9b6033 patch 8.2.2179: Vim9: crash when indexing a dict with a number
Bram Moolenaar <Bram@vim.org>
parents: 23254
diff changeset
2058 }
00f7cd9b6033 patch 8.2.2179: Vim9: crash when indexing a dict with a number
Bram Moolenaar <Bram@vim.org>
parents: 23254
diff changeset
2059 if (lidx < 0 && list->lv_len + lidx >= 0)
00f7cd9b6033 patch 8.2.2179: Vim9: crash when indexing a dict with a number
Bram Moolenaar <Bram@vim.org>
parents: 23254
diff changeset
2060 // negative index is relative to the end
00f7cd9b6033 patch 8.2.2179: Vim9: crash when indexing a dict with a number
Bram Moolenaar <Bram@vim.org>
parents: 23254
diff changeset
2061 lidx = list->lv_len + lidx;
00f7cd9b6033 patch 8.2.2179: Vim9: crash when indexing a dict with a number
Bram Moolenaar <Bram@vim.org>
parents: 23254
diff changeset
2062 if (lidx < 0 || lidx > list->lv_len)
00f7cd9b6033 patch 8.2.2179: Vim9: crash when indexing a dict with a number
Bram Moolenaar <Bram@vim.org>
parents: 23254
diff changeset
2063 {
00f7cd9b6033 patch 8.2.2179: Vim9: crash when indexing a dict with a number
Bram Moolenaar <Bram@vim.org>
parents: 23254
diff changeset
2064 semsg(_(e_listidx), lidx);
00f7cd9b6033 patch 8.2.2179: Vim9: crash when indexing a dict with a number
Bram Moolenaar <Bram@vim.org>
parents: 23254
diff changeset
2065 goto on_error;
00f7cd9b6033 patch 8.2.2179: Vim9: crash when indexing a dict with a number
Bram Moolenaar <Bram@vim.org>
parents: 23254
diff changeset
2066 }
00f7cd9b6033 patch 8.2.2179: Vim9: crash when indexing a dict with a number
Bram Moolenaar <Bram@vim.org>
parents: 23254
diff changeset
2067 if (lidx < list->lv_len)
00f7cd9b6033 patch 8.2.2179: Vim9: crash when indexing a dict with a number
Bram Moolenaar <Bram@vim.org>
parents: 23254
diff changeset
2068 {
00f7cd9b6033 patch 8.2.2179: Vim9: crash when indexing a dict with a number
Bram Moolenaar <Bram@vim.org>
parents: 23254
diff changeset
2069 listitem_T *li = list_find(list, lidx);
00f7cd9b6033 patch 8.2.2179: Vim9: crash when indexing a dict with a number
Bram Moolenaar <Bram@vim.org>
parents: 23254
diff changeset
2070
00f7cd9b6033 patch 8.2.2179: Vim9: crash when indexing a dict with a number
Bram Moolenaar <Bram@vim.org>
parents: 23254
diff changeset
2071 if (error_if_locked(li->li_tv.v_lock,
00f7cd9b6033 patch 8.2.2179: Vim9: crash when indexing a dict with a number
Bram Moolenaar <Bram@vim.org>
parents: 23254
diff changeset
2072 e_cannot_change_list_item))
00f7cd9b6033 patch 8.2.2179: Vim9: crash when indexing a dict with a number
Bram Moolenaar <Bram@vim.org>
parents: 23254
diff changeset
2073 goto on_error;
00f7cd9b6033 patch 8.2.2179: Vim9: crash when indexing a dict with a number
Bram Moolenaar <Bram@vim.org>
parents: 23254
diff changeset
2074 // overwrite existing list item
00f7cd9b6033 patch 8.2.2179: Vim9: crash when indexing a dict with a number
Bram Moolenaar <Bram@vim.org>
parents: 23254
diff changeset
2075 clear_tv(&li->li_tv);
00f7cd9b6033 patch 8.2.2179: Vim9: crash when indexing a dict with a number
Bram Moolenaar <Bram@vim.org>
parents: 23254
diff changeset
2076 li->li_tv = *tv;
00f7cd9b6033 patch 8.2.2179: Vim9: crash when indexing a dict with a number
Bram Moolenaar <Bram@vim.org>
parents: 23254
diff changeset
2077 }
00f7cd9b6033 patch 8.2.2179: Vim9: crash when indexing a dict with a number
Bram Moolenaar <Bram@vim.org>
parents: 23254
diff changeset
2078 else
00f7cd9b6033 patch 8.2.2179: Vim9: crash when indexing a dict with a number
Bram Moolenaar <Bram@vim.org>
parents: 23254
diff changeset
2079 {
00f7cd9b6033 patch 8.2.2179: Vim9: crash when indexing a dict with a number
Bram Moolenaar <Bram@vim.org>
parents: 23254
diff changeset
2080 if (error_if_locked(list->lv_lock,
00f7cd9b6033 patch 8.2.2179: Vim9: crash when indexing a dict with a number
Bram Moolenaar <Bram@vim.org>
parents: 23254
diff changeset
2081 e_cannot_change_list))
00f7cd9b6033 patch 8.2.2179: Vim9: crash when indexing a dict with a number
Bram Moolenaar <Bram@vim.org>
parents: 23254
diff changeset
2082 goto on_error;
00f7cd9b6033 patch 8.2.2179: Vim9: crash when indexing a dict with a number
Bram Moolenaar <Bram@vim.org>
parents: 23254
diff changeset
2083 // append to list, only fails when out of memory
00f7cd9b6033 patch 8.2.2179: Vim9: crash when indexing a dict with a number
Bram Moolenaar <Bram@vim.org>
parents: 23254
diff changeset
2084 if (list_append_tv(list, tv) == FAIL)
24488
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
2085 return FAIL;
23266
00f7cd9b6033 patch 8.2.2179: Vim9: crash when indexing a dict with a number
Bram Moolenaar <Bram@vim.org>
parents: 23254
diff changeset
2086 clear_tv(tv);
00f7cd9b6033 patch 8.2.2179: Vim9: crash when indexing a dict with a number
Bram Moolenaar <Bram@vim.org>
parents: 23254
diff changeset
2087 }
20349
e29b2ec8d4d2 patch 8.2.0730: Vim9: Assignment to dict member does not work
Bram Moolenaar <Bram@vim.org>
parents: 20341
diff changeset
2088 }
23266
00f7cd9b6033 patch 8.2.2179: Vim9: crash when indexing a dict with a number
Bram Moolenaar <Bram@vim.org>
parents: 23254
diff changeset
2089 else if (status == OK && dest_type == VAR_DICT)
20349
e29b2ec8d4d2 patch 8.2.0730: Vim9: Assignment to dict member does not work
Bram Moolenaar <Bram@vim.org>
parents: 20341
diff changeset
2090 {
23266
00f7cd9b6033 patch 8.2.2179: Vim9: crash when indexing a dict with a number
Bram Moolenaar <Bram@vim.org>
parents: 23254
diff changeset
2091 char_u *key = tv_idx->vval.v_string;
00f7cd9b6033 patch 8.2.2179: Vim9: crash when indexing a dict with a number
Bram Moolenaar <Bram@vim.org>
parents: 23254
diff changeset
2092 dict_T *dict = tv_dest->vval.v_dict;
00f7cd9b6033 patch 8.2.2179: Vim9: crash when indexing a dict with a number
Bram Moolenaar <Bram@vim.org>
parents: 23254
diff changeset
2093 dictitem_T *di;
00f7cd9b6033 patch 8.2.2179: Vim9: crash when indexing a dict with a number
Bram Moolenaar <Bram@vim.org>
parents: 23254
diff changeset
2094
00f7cd9b6033 patch 8.2.2179: Vim9: crash when indexing a dict with a number
Bram Moolenaar <Bram@vim.org>
parents: 23254
diff changeset
2095 SOURCING_LNUM = iptr->isn_lnum;
00f7cd9b6033 patch 8.2.2179: Vim9: crash when indexing a dict with a number
Bram Moolenaar <Bram@vim.org>
parents: 23254
diff changeset
2096 if (dict == NULL)
00f7cd9b6033 patch 8.2.2179: Vim9: crash when indexing a dict with a number
Bram Moolenaar <Bram@vim.org>
parents: 23254
diff changeset
2097 {
00f7cd9b6033 patch 8.2.2179: Vim9: crash when indexing a dict with a number
Bram Moolenaar <Bram@vim.org>
parents: 23254
diff changeset
2098 emsg(_(e_dictionary_not_set));
00f7cd9b6033 patch 8.2.2179: Vim9: crash when indexing a dict with a number
Bram Moolenaar <Bram@vim.org>
parents: 23254
diff changeset
2099 goto on_error;
00f7cd9b6033 patch 8.2.2179: Vim9: crash when indexing a dict with a number
Bram Moolenaar <Bram@vim.org>
parents: 23254
diff changeset
2100 }
00f7cd9b6033 patch 8.2.2179: Vim9: crash when indexing a dict with a number
Bram Moolenaar <Bram@vim.org>
parents: 23254
diff changeset
2101 if (key == NULL)
00f7cd9b6033 patch 8.2.2179: Vim9: crash when indexing a dict with a number
Bram Moolenaar <Bram@vim.org>
parents: 23254
diff changeset
2102 key = (char_u *)"";
00f7cd9b6033 patch 8.2.2179: Vim9: crash when indexing a dict with a number
Bram Moolenaar <Bram@vim.org>
parents: 23254
diff changeset
2103 di = dict_find(dict, key, -1);
00f7cd9b6033 patch 8.2.2179: Vim9: crash when indexing a dict with a number
Bram Moolenaar <Bram@vim.org>
parents: 23254
diff changeset
2104 if (di != NULL)
00f7cd9b6033 patch 8.2.2179: Vim9: crash when indexing a dict with a number
Bram Moolenaar <Bram@vim.org>
parents: 23254
diff changeset
2105 {
00f7cd9b6033 patch 8.2.2179: Vim9: crash when indexing a dict with a number
Bram Moolenaar <Bram@vim.org>
parents: 23254
diff changeset
2106 if (error_if_locked(di->di_tv.v_lock,
00f7cd9b6033 patch 8.2.2179: Vim9: crash when indexing a dict with a number
Bram Moolenaar <Bram@vim.org>
parents: 23254
diff changeset
2107 e_cannot_change_dict_item))
00f7cd9b6033 patch 8.2.2179: Vim9: crash when indexing a dict with a number
Bram Moolenaar <Bram@vim.org>
parents: 23254
diff changeset
2108 goto on_error;
00f7cd9b6033 patch 8.2.2179: Vim9: crash when indexing a dict with a number
Bram Moolenaar <Bram@vim.org>
parents: 23254
diff changeset
2109 // overwrite existing value
00f7cd9b6033 patch 8.2.2179: Vim9: crash when indexing a dict with a number
Bram Moolenaar <Bram@vim.org>
parents: 23254
diff changeset
2110 clear_tv(&di->di_tv);
00f7cd9b6033 patch 8.2.2179: Vim9: crash when indexing a dict with a number
Bram Moolenaar <Bram@vim.org>
parents: 23254
diff changeset
2111 di->di_tv = *tv;
00f7cd9b6033 patch 8.2.2179: Vim9: crash when indexing a dict with a number
Bram Moolenaar <Bram@vim.org>
parents: 23254
diff changeset
2112 }
00f7cd9b6033 patch 8.2.2179: Vim9: crash when indexing a dict with a number
Bram Moolenaar <Bram@vim.org>
parents: 23254
diff changeset
2113 else
00f7cd9b6033 patch 8.2.2179: Vim9: crash when indexing a dict with a number
Bram Moolenaar <Bram@vim.org>
parents: 23254
diff changeset
2114 {
00f7cd9b6033 patch 8.2.2179: Vim9: crash when indexing a dict with a number
Bram Moolenaar <Bram@vim.org>
parents: 23254
diff changeset
2115 if (error_if_locked(dict->dv_lock,
00f7cd9b6033 patch 8.2.2179: Vim9: crash when indexing a dict with a number
Bram Moolenaar <Bram@vim.org>
parents: 23254
diff changeset
2116 e_cannot_change_dict))
00f7cd9b6033 patch 8.2.2179: Vim9: crash when indexing a dict with a number
Bram Moolenaar <Bram@vim.org>
parents: 23254
diff changeset
2117 goto on_error;
00f7cd9b6033 patch 8.2.2179: Vim9: crash when indexing a dict with a number
Bram Moolenaar <Bram@vim.org>
parents: 23254
diff changeset
2118 // add to dict, only fails when out of memory
00f7cd9b6033 patch 8.2.2179: Vim9: crash when indexing a dict with a number
Bram Moolenaar <Bram@vim.org>
parents: 23254
diff changeset
2119 if (dict_add_tv(dict, (char *)key, tv) == FAIL)
24488
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
2120 return FAIL;
23266
00f7cd9b6033 patch 8.2.2179: Vim9: crash when indexing a dict with a number
Bram Moolenaar <Bram@vim.org>
parents: 23254
diff changeset
2121 clear_tv(tv);
00f7cd9b6033 patch 8.2.2179: Vim9: crash when indexing a dict with a number
Bram Moolenaar <Bram@vim.org>
parents: 23254
diff changeset
2122 }
20349
e29b2ec8d4d2 patch 8.2.0730: Vim9: Assignment to dict member does not work
Bram Moolenaar <Bram@vim.org>
parents: 20341
diff changeset
2123 }
24434
602e528a8e43 patch 8.2.2757: Vim9: blob tests for legacy and Vim9 script are separate
Bram Moolenaar <Bram@vim.org>
parents: 24432
diff changeset
2124 else if (status == OK && dest_type == VAR_BLOB)
602e528a8e43 patch 8.2.2757: Vim9: blob tests for legacy and Vim9 script are separate
Bram Moolenaar <Bram@vim.org>
parents: 24432
diff changeset
2125 {
24475
96905804bf5a patch 8.2.2777: Vim9: blob operations not tested in all ways
Bram Moolenaar <Bram@vim.org>
parents: 24471
diff changeset
2126 long lidx = (long)tv_idx->vval.v_number;
96905804bf5a patch 8.2.2777: Vim9: blob operations not tested in all ways
Bram Moolenaar <Bram@vim.org>
parents: 24471
diff changeset
2127 blob_T *blob = tv_dest->vval.v_blob;
96905804bf5a patch 8.2.2777: Vim9: blob operations not tested in all ways
Bram Moolenaar <Bram@vim.org>
parents: 24471
diff changeset
2128 varnumber_T nr;
96905804bf5a patch 8.2.2777: Vim9: blob operations not tested in all ways
Bram Moolenaar <Bram@vim.org>
parents: 24471
diff changeset
2129 int error = FALSE;
96905804bf5a patch 8.2.2777: Vim9: blob operations not tested in all ways
Bram Moolenaar <Bram@vim.org>
parents: 24471
diff changeset
2130 int len;
96905804bf5a patch 8.2.2777: Vim9: blob operations not tested in all ways
Bram Moolenaar <Bram@vim.org>
parents: 24471
diff changeset
2131
96905804bf5a patch 8.2.2777: Vim9: blob operations not tested in all ways
Bram Moolenaar <Bram@vim.org>
parents: 24471
diff changeset
2132 if (blob == NULL)
96905804bf5a patch 8.2.2777: Vim9: blob operations not tested in all ways
Bram Moolenaar <Bram@vim.org>
parents: 24471
diff changeset
2133 {
96905804bf5a patch 8.2.2777: Vim9: blob operations not tested in all ways
Bram Moolenaar <Bram@vim.org>
parents: 24471
diff changeset
2134 emsg(_(e_blob_not_set));
96905804bf5a patch 8.2.2777: Vim9: blob operations not tested in all ways
Bram Moolenaar <Bram@vim.org>
parents: 24471
diff changeset
2135 goto on_error;
96905804bf5a patch 8.2.2777: Vim9: blob operations not tested in all ways
Bram Moolenaar <Bram@vim.org>
parents: 24471
diff changeset
2136 }
96905804bf5a patch 8.2.2777: Vim9: blob operations not tested in all ways
Bram Moolenaar <Bram@vim.org>
parents: 24471
diff changeset
2137 len = blob_len(blob);
96905804bf5a patch 8.2.2777: Vim9: blob operations not tested in all ways
Bram Moolenaar <Bram@vim.org>
parents: 24471
diff changeset
2138 if (lidx < 0 && len + lidx >= 0)
96905804bf5a patch 8.2.2777: Vim9: blob operations not tested in all ways
Bram Moolenaar <Bram@vim.org>
parents: 24471
diff changeset
2139 // negative index is relative to the end
96905804bf5a patch 8.2.2777: Vim9: blob operations not tested in all ways
Bram Moolenaar <Bram@vim.org>
parents: 24471
diff changeset
2140 lidx = len + lidx;
96905804bf5a patch 8.2.2777: Vim9: blob operations not tested in all ways
Bram Moolenaar <Bram@vim.org>
parents: 24471
diff changeset
2141
96905804bf5a patch 8.2.2777: Vim9: blob operations not tested in all ways
Bram Moolenaar <Bram@vim.org>
parents: 24471
diff changeset
2142 // Can add one byte at the end.
96905804bf5a patch 8.2.2777: Vim9: blob operations not tested in all ways
Bram Moolenaar <Bram@vim.org>
parents: 24471
diff changeset
2143 if (lidx < 0 || lidx > len)
96905804bf5a patch 8.2.2777: Vim9: blob operations not tested in all ways
Bram Moolenaar <Bram@vim.org>
parents: 24471
diff changeset
2144 {
96905804bf5a patch 8.2.2777: Vim9: blob operations not tested in all ways
Bram Moolenaar <Bram@vim.org>
parents: 24471
diff changeset
2145 semsg(_(e_blobidx), lidx);
96905804bf5a patch 8.2.2777: Vim9: blob operations not tested in all ways
Bram Moolenaar <Bram@vim.org>
parents: 24471
diff changeset
2146 goto on_error;
96905804bf5a patch 8.2.2777: Vim9: blob operations not tested in all ways
Bram Moolenaar <Bram@vim.org>
parents: 24471
diff changeset
2147 }
96905804bf5a patch 8.2.2777: Vim9: blob operations not tested in all ways
Bram Moolenaar <Bram@vim.org>
parents: 24471
diff changeset
2148 if (value_check_lock(blob->bv_lock,
96905804bf5a patch 8.2.2777: Vim9: blob operations not tested in all ways
Bram Moolenaar <Bram@vim.org>
parents: 24471
diff changeset
2149 (char_u *)"blob", FALSE))
96905804bf5a patch 8.2.2777: Vim9: blob operations not tested in all ways
Bram Moolenaar <Bram@vim.org>
parents: 24471
diff changeset
2150 goto on_error;
96905804bf5a patch 8.2.2777: Vim9: blob operations not tested in all ways
Bram Moolenaar <Bram@vim.org>
parents: 24471
diff changeset
2151 nr = tv_get_number_chk(tv, &error);
96905804bf5a patch 8.2.2777: Vim9: blob operations not tested in all ways
Bram Moolenaar <Bram@vim.org>
parents: 24471
diff changeset
2152 if (error)
96905804bf5a patch 8.2.2777: Vim9: blob operations not tested in all ways
Bram Moolenaar <Bram@vim.org>
parents: 24471
diff changeset
2153 goto on_error;
96905804bf5a patch 8.2.2777: Vim9: blob operations not tested in all ways
Bram Moolenaar <Bram@vim.org>
parents: 24471
diff changeset
2154 blob_set_append(blob, lidx, nr);
24434
602e528a8e43 patch 8.2.2757: Vim9: blob tests for legacy and Vim9 script are separate
Bram Moolenaar <Bram@vim.org>
parents: 24432
diff changeset
2155 }
20349
e29b2ec8d4d2 patch 8.2.0730: Vim9: Assignment to dict member does not work
Bram Moolenaar <Bram@vim.org>
parents: 20341
diff changeset
2156 else
e29b2ec8d4d2 patch 8.2.0730: Vim9: Assignment to dict member does not work
Bram Moolenaar <Bram@vim.org>
parents: 20341
diff changeset
2157 {
23266
00f7cd9b6033 patch 8.2.2179: Vim9: crash when indexing a dict with a number
Bram Moolenaar <Bram@vim.org>
parents: 23254
diff changeset
2158 status = FAIL;
00f7cd9b6033 patch 8.2.2179: Vim9: crash when indexing a dict with a number
Bram Moolenaar <Bram@vim.org>
parents: 23254
diff changeset
2159 semsg(_(e_cannot_index_str), vartype_name(dest_type));
20349
e29b2ec8d4d2 patch 8.2.0730: Vim9: Assignment to dict member does not work
Bram Moolenaar <Bram@vim.org>
parents: 20341
diff changeset
2160 }
23266
00f7cd9b6033 patch 8.2.2179: Vim9: crash when indexing a dict with a number
Bram Moolenaar <Bram@vim.org>
parents: 23254
diff changeset
2161
20349
e29b2ec8d4d2 patch 8.2.0730: Vim9: Assignment to dict member does not work
Bram Moolenaar <Bram@vim.org>
parents: 20341
diff changeset
2162 clear_tv(tv_idx);
23266
00f7cd9b6033 patch 8.2.2179: Vim9: crash when indexing a dict with a number
Bram Moolenaar <Bram@vim.org>
parents: 23254
diff changeset
2163 clear_tv(tv_dest);
24488
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
2164 ectx->ec_stack.ga_len -= 3;
23266
00f7cd9b6033 patch 8.2.2179: Vim9: crash when indexing a dict with a number
Bram Moolenaar <Bram@vim.org>
parents: 23254
diff changeset
2165 if (status == FAIL)
21576
f4252efe370e patch 8.2.1338: Vim9: assigning to script-local variable doesn't check type
Bram Moolenaar <Bram@vim.org>
parents: 21574
diff changeset
2166 {
23266
00f7cd9b6033 patch 8.2.2179: Vim9: crash when indexing a dict with a number
Bram Moolenaar <Bram@vim.org>
parents: 23254
diff changeset
2167 clear_tv(tv);
21576
f4252efe370e patch 8.2.1338: Vim9: assigning to script-local variable doesn't check type
Bram Moolenaar <Bram@vim.org>
parents: 21574
diff changeset
2168 goto on_error;
f4252efe370e patch 8.2.1338: Vim9: assigning to script-local variable doesn't check type
Bram Moolenaar <Bram@vim.org>
parents: 21574
diff changeset
2169 }
20349
e29b2ec8d4d2 patch 8.2.0730: Vim9: Assignment to dict member does not work
Bram Moolenaar <Bram@vim.org>
parents: 20341
diff changeset
2170 }
e29b2ec8d4d2 patch 8.2.0730: Vim9: Assignment to dict member does not work
Bram Moolenaar <Bram@vim.org>
parents: 20341
diff changeset
2171 break;
e29b2ec8d4d2 patch 8.2.0730: Vim9: Assignment to dict member does not work
Bram Moolenaar <Bram@vim.org>
parents: 20341
diff changeset
2172
24434
602e528a8e43 patch 8.2.2757: Vim9: blob tests for legacy and Vim9 script are separate
Bram Moolenaar <Bram@vim.org>
parents: 24432
diff changeset
2173 // store value in blob range
602e528a8e43 patch 8.2.2757: Vim9: blob tests for legacy and Vim9 script are separate
Bram Moolenaar <Bram@vim.org>
parents: 24432
diff changeset
2174 case ISN_STORERANGE:
602e528a8e43 patch 8.2.2757: Vim9: blob tests for legacy and Vim9 script are separate
Bram Moolenaar <Bram@vim.org>
parents: 24432
diff changeset
2175 {
602e528a8e43 patch 8.2.2757: Vim9: blob tests for legacy and Vim9 script are separate
Bram Moolenaar <Bram@vim.org>
parents: 24432
diff changeset
2176 typval_T *tv_idx1 = STACK_TV_BOT(-3);
602e528a8e43 patch 8.2.2757: Vim9: blob tests for legacy and Vim9 script are separate
Bram Moolenaar <Bram@vim.org>
parents: 24432
diff changeset
2177 typval_T *tv_idx2 = STACK_TV_BOT(-2);
602e528a8e43 patch 8.2.2757: Vim9: blob tests for legacy and Vim9 script are separate
Bram Moolenaar <Bram@vim.org>
parents: 24432
diff changeset
2178 typval_T *tv_dest = STACK_TV_BOT(-1);
602e528a8e43 patch 8.2.2757: Vim9: blob tests for legacy and Vim9 script are separate
Bram Moolenaar <Bram@vim.org>
parents: 24432
diff changeset
2179 int status = OK;
602e528a8e43 patch 8.2.2757: Vim9: blob tests for legacy and Vim9 script are separate
Bram Moolenaar <Bram@vim.org>
parents: 24432
diff changeset
2180
602e528a8e43 patch 8.2.2757: Vim9: blob tests for legacy and Vim9 script are separate
Bram Moolenaar <Bram@vim.org>
parents: 24432
diff changeset
2181 // Stack contains:
602e528a8e43 patch 8.2.2757: Vim9: blob tests for legacy and Vim9 script are separate
Bram Moolenaar <Bram@vim.org>
parents: 24432
diff changeset
2182 // -4 value to be stored
602e528a8e43 patch 8.2.2757: Vim9: blob tests for legacy and Vim9 script are separate
Bram Moolenaar <Bram@vim.org>
parents: 24432
diff changeset
2183 // -3 first index or "none"
602e528a8e43 patch 8.2.2757: Vim9: blob tests for legacy and Vim9 script are separate
Bram Moolenaar <Bram@vim.org>
parents: 24432
diff changeset
2184 // -2 second index or "none"
602e528a8e43 patch 8.2.2757: Vim9: blob tests for legacy and Vim9 script are separate
Bram Moolenaar <Bram@vim.org>
parents: 24432
diff changeset
2185 // -1 destination blob
602e528a8e43 patch 8.2.2757: Vim9: blob tests for legacy and Vim9 script are separate
Bram Moolenaar <Bram@vim.org>
parents: 24432
diff changeset
2186 tv = STACK_TV_BOT(-4);
602e528a8e43 patch 8.2.2757: Vim9: blob tests for legacy and Vim9 script are separate
Bram Moolenaar <Bram@vim.org>
parents: 24432
diff changeset
2187 if (tv_dest->v_type != VAR_BLOB)
602e528a8e43 patch 8.2.2757: Vim9: blob tests for legacy and Vim9 script are separate
Bram Moolenaar <Bram@vim.org>
parents: 24432
diff changeset
2188 {
602e528a8e43 patch 8.2.2757: Vim9: blob tests for legacy and Vim9 script are separate
Bram Moolenaar <Bram@vim.org>
parents: 24432
diff changeset
2189 status = FAIL;
602e528a8e43 patch 8.2.2757: Vim9: blob tests for legacy and Vim9 script are separate
Bram Moolenaar <Bram@vim.org>
parents: 24432
diff changeset
2190 emsg(_(e_blob_required));
602e528a8e43 patch 8.2.2757: Vim9: blob tests for legacy and Vim9 script are separate
Bram Moolenaar <Bram@vim.org>
parents: 24432
diff changeset
2191 }
602e528a8e43 patch 8.2.2757: Vim9: blob tests for legacy and Vim9 script are separate
Bram Moolenaar <Bram@vim.org>
parents: 24432
diff changeset
2192 else
602e528a8e43 patch 8.2.2757: Vim9: blob tests for legacy and Vim9 script are separate
Bram Moolenaar <Bram@vim.org>
parents: 24432
diff changeset
2193 {
602e528a8e43 patch 8.2.2757: Vim9: blob tests for legacy and Vim9 script are separate
Bram Moolenaar <Bram@vim.org>
parents: 24432
diff changeset
2194 varnumber_T n1;
602e528a8e43 patch 8.2.2757: Vim9: blob tests for legacy and Vim9 script are separate
Bram Moolenaar <Bram@vim.org>
parents: 24432
diff changeset
2195 varnumber_T n2;
602e528a8e43 patch 8.2.2757: Vim9: blob tests for legacy and Vim9 script are separate
Bram Moolenaar <Bram@vim.org>
parents: 24432
diff changeset
2196 int error = FALSE;
602e528a8e43 patch 8.2.2757: Vim9: blob tests for legacy and Vim9 script are separate
Bram Moolenaar <Bram@vim.org>
parents: 24432
diff changeset
2197
602e528a8e43 patch 8.2.2757: Vim9: blob tests for legacy and Vim9 script are separate
Bram Moolenaar <Bram@vim.org>
parents: 24432
diff changeset
2198 n1 = tv_get_number_chk(tv_idx1, &error);
602e528a8e43 patch 8.2.2757: Vim9: blob tests for legacy and Vim9 script are separate
Bram Moolenaar <Bram@vim.org>
parents: 24432
diff changeset
2199 if (error)
602e528a8e43 patch 8.2.2757: Vim9: blob tests for legacy and Vim9 script are separate
Bram Moolenaar <Bram@vim.org>
parents: 24432
diff changeset
2200 status = FAIL;
602e528a8e43 patch 8.2.2757: Vim9: blob tests for legacy and Vim9 script are separate
Bram Moolenaar <Bram@vim.org>
parents: 24432
diff changeset
2201 else
602e528a8e43 patch 8.2.2757: Vim9: blob tests for legacy and Vim9 script are separate
Bram Moolenaar <Bram@vim.org>
parents: 24432
diff changeset
2202 {
602e528a8e43 patch 8.2.2757: Vim9: blob tests for legacy and Vim9 script are separate
Bram Moolenaar <Bram@vim.org>
parents: 24432
diff changeset
2203 if (tv_idx2->v_type == VAR_SPECIAL
602e528a8e43 patch 8.2.2757: Vim9: blob tests for legacy and Vim9 script are separate
Bram Moolenaar <Bram@vim.org>
parents: 24432
diff changeset
2204 && tv_idx2->vval.v_number == VVAL_NONE)
602e528a8e43 patch 8.2.2757: Vim9: blob tests for legacy and Vim9 script are separate
Bram Moolenaar <Bram@vim.org>
parents: 24432
diff changeset
2205 n2 = blob_len(tv_dest->vval.v_blob) - 1;
602e528a8e43 patch 8.2.2757: Vim9: blob tests for legacy and Vim9 script are separate
Bram Moolenaar <Bram@vim.org>
parents: 24432
diff changeset
2206 else
602e528a8e43 patch 8.2.2757: Vim9: blob tests for legacy and Vim9 script are separate
Bram Moolenaar <Bram@vim.org>
parents: 24432
diff changeset
2207 n2 = tv_get_number_chk(tv_idx2, &error);
602e528a8e43 patch 8.2.2757: Vim9: blob tests for legacy and Vim9 script are separate
Bram Moolenaar <Bram@vim.org>
parents: 24432
diff changeset
2208 if (error)
602e528a8e43 patch 8.2.2757: Vim9: blob tests for legacy and Vim9 script are separate
Bram Moolenaar <Bram@vim.org>
parents: 24432
diff changeset
2209 status = FAIL;
602e528a8e43 patch 8.2.2757: Vim9: blob tests for legacy and Vim9 script are separate
Bram Moolenaar <Bram@vim.org>
parents: 24432
diff changeset
2210 else
24450
3e1886f1e875 patch 8.2.2765: Vim9: not all blob operations work
Bram Moolenaar <Bram@vim.org>
parents: 24434
diff changeset
2211 {
3e1886f1e875 patch 8.2.2765: Vim9: not all blob operations work
Bram Moolenaar <Bram@vim.org>
parents: 24434
diff changeset
2212 long bloblen = blob_len(tv_dest->vval.v_blob);
3e1886f1e875 patch 8.2.2765: Vim9: not all blob operations work
Bram Moolenaar <Bram@vim.org>
parents: 24434
diff changeset
2213
3e1886f1e875 patch 8.2.2765: Vim9: not all blob operations work
Bram Moolenaar <Bram@vim.org>
parents: 24434
diff changeset
2214 if (check_blob_index(bloblen,
24454
53216e87f21c patch 8.2.2767: compiler warning for unused argument
Bram Moolenaar <Bram@vim.org>
parents: 24450
diff changeset
2215 n1, FALSE) == FAIL
24450
3e1886f1e875 patch 8.2.2765: Vim9: not all blob operations work
Bram Moolenaar <Bram@vim.org>
parents: 24434
diff changeset
2216 || check_blob_range(bloblen,
3e1886f1e875 patch 8.2.2765: Vim9: not all blob operations work
Bram Moolenaar <Bram@vim.org>
parents: 24434
diff changeset
2217 n1, n2, FALSE) == FAIL)
3e1886f1e875 patch 8.2.2765: Vim9: not all blob operations work
Bram Moolenaar <Bram@vim.org>
parents: 24434
diff changeset
2218 status = FAIL;
3e1886f1e875 patch 8.2.2765: Vim9: not all blob operations work
Bram Moolenaar <Bram@vim.org>
parents: 24434
diff changeset
2219 else
3e1886f1e875 patch 8.2.2765: Vim9: not all blob operations work
Bram Moolenaar <Bram@vim.org>
parents: 24434
diff changeset
2220 status = blob_set_range(
3e1886f1e875 patch 8.2.2765: Vim9: not all blob operations work
Bram Moolenaar <Bram@vim.org>
parents: 24434
diff changeset
2221 tv_dest->vval.v_blob, n1, n2, tv);
3e1886f1e875 patch 8.2.2765: Vim9: not all blob operations work
Bram Moolenaar <Bram@vim.org>
parents: 24434
diff changeset
2222 }
24434
602e528a8e43 patch 8.2.2757: Vim9: blob tests for legacy and Vim9 script are separate
Bram Moolenaar <Bram@vim.org>
parents: 24432
diff changeset
2223 }
602e528a8e43 patch 8.2.2757: Vim9: blob tests for legacy and Vim9 script are separate
Bram Moolenaar <Bram@vim.org>
parents: 24432
diff changeset
2224 }
602e528a8e43 patch 8.2.2757: Vim9: blob tests for legacy and Vim9 script are separate
Bram Moolenaar <Bram@vim.org>
parents: 24432
diff changeset
2225
602e528a8e43 patch 8.2.2757: Vim9: blob tests for legacy and Vim9 script are separate
Bram Moolenaar <Bram@vim.org>
parents: 24432
diff changeset
2226 clear_tv(tv_idx1);
602e528a8e43 patch 8.2.2757: Vim9: blob tests for legacy and Vim9 script are separate
Bram Moolenaar <Bram@vim.org>
parents: 24432
diff changeset
2227 clear_tv(tv_idx2);
602e528a8e43 patch 8.2.2757: Vim9: blob tests for legacy and Vim9 script are separate
Bram Moolenaar <Bram@vim.org>
parents: 24432
diff changeset
2228 clear_tv(tv_dest);
24488
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
2229 ectx->ec_stack.ga_len -= 4;
24434
602e528a8e43 patch 8.2.2757: Vim9: blob tests for legacy and Vim9 script are separate
Bram Moolenaar <Bram@vim.org>
parents: 24432
diff changeset
2230 clear_tv(tv);
602e528a8e43 patch 8.2.2757: Vim9: blob tests for legacy and Vim9 script are separate
Bram Moolenaar <Bram@vim.org>
parents: 24432
diff changeset
2231
602e528a8e43 patch 8.2.2757: Vim9: blob tests for legacy and Vim9 script are separate
Bram Moolenaar <Bram@vim.org>
parents: 24432
diff changeset
2232 if (status == FAIL)
602e528a8e43 patch 8.2.2757: Vim9: blob tests for legacy and Vim9 script are separate
Bram Moolenaar <Bram@vim.org>
parents: 24432
diff changeset
2233 goto on_error;
602e528a8e43 patch 8.2.2757: Vim9: blob tests for legacy and Vim9 script are separate
Bram Moolenaar <Bram@vim.org>
parents: 24432
diff changeset
2234 }
602e528a8e43 patch 8.2.2757: Vim9: blob tests for legacy and Vim9 script are separate
Bram Moolenaar <Bram@vim.org>
parents: 24432
diff changeset
2235 break;
602e528a8e43 patch 8.2.2757: Vim9: blob tests for legacy and Vim9 script are separate
Bram Moolenaar <Bram@vim.org>
parents: 24432
diff changeset
2236
23559
64dfb69e7d46 patch 8.2.2322: Vim9: closure nested limiting to one level
Bram Moolenaar <Bram@vim.org>
parents: 23557
diff changeset
2237 // load or store variable or argument from outer scope
64dfb69e7d46 patch 8.2.2322: Vim9: closure nested limiting to one level
Bram Moolenaar <Bram@vim.org>
parents: 23557
diff changeset
2238 case ISN_LOADOUTER:
64dfb69e7d46 patch 8.2.2322: Vim9: closure nested limiting to one level
Bram Moolenaar <Bram@vim.org>
parents: 23557
diff changeset
2239 case ISN_STOREOUTER:
64dfb69e7d46 patch 8.2.2322: Vim9: closure nested limiting to one level
Bram Moolenaar <Bram@vim.org>
parents: 23557
diff changeset
2240 {
64dfb69e7d46 patch 8.2.2322: Vim9: closure nested limiting to one level
Bram Moolenaar <Bram@vim.org>
parents: 23557
diff changeset
2241 int depth = iptr->isn_arg.outer.outer_depth;
24488
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
2242 outer_T *outer = ectx->ec_outer;
23559
64dfb69e7d46 patch 8.2.2322: Vim9: closure nested limiting to one level
Bram Moolenaar <Bram@vim.org>
parents: 23557
diff changeset
2243
64dfb69e7d46 patch 8.2.2322: Vim9: closure nested limiting to one level
Bram Moolenaar <Bram@vim.org>
parents: 23557
diff changeset
2244 while (depth > 1 && outer != NULL)
64dfb69e7d46 patch 8.2.2322: Vim9: closure nested limiting to one level
Bram Moolenaar <Bram@vim.org>
parents: 23557
diff changeset
2245 {
64dfb69e7d46 patch 8.2.2322: Vim9: closure nested limiting to one level
Bram Moolenaar <Bram@vim.org>
parents: 23557
diff changeset
2246 outer = outer->out_up;
64dfb69e7d46 patch 8.2.2322: Vim9: closure nested limiting to one level
Bram Moolenaar <Bram@vim.org>
parents: 23557
diff changeset
2247 --depth;
64dfb69e7d46 patch 8.2.2322: Vim9: closure nested limiting to one level
Bram Moolenaar <Bram@vim.org>
parents: 23557
diff changeset
2248 }
64dfb69e7d46 patch 8.2.2322: Vim9: closure nested limiting to one level
Bram Moolenaar <Bram@vim.org>
parents: 23557
diff changeset
2249 if (outer == NULL)
64dfb69e7d46 patch 8.2.2322: Vim9: closure nested limiting to one level
Bram Moolenaar <Bram@vim.org>
parents: 23557
diff changeset
2250 {
64dfb69e7d46 patch 8.2.2322: Vim9: closure nested limiting to one level
Bram Moolenaar <Bram@vim.org>
parents: 23557
diff changeset
2251 SOURCING_LNUM = iptr->isn_lnum;
64dfb69e7d46 patch 8.2.2322: Vim9: closure nested limiting to one level
Bram Moolenaar <Bram@vim.org>
parents: 23557
diff changeset
2252 iemsg("LOADOUTER depth more than scope levels");
24488
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
2253 return FAIL;
23559
64dfb69e7d46 patch 8.2.2322: Vim9: closure nested limiting to one level
Bram Moolenaar <Bram@vim.org>
parents: 23557
diff changeset
2254 }
64dfb69e7d46 patch 8.2.2322: Vim9: closure nested limiting to one level
Bram Moolenaar <Bram@vim.org>
parents: 23557
diff changeset
2255 tv = ((typval_T *)outer->out_stack->ga_data)
64dfb69e7d46 patch 8.2.2322: Vim9: closure nested limiting to one level
Bram Moolenaar <Bram@vim.org>
parents: 23557
diff changeset
2256 + outer->out_frame_idx + STACK_FRAME_SIZE
64dfb69e7d46 patch 8.2.2322: Vim9: closure nested limiting to one level
Bram Moolenaar <Bram@vim.org>
parents: 23557
diff changeset
2257 + iptr->isn_arg.outer.outer_idx;
64dfb69e7d46 patch 8.2.2322: Vim9: closure nested limiting to one level
Bram Moolenaar <Bram@vim.org>
parents: 23557
diff changeset
2258 if (iptr->isn_type == ISN_LOADOUTER)
64dfb69e7d46 patch 8.2.2322: Vim9: closure nested limiting to one level
Bram Moolenaar <Bram@vim.org>
parents: 23557
diff changeset
2259 {
24488
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
2260 if (GA_GROW(&ectx->ec_stack, 1) == FAIL)
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
2261 return FAIL;
23559
64dfb69e7d46 patch 8.2.2322: Vim9: closure nested limiting to one level
Bram Moolenaar <Bram@vim.org>
parents: 23557
diff changeset
2262 copy_tv(tv, STACK_TV_BOT(0));
24488
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
2263 ++ectx->ec_stack.ga_len;
23559
64dfb69e7d46 patch 8.2.2322: Vim9: closure nested limiting to one level
Bram Moolenaar <Bram@vim.org>
parents: 23557
diff changeset
2264 }
64dfb69e7d46 patch 8.2.2322: Vim9: closure nested limiting to one level
Bram Moolenaar <Bram@vim.org>
parents: 23557
diff changeset
2265 else
64dfb69e7d46 patch 8.2.2322: Vim9: closure nested limiting to one level
Bram Moolenaar <Bram@vim.org>
parents: 23557
diff changeset
2266 {
24488
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
2267 --ectx->ec_stack.ga_len;
23559
64dfb69e7d46 patch 8.2.2322: Vim9: closure nested limiting to one level
Bram Moolenaar <Bram@vim.org>
parents: 23557
diff changeset
2268 clear_tv(tv);
64dfb69e7d46 patch 8.2.2322: Vim9: closure nested limiting to one level
Bram Moolenaar <Bram@vim.org>
parents: 23557
diff changeset
2269 *tv = *STACK_TV_BOT(0);
64dfb69e7d46 patch 8.2.2322: Vim9: closure nested limiting to one level
Bram Moolenaar <Bram@vim.org>
parents: 23557
diff changeset
2270 }
64dfb69e7d46 patch 8.2.2322: Vim9: closure nested limiting to one level
Bram Moolenaar <Bram@vim.org>
parents: 23557
diff changeset
2271 }
64dfb69e7d46 patch 8.2.2322: Vim9: closure nested limiting to one level
Bram Moolenaar <Bram@vim.org>
parents: 23557
diff changeset
2272 break;
64dfb69e7d46 patch 8.2.2322: Vim9: closure nested limiting to one level
Bram Moolenaar <Bram@vim.org>
parents: 23557
diff changeset
2273
23517
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23513
diff changeset
2274 // unlet item in list or dict variable
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23513
diff changeset
2275 case ISN_UNLETINDEX:
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23513
diff changeset
2276 {
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23513
diff changeset
2277 typval_T *tv_idx = STACK_TV_BOT(-2);
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23513
diff changeset
2278 typval_T *tv_dest = STACK_TV_BOT(-1);
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23513
diff changeset
2279 int status = OK;
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23513
diff changeset
2280
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23513
diff changeset
2281 // Stack contains:
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23513
diff changeset
2282 // -2 index
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23513
diff changeset
2283 // -1 dict or list
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23513
diff changeset
2284 if (tv_dest->v_type == VAR_DICT)
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23513
diff changeset
2285 {
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23513
diff changeset
2286 // unlet a dict item, index must be a string
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23513
diff changeset
2287 if (tv_idx->v_type != VAR_STRING)
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23513
diff changeset
2288 {
23523
b0a6e7325169 patch 8.2.2304: Vim9: no test for unletting an imported variable
Bram Moolenaar <Bram@vim.org>
parents: 23517
diff changeset
2289 SOURCING_LNUM = iptr->isn_lnum;
23517
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23513
diff changeset
2290 semsg(_(e_expected_str_but_got_str),
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23513
diff changeset
2291 vartype_name(VAR_STRING),
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23513
diff changeset
2292 vartype_name(tv_idx->v_type));
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23513
diff changeset
2293 status = FAIL;
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23513
diff changeset
2294 }
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23513
diff changeset
2295 else
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23513
diff changeset
2296 {
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23513
diff changeset
2297 dict_T *d = tv_dest->vval.v_dict;
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23513
diff changeset
2298 char_u *key = tv_idx->vval.v_string;
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23513
diff changeset
2299 dictitem_T *di = NULL;
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23513
diff changeset
2300
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23513
diff changeset
2301 if (key == NULL)
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23513
diff changeset
2302 key = (char_u *)"";
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23513
diff changeset
2303 if (d != NULL)
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23513
diff changeset
2304 di = dict_find(d, key, (int)STRLEN(key));
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23513
diff changeset
2305 if (di == NULL)
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23513
diff changeset
2306 {
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23513
diff changeset
2307 // NULL dict is equivalent to empty dict
23523
b0a6e7325169 patch 8.2.2304: Vim9: no test for unletting an imported variable
Bram Moolenaar <Bram@vim.org>
parents: 23517
diff changeset
2308 SOURCING_LNUM = iptr->isn_lnum;
23517
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23513
diff changeset
2309 semsg(_(e_dictkey), key);
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23513
diff changeset
2310 status = FAIL;
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23513
diff changeset
2311 }
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23513
diff changeset
2312 else
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23513
diff changeset
2313 {
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23513
diff changeset
2314 // TODO: check for dict or item locked
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23513
diff changeset
2315 dictitem_remove(d, di);
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23513
diff changeset
2316 }
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23513
diff changeset
2317 }
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23513
diff changeset
2318 }
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23513
diff changeset
2319 else if (tv_dest->v_type == VAR_LIST)
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23513
diff changeset
2320 {
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23513
diff changeset
2321 // unlet a List item, index must be a number
23982
9fcd71d0db89 patch 8.2.2533: Vim9: cannot use a range with :unlet
Bram Moolenaar <Bram@vim.org>
parents: 23976
diff changeset
2322 SOURCING_LNUM = iptr->isn_lnum;
9fcd71d0db89 patch 8.2.2533: Vim9: cannot use a range with :unlet
Bram Moolenaar <Bram@vim.org>
parents: 23976
diff changeset
2323 if (check_for_number(tv_idx) == FAIL)
23517
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23513
diff changeset
2324 {
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23513
diff changeset
2325 status = FAIL;
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23513
diff changeset
2326 }
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23513
diff changeset
2327 else
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23513
diff changeset
2328 {
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23513
diff changeset
2329 list_T *l = tv_dest->vval.v_list;
23650
83a69ada0274 patch 8.2.2367: test failures on some less often used systems
Bram Moolenaar <Bram@vim.org>
parents: 23628
diff changeset
2330 long n = (long)tv_idx->vval.v_number;
23517
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23513
diff changeset
2331 listitem_T *li = NULL;
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23513
diff changeset
2332
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23513
diff changeset
2333 li = list_find(l, n);
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23513
diff changeset
2334 if (li == NULL)
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23513
diff changeset
2335 {
23523
b0a6e7325169 patch 8.2.2304: Vim9: no test for unletting an imported variable
Bram Moolenaar <Bram@vim.org>
parents: 23517
diff changeset
2336 SOURCING_LNUM = iptr->isn_lnum;
23517
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23513
diff changeset
2337 semsg(_(e_listidx), n);
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23513
diff changeset
2338 status = FAIL;
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23513
diff changeset
2339 }
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23513
diff changeset
2340 else
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23513
diff changeset
2341 // TODO: check for list or item locked
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23513
diff changeset
2342 listitem_remove(l, li);
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23513
diff changeset
2343 }
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23513
diff changeset
2344 }
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23513
diff changeset
2345 else
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23513
diff changeset
2346 {
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23513
diff changeset
2347 status = FAIL;
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23513
diff changeset
2348 semsg(_(e_cannot_index_str),
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23513
diff changeset
2349 vartype_name(tv_dest->v_type));
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23513
diff changeset
2350 }
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23513
diff changeset
2351
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23513
diff changeset
2352 clear_tv(tv_idx);
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23513
diff changeset
2353 clear_tv(tv_dest);
24488
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
2354 ectx->ec_stack.ga_len -= 2;
23517
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23513
diff changeset
2355 if (status == FAIL)
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23513
diff changeset
2356 goto on_error;
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23513
diff changeset
2357 }
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23513
diff changeset
2358 break;
36bf9a6fbd4c patch 8.2.2301: Vim9: cannot unlet a dict or list item
Bram Moolenaar <Bram@vim.org>
parents: 23513
diff changeset
2359
23982
9fcd71d0db89 patch 8.2.2533: Vim9: cannot use a range with :unlet
Bram Moolenaar <Bram@vim.org>
parents: 23976
diff changeset
2360 // unlet range of items in list variable
9fcd71d0db89 patch 8.2.2533: Vim9: cannot use a range with :unlet
Bram Moolenaar <Bram@vim.org>
parents: 23976
diff changeset
2361 case ISN_UNLETRANGE:
9fcd71d0db89 patch 8.2.2533: Vim9: cannot use a range with :unlet
Bram Moolenaar <Bram@vim.org>
parents: 23976
diff changeset
2362 {
9fcd71d0db89 patch 8.2.2533: Vim9: cannot use a range with :unlet
Bram Moolenaar <Bram@vim.org>
parents: 23976
diff changeset
2363 // Stack contains:
9fcd71d0db89 patch 8.2.2533: Vim9: cannot use a range with :unlet
Bram Moolenaar <Bram@vim.org>
parents: 23976
diff changeset
2364 // -3 index1
9fcd71d0db89 patch 8.2.2533: Vim9: cannot use a range with :unlet
Bram Moolenaar <Bram@vim.org>
parents: 23976
diff changeset
2365 // -2 index2
9fcd71d0db89 patch 8.2.2533: Vim9: cannot use a range with :unlet
Bram Moolenaar <Bram@vim.org>
parents: 23976
diff changeset
2366 // -1 dict or list
9fcd71d0db89 patch 8.2.2533: Vim9: cannot use a range with :unlet
Bram Moolenaar <Bram@vim.org>
parents: 23976
diff changeset
2367 typval_T *tv_idx1 = STACK_TV_BOT(-3);
9fcd71d0db89 patch 8.2.2533: Vim9: cannot use a range with :unlet
Bram Moolenaar <Bram@vim.org>
parents: 23976
diff changeset
2368 typval_T *tv_idx2 = STACK_TV_BOT(-2);
9fcd71d0db89 patch 8.2.2533: Vim9: cannot use a range with :unlet
Bram Moolenaar <Bram@vim.org>
parents: 23976
diff changeset
2369 typval_T *tv_dest = STACK_TV_BOT(-1);
9fcd71d0db89 patch 8.2.2533: Vim9: cannot use a range with :unlet
Bram Moolenaar <Bram@vim.org>
parents: 23976
diff changeset
2370 int status = OK;
9fcd71d0db89 patch 8.2.2533: Vim9: cannot use a range with :unlet
Bram Moolenaar <Bram@vim.org>
parents: 23976
diff changeset
2371
9fcd71d0db89 patch 8.2.2533: Vim9: cannot use a range with :unlet
Bram Moolenaar <Bram@vim.org>
parents: 23976
diff changeset
2372 if (tv_dest->v_type == VAR_LIST)
9fcd71d0db89 patch 8.2.2533: Vim9: cannot use a range with :unlet
Bram Moolenaar <Bram@vim.org>
parents: 23976
diff changeset
2373 {
9fcd71d0db89 patch 8.2.2533: Vim9: cannot use a range with :unlet
Bram Moolenaar <Bram@vim.org>
parents: 23976
diff changeset
2374 // indexes must be a number
9fcd71d0db89 patch 8.2.2533: Vim9: cannot use a range with :unlet
Bram Moolenaar <Bram@vim.org>
parents: 23976
diff changeset
2375 SOURCING_LNUM = iptr->isn_lnum;
9fcd71d0db89 patch 8.2.2533: Vim9: cannot use a range with :unlet
Bram Moolenaar <Bram@vim.org>
parents: 23976
diff changeset
2376 if (check_for_number(tv_idx1) == FAIL
9fcd71d0db89 patch 8.2.2533: Vim9: cannot use a range with :unlet
Bram Moolenaar <Bram@vim.org>
parents: 23976
diff changeset
2377 || check_for_number(tv_idx2) == FAIL)
9fcd71d0db89 patch 8.2.2533: Vim9: cannot use a range with :unlet
Bram Moolenaar <Bram@vim.org>
parents: 23976
diff changeset
2378 {
9fcd71d0db89 patch 8.2.2533: Vim9: cannot use a range with :unlet
Bram Moolenaar <Bram@vim.org>
parents: 23976
diff changeset
2379 status = FAIL;
9fcd71d0db89 patch 8.2.2533: Vim9: cannot use a range with :unlet
Bram Moolenaar <Bram@vim.org>
parents: 23976
diff changeset
2380 }
9fcd71d0db89 patch 8.2.2533: Vim9: cannot use a range with :unlet
Bram Moolenaar <Bram@vim.org>
parents: 23976
diff changeset
2381 else
9fcd71d0db89 patch 8.2.2533: Vim9: cannot use a range with :unlet
Bram Moolenaar <Bram@vim.org>
parents: 23976
diff changeset
2382 {
9fcd71d0db89 patch 8.2.2533: Vim9: cannot use a range with :unlet
Bram Moolenaar <Bram@vim.org>
parents: 23976
diff changeset
2383 list_T *l = tv_dest->vval.v_list;
9fcd71d0db89 patch 8.2.2533: Vim9: cannot use a range with :unlet
Bram Moolenaar <Bram@vim.org>
parents: 23976
diff changeset
2384 long n1 = (long)tv_idx1->vval.v_number;
9fcd71d0db89 patch 8.2.2533: Vim9: cannot use a range with :unlet
Bram Moolenaar <Bram@vim.org>
parents: 23976
diff changeset
2385 long n2 = (long)tv_idx2->vval.v_number;
9fcd71d0db89 patch 8.2.2533: Vim9: cannot use a range with :unlet
Bram Moolenaar <Bram@vim.org>
parents: 23976
diff changeset
2386 listitem_T *li;
9fcd71d0db89 patch 8.2.2533: Vim9: cannot use a range with :unlet
Bram Moolenaar <Bram@vim.org>
parents: 23976
diff changeset
2387
9fcd71d0db89 patch 8.2.2533: Vim9: cannot use a range with :unlet
Bram Moolenaar <Bram@vim.org>
parents: 23976
diff changeset
2388 li = list_find_index(l, &n1);
9fcd71d0db89 patch 8.2.2533: Vim9: cannot use a range with :unlet
Bram Moolenaar <Bram@vim.org>
parents: 23976
diff changeset
2389 if (li == NULL
9fcd71d0db89 patch 8.2.2533: Vim9: cannot use a range with :unlet
Bram Moolenaar <Bram@vim.org>
parents: 23976
diff changeset
2390 || list_unlet_range(l, li, NULL, n1,
9fcd71d0db89 patch 8.2.2533: Vim9: cannot use a range with :unlet
Bram Moolenaar <Bram@vim.org>
parents: 23976
diff changeset
2391 TRUE, n2) == FAIL)
9fcd71d0db89 patch 8.2.2533: Vim9: cannot use a range with :unlet
Bram Moolenaar <Bram@vim.org>
parents: 23976
diff changeset
2392 status = FAIL;
9fcd71d0db89 patch 8.2.2533: Vim9: cannot use a range with :unlet
Bram Moolenaar <Bram@vim.org>
parents: 23976
diff changeset
2393 }
9fcd71d0db89 patch 8.2.2533: Vim9: cannot use a range with :unlet
Bram Moolenaar <Bram@vim.org>
parents: 23976
diff changeset
2394 }
9fcd71d0db89 patch 8.2.2533: Vim9: cannot use a range with :unlet
Bram Moolenaar <Bram@vim.org>
parents: 23976
diff changeset
2395 else
9fcd71d0db89 patch 8.2.2533: Vim9: cannot use a range with :unlet
Bram Moolenaar <Bram@vim.org>
parents: 23976
diff changeset
2396 {
9fcd71d0db89 patch 8.2.2533: Vim9: cannot use a range with :unlet
Bram Moolenaar <Bram@vim.org>
parents: 23976
diff changeset
2397 status = FAIL;
9fcd71d0db89 patch 8.2.2533: Vim9: cannot use a range with :unlet
Bram Moolenaar <Bram@vim.org>
parents: 23976
diff changeset
2398 SOURCING_LNUM = iptr->isn_lnum;
9fcd71d0db89 patch 8.2.2533: Vim9: cannot use a range with :unlet
Bram Moolenaar <Bram@vim.org>
parents: 23976
diff changeset
2399 semsg(_(e_cannot_index_str),
9fcd71d0db89 patch 8.2.2533: Vim9: cannot use a range with :unlet
Bram Moolenaar <Bram@vim.org>
parents: 23976
diff changeset
2400 vartype_name(tv_dest->v_type));
9fcd71d0db89 patch 8.2.2533: Vim9: cannot use a range with :unlet
Bram Moolenaar <Bram@vim.org>
parents: 23976
diff changeset
2401 }
9fcd71d0db89 patch 8.2.2533: Vim9: cannot use a range with :unlet
Bram Moolenaar <Bram@vim.org>
parents: 23976
diff changeset
2402
9fcd71d0db89 patch 8.2.2533: Vim9: cannot use a range with :unlet
Bram Moolenaar <Bram@vim.org>
parents: 23976
diff changeset
2403 clear_tv(tv_idx1);
9fcd71d0db89 patch 8.2.2533: Vim9: cannot use a range with :unlet
Bram Moolenaar <Bram@vim.org>
parents: 23976
diff changeset
2404 clear_tv(tv_idx2);
9fcd71d0db89 patch 8.2.2533: Vim9: cannot use a range with :unlet
Bram Moolenaar <Bram@vim.org>
parents: 23976
diff changeset
2405 clear_tv(tv_dest);
24488
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
2406 ectx->ec_stack.ga_len -= 3;
23982
9fcd71d0db89 patch 8.2.2533: Vim9: cannot use a range with :unlet
Bram Moolenaar <Bram@vim.org>
parents: 23976
diff changeset
2407 if (status == FAIL)
9fcd71d0db89 patch 8.2.2533: Vim9: cannot use a range with :unlet
Bram Moolenaar <Bram@vim.org>
parents: 23976
diff changeset
2408 goto on_error;
9fcd71d0db89 patch 8.2.2533: Vim9: cannot use a range with :unlet
Bram Moolenaar <Bram@vim.org>
parents: 23976
diff changeset
2409 }
9fcd71d0db89 patch 8.2.2533: Vim9: cannot use a range with :unlet
Bram Moolenaar <Bram@vim.org>
parents: 23976
diff changeset
2410 break;
9fcd71d0db89 patch 8.2.2533: Vim9: cannot use a range with :unlet
Bram Moolenaar <Bram@vim.org>
parents: 23976
diff changeset
2411
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2412 // push constant
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2413 case ISN_PUSHNR:
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2414 case ISN_PUSHBOOL:
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2415 case ISN_PUSHSPEC:
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2416 case ISN_PUSHF:
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2417 case ISN_PUSHS:
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2418 case ISN_PUSHBLOB:
19558
8eeec8886c02 patch 8.2.0336: Vim9: insufficient test coverage for compiling
Bram Moolenaar <Bram@vim.org>
parents: 19538
diff changeset
2419 case ISN_PUSHFUNC:
8eeec8886c02 patch 8.2.0336: Vim9: insufficient test coverage for compiling
Bram Moolenaar <Bram@vim.org>
parents: 19538
diff changeset
2420 case ISN_PUSHCHANNEL:
8eeec8886c02 patch 8.2.0336: Vim9: insufficient test coverage for compiling
Bram Moolenaar <Bram@vim.org>
parents: 19538
diff changeset
2421 case ISN_PUSHJOB:
24488
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
2422 if (GA_GROW(&ectx->ec_stack, 1) == FAIL)
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
2423 return FAIL;
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2424 tv = STACK_TV_BOT(0);
21399
5cb6e676defd patch 8.2.1250: Vim9: cannot use the g:, b:, t: and w: namespaces
Bram Moolenaar <Bram@vim.org>
parents: 21393
diff changeset
2425 tv->v_lock = 0;
24488
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
2426 ++ectx->ec_stack.ga_len;
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2427 switch (iptr->isn_type)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2428 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2429 case ISN_PUSHNR:
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2430 tv->v_type = VAR_NUMBER;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2431 tv->vval.v_number = iptr->isn_arg.number;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2432 break;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2433 case ISN_PUSHBOOL:
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2434 tv->v_type = VAR_BOOL;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2435 tv->vval.v_number = iptr->isn_arg.number;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2436 break;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2437 case ISN_PUSHSPEC:
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2438 tv->v_type = VAR_SPECIAL;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2439 tv->vval.v_number = iptr->isn_arg.number;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2440 break;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2441 #ifdef FEAT_FLOAT
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2442 case ISN_PUSHF:
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2443 tv->v_type = VAR_FLOAT;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2444 tv->vval.v_float = iptr->isn_arg.fnumber;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2445 break;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2446 #endif
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2447 case ISN_PUSHBLOB:
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2448 blob_copy(iptr->isn_arg.blob, tv);
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2449 break;
19558
8eeec8886c02 patch 8.2.0336: Vim9: insufficient test coverage for compiling
Bram Moolenaar <Bram@vim.org>
parents: 19538
diff changeset
2450 case ISN_PUSHFUNC:
8eeec8886c02 patch 8.2.0336: Vim9: insufficient test coverage for compiling
Bram Moolenaar <Bram@vim.org>
parents: 19538
diff changeset
2451 tv->v_type = VAR_FUNC;
19566
ec1eeb1b69e2 patch 8.2.0340: Vim9: function and partial types not tested
Bram Moolenaar <Bram@vim.org>
parents: 19558
diff changeset
2452 if (iptr->isn_arg.string == NULL)
ec1eeb1b69e2 patch 8.2.0340: Vim9: function and partial types not tested
Bram Moolenaar <Bram@vim.org>
parents: 19558
diff changeset
2453 tv->vval.v_string = NULL;
ec1eeb1b69e2 patch 8.2.0340: Vim9: function and partial types not tested
Bram Moolenaar <Bram@vim.org>
parents: 19558
diff changeset
2454 else
ec1eeb1b69e2 patch 8.2.0340: Vim9: function and partial types not tested
Bram Moolenaar <Bram@vim.org>
parents: 19558
diff changeset
2455 tv->vval.v_string =
ec1eeb1b69e2 patch 8.2.0340: Vim9: function and partial types not tested
Bram Moolenaar <Bram@vim.org>
parents: 19558
diff changeset
2456 vim_strsave(iptr->isn_arg.string);
19558
8eeec8886c02 patch 8.2.0336: Vim9: insufficient test coverage for compiling
Bram Moolenaar <Bram@vim.org>
parents: 19538
diff changeset
2457 break;
8eeec8886c02 patch 8.2.0336: Vim9: insufficient test coverage for compiling
Bram Moolenaar <Bram@vim.org>
parents: 19538
diff changeset
2458 case ISN_PUSHCHANNEL:
8eeec8886c02 patch 8.2.0336: Vim9: insufficient test coverage for compiling
Bram Moolenaar <Bram@vim.org>
parents: 19538
diff changeset
2459 #ifdef FEAT_JOB_CHANNEL
8eeec8886c02 patch 8.2.0336: Vim9: insufficient test coverage for compiling
Bram Moolenaar <Bram@vim.org>
parents: 19538
diff changeset
2460 tv->v_type = VAR_CHANNEL;
8eeec8886c02 patch 8.2.0336: Vim9: insufficient test coverage for compiling
Bram Moolenaar <Bram@vim.org>
parents: 19538
diff changeset
2461 tv->vval.v_channel = iptr->isn_arg.channel;
8eeec8886c02 patch 8.2.0336: Vim9: insufficient test coverage for compiling
Bram Moolenaar <Bram@vim.org>
parents: 19538
diff changeset
2462 if (tv->vval.v_channel != NULL)
8eeec8886c02 patch 8.2.0336: Vim9: insufficient test coverage for compiling
Bram Moolenaar <Bram@vim.org>
parents: 19538
diff changeset
2463 ++tv->vval.v_channel->ch_refcount;
8eeec8886c02 patch 8.2.0336: Vim9: insufficient test coverage for compiling
Bram Moolenaar <Bram@vim.org>
parents: 19538
diff changeset
2464 #endif
8eeec8886c02 patch 8.2.0336: Vim9: insufficient test coverage for compiling
Bram Moolenaar <Bram@vim.org>
parents: 19538
diff changeset
2465 break;
8eeec8886c02 patch 8.2.0336: Vim9: insufficient test coverage for compiling
Bram Moolenaar <Bram@vim.org>
parents: 19538
diff changeset
2466 case ISN_PUSHJOB:
8eeec8886c02 patch 8.2.0336: Vim9: insufficient test coverage for compiling
Bram Moolenaar <Bram@vim.org>
parents: 19538
diff changeset
2467 #ifdef FEAT_JOB_CHANNEL
8eeec8886c02 patch 8.2.0336: Vim9: insufficient test coverage for compiling
Bram Moolenaar <Bram@vim.org>
parents: 19538
diff changeset
2468 tv->v_type = VAR_JOB;
8eeec8886c02 patch 8.2.0336: Vim9: insufficient test coverage for compiling
Bram Moolenaar <Bram@vim.org>
parents: 19538
diff changeset
2469 tv->vval.v_job = iptr->isn_arg.job;
8eeec8886c02 patch 8.2.0336: Vim9: insufficient test coverage for compiling
Bram Moolenaar <Bram@vim.org>
parents: 19538
diff changeset
2470 if (tv->vval.v_job != NULL)
8eeec8886c02 patch 8.2.0336: Vim9: insufficient test coverage for compiling
Bram Moolenaar <Bram@vim.org>
parents: 19538
diff changeset
2471 ++tv->vval.v_job->jv_refcount;
8eeec8886c02 patch 8.2.0336: Vim9: insufficient test coverage for compiling
Bram Moolenaar <Bram@vim.org>
parents: 19538
diff changeset
2472 #endif
8eeec8886c02 patch 8.2.0336: Vim9: insufficient test coverage for compiling
Bram Moolenaar <Bram@vim.org>
parents: 19538
diff changeset
2473 break;
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2474 default:
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2475 tv->v_type = VAR_STRING;
19874
f92435f0f449 patch 8.2.0493: Vim9: some error messages not tested
Bram Moolenaar <Bram@vim.org>
parents: 19872
diff changeset
2476 tv->vval.v_string = vim_strsave(
f92435f0f449 patch 8.2.0493: Vim9: some error messages not tested
Bram Moolenaar <Bram@vim.org>
parents: 19872
diff changeset
2477 iptr->isn_arg.string == NULL
f92435f0f449 patch 8.2.0493: Vim9: some error messages not tested
Bram Moolenaar <Bram@vim.org>
parents: 19872
diff changeset
2478 ? (char_u *)"" : iptr->isn_arg.string);
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2479 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2480 break;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2481
20091
a64c16ff98b8 patch 8.2.0601: Vim9: :unlet is not compiled
Bram Moolenaar <Bram@vim.org>
parents: 20089
diff changeset
2482 case ISN_UNLET:
a64c16ff98b8 patch 8.2.0601: Vim9: :unlet is not compiled
Bram Moolenaar <Bram@vim.org>
parents: 20089
diff changeset
2483 if (do_unlet(iptr->isn_arg.unlet.ul_name,
a64c16ff98b8 patch 8.2.0601: Vim9: :unlet is not compiled
Bram Moolenaar <Bram@vim.org>
parents: 20089
diff changeset
2484 iptr->isn_arg.unlet.ul_forceit) == FAIL)
21371
8e1081ede3b8 patch 8.2.1236: Vim9: a few errors not caught by try/catch
Bram Moolenaar <Bram@vim.org>
parents: 21365
diff changeset
2485 goto on_error;
20091
a64c16ff98b8 patch 8.2.0601: Vim9: :unlet is not compiled
Bram Moolenaar <Bram@vim.org>
parents: 20089
diff changeset
2486 break;
20099
058b41f85bcb patch 8.2.0605: Vim9: cannot unlet an environment variable
Bram Moolenaar <Bram@vim.org>
parents: 20091
diff changeset
2487 case ISN_UNLETENV:
058b41f85bcb patch 8.2.0605: Vim9: cannot unlet an environment variable
Bram Moolenaar <Bram@vim.org>
parents: 20091
diff changeset
2488 vim_unsetenv(iptr->isn_arg.unlet.ul_name);
058b41f85bcb patch 8.2.0605: Vim9: cannot unlet an environment variable
Bram Moolenaar <Bram@vim.org>
parents: 20091
diff changeset
2489 break;
20091
a64c16ff98b8 patch 8.2.0601: Vim9: :unlet is not compiled
Bram Moolenaar <Bram@vim.org>
parents: 20089
diff changeset
2490
22272
eb1f5f618c75 patch 8.2.1685: Vim9: cannot declare a constant value
Bram Moolenaar <Bram@vim.org>
parents: 22262
diff changeset
2491 case ISN_LOCKCONST:
eb1f5f618c75 patch 8.2.1685: Vim9: cannot declare a constant value
Bram Moolenaar <Bram@vim.org>
parents: 22262
diff changeset
2492 item_lock(STACK_TV_BOT(-1), 100, TRUE, TRUE);
eb1f5f618c75 patch 8.2.1685: Vim9: cannot declare a constant value
Bram Moolenaar <Bram@vim.org>
parents: 22262
diff changeset
2493 break;
eb1f5f618c75 patch 8.2.1685: Vim9: cannot declare a constant value
Bram Moolenaar <Bram@vim.org>
parents: 22262
diff changeset
2494
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2495 // create a list from items on the stack; uses a single allocation
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2496 // for the list header and the items
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2497 case ISN_NEWLIST:
24488
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
2498 if (exe_newlist(iptr->isn_arg.number, ectx) == FAIL)
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
2499 return FAIL;
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2500 break;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2501
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2502 // create a dict from items on the stack
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2503 case ISN_NEWDICT:
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2504 {
21371
8e1081ede3b8 patch 8.2.1236: Vim9: a few errors not caught by try/catch
Bram Moolenaar <Bram@vim.org>
parents: 21365
diff changeset
2505 int count = iptr->isn_arg.number;
8e1081ede3b8 patch 8.2.1236: Vim9: a few errors not caught by try/catch
Bram Moolenaar <Bram@vim.org>
parents: 21365
diff changeset
2506 dict_T *dict = dict_alloc();
8e1081ede3b8 patch 8.2.1236: Vim9: a few errors not caught by try/catch
Bram Moolenaar <Bram@vim.org>
parents: 21365
diff changeset
2507 dictitem_T *item;
22808
96dbb61a54c2 patch 8.2.1952: Vim9: crash when using a NULL dict key
Bram Moolenaar <Bram@vim.org>
parents: 22760
diff changeset
2508 char_u *key;
24488
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
2509 int idx;
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2510
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2511 if (dict == NULL)
24488
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
2512 return FAIL;
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2513 for (idx = 0; idx < count; ++idx)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2514 {
21371
8e1081ede3b8 patch 8.2.1236: Vim9: a few errors not caught by try/catch
Bram Moolenaar <Bram@vim.org>
parents: 21365
diff changeset
2515 // have already checked key type is VAR_STRING
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2516 tv = STACK_TV_BOT(2 * (idx - count));
21371
8e1081ede3b8 patch 8.2.1236: Vim9: a few errors not caught by try/catch
Bram Moolenaar <Bram@vim.org>
parents: 21365
diff changeset
2517 // check key is unique
22808
96dbb61a54c2 patch 8.2.1952: Vim9: crash when using a NULL dict key
Bram Moolenaar <Bram@vim.org>
parents: 22760
diff changeset
2518 key = tv->vval.v_string == NULL
96dbb61a54c2 patch 8.2.1952: Vim9: crash when using a NULL dict key
Bram Moolenaar <Bram@vim.org>
parents: 22760
diff changeset
2519 ? (char_u *)"" : tv->vval.v_string;
96dbb61a54c2 patch 8.2.1952: Vim9: crash when using a NULL dict key
Bram Moolenaar <Bram@vim.org>
parents: 22760
diff changeset
2520 item = dict_find(dict, key, -1);
21371
8e1081ede3b8 patch 8.2.1236: Vim9: a few errors not caught by try/catch
Bram Moolenaar <Bram@vim.org>
parents: 21365
diff changeset
2521 if (item != NULL)
8e1081ede3b8 patch 8.2.1236: Vim9: a few errors not caught by try/catch
Bram Moolenaar <Bram@vim.org>
parents: 21365
diff changeset
2522 {
21793
0706bd071fa3 patch 8.2.1446: Vim9: line number in error message is not correct
Bram Moolenaar <Bram@vim.org>
parents: 21789
diff changeset
2523 SOURCING_LNUM = iptr->isn_lnum;
22808
96dbb61a54c2 patch 8.2.1952: Vim9: crash when using a NULL dict key
Bram Moolenaar <Bram@vim.org>
parents: 22760
diff changeset
2524 semsg(_(e_duplicate_key), key);
21371
8e1081ede3b8 patch 8.2.1236: Vim9: a few errors not caught by try/catch
Bram Moolenaar <Bram@vim.org>
parents: 21365
diff changeset
2525 dict_unref(dict);
8e1081ede3b8 patch 8.2.1236: Vim9: a few errors not caught by try/catch
Bram Moolenaar <Bram@vim.org>
parents: 21365
diff changeset
2526 goto on_error;
8e1081ede3b8 patch 8.2.1236: Vim9: a few errors not caught by try/catch
Bram Moolenaar <Bram@vim.org>
parents: 21365
diff changeset
2527 }
22808
96dbb61a54c2 patch 8.2.1952: Vim9: crash when using a NULL dict key
Bram Moolenaar <Bram@vim.org>
parents: 22760
diff changeset
2528 item = dictitem_alloc(key);
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2529 clear_tv(tv);
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2530 if (item == NULL)
21371
8e1081ede3b8 patch 8.2.1236: Vim9: a few errors not caught by try/catch
Bram Moolenaar <Bram@vim.org>
parents: 21365
diff changeset
2531 {
8e1081ede3b8 patch 8.2.1236: Vim9: a few errors not caught by try/catch
Bram Moolenaar <Bram@vim.org>
parents: 21365
diff changeset
2532 dict_unref(dict);
24488
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
2533 return FAIL;
21371
8e1081ede3b8 patch 8.2.1236: Vim9: a few errors not caught by try/catch
Bram Moolenaar <Bram@vim.org>
parents: 21365
diff changeset
2534 }
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2535 item->di_tv = *STACK_TV_BOT(2 * (idx - count) + 1);
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2536 item->di_tv.v_lock = 0;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2537 if (dict_add(dict, item) == FAIL)
21371
8e1081ede3b8 patch 8.2.1236: Vim9: a few errors not caught by try/catch
Bram Moolenaar <Bram@vim.org>
parents: 21365
diff changeset
2538 {
21375
92e2ed2a2778 patch 8.2.1238: Vim9: a few remaining errors not caught by try/catch
Bram Moolenaar <Bram@vim.org>
parents: 21371
diff changeset
2539 // can this ever happen?
21371
8e1081ede3b8 patch 8.2.1236: Vim9: a few errors not caught by try/catch
Bram Moolenaar <Bram@vim.org>
parents: 21365
diff changeset
2540 dict_unref(dict);
24488
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
2541 return FAIL;
21371
8e1081ede3b8 patch 8.2.1236: Vim9: a few errors not caught by try/catch
Bram Moolenaar <Bram@vim.org>
parents: 21365
diff changeset
2542 }
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2543 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2544
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2545 if (count > 0)
24488
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
2546 ectx->ec_stack.ga_len -= 2 * count - 1;
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
2547 else if (GA_GROW(&ectx->ec_stack, 1) == FAIL)
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
2548 return FAIL;
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2549 else
24488
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
2550 ++ectx->ec_stack.ga_len;
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2551 tv = STACK_TV_BOT(-1);
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2552 tv->v_type = VAR_DICT;
21399
5cb6e676defd patch 8.2.1250: Vim9: cannot use the g:, b:, t: and w: namespaces
Bram Moolenaar <Bram@vim.org>
parents: 21393
diff changeset
2553 tv->v_lock = 0;
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2554 tv->vval.v_dict = dict;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2555 ++dict->dv_refcount;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2556 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2557 break;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2558
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2559 // call a :def function
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2560 case ISN_DCALL:
22214
efa1511a5bf3 patch 8.2.1656: Vim9: callstack wrong if :def function calls :def function
Bram Moolenaar <Bram@vim.org>
parents: 22176
diff changeset
2561 SOURCING_LNUM = iptr->isn_lnum;
24218
40e27d96e395 patch 8.2.2650: Vim9: command modifiers not handled in nested function
Bram Moolenaar <Bram@vim.org>
parents: 24146
diff changeset
2562 if (call_dfunc(iptr->isn_arg.dfunc.cdf_idx,
40e27d96e395 patch 8.2.2650: Vim9: command modifiers not handled in nested function
Bram Moolenaar <Bram@vim.org>
parents: 24146
diff changeset
2563 NULL,
40e27d96e395 patch 8.2.2650: Vim9: command modifiers not handled in nested function
Bram Moolenaar <Bram@vim.org>
parents: 24146
diff changeset
2564 iptr->isn_arg.dfunc.cdf_argcount,
24488
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
2565 ectx) == FAIL)
21371
8e1081ede3b8 patch 8.2.1236: Vim9: a few errors not caught by try/catch
Bram Moolenaar <Bram@vim.org>
parents: 21365
diff changeset
2566 goto on_error;
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2567 break;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2568
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2569 // call a builtin function
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2570 case ISN_BCALL:
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2571 SOURCING_LNUM = iptr->isn_lnum;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2572 if (call_bfunc(iptr->isn_arg.bfunc.cbf_idx,
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2573 iptr->isn_arg.bfunc.cbf_argcount,
24488
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
2574 ectx) == FAIL)
21375
92e2ed2a2778 patch 8.2.1238: Vim9: a few remaining errors not caught by try/catch
Bram Moolenaar <Bram@vim.org>
parents: 21371
diff changeset
2575 goto on_error;
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2576 break;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2577
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2578 // call a funcref or partial
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2579 case ISN_PCALL:
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2580 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2581 cpfunc_T *pfunc = &iptr->isn_arg.pfunc;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2582 int r;
20433
5950284a517f patch 8.2.0771: Vim9: cannot call a compiled closure from not compiled code
Bram Moolenaar <Bram@vim.org>
parents: 20427
diff changeset
2583 typval_T partial_tv;
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2584
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2585 SOURCING_LNUM = iptr->isn_lnum;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2586 if (pfunc->cpf_top)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2587 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2588 // funcref is above the arguments
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2589 tv = STACK_TV_BOT(-pfunc->cpf_argcount - 1);
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2590 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2591 else
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2592 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2593 // Get the funcref from the stack.
24488
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
2594 --ectx->ec_stack.ga_len;
20433
5950284a517f patch 8.2.0771: Vim9: cannot call a compiled closure from not compiled code
Bram Moolenaar <Bram@vim.org>
parents: 20427
diff changeset
2595 partial_tv = *STACK_TV_BOT(0);
5950284a517f patch 8.2.0771: Vim9: cannot call a compiled closure from not compiled code
Bram Moolenaar <Bram@vim.org>
parents: 20427
diff changeset
2596 tv = &partial_tv;
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2597 }
24488
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
2598 r = call_partial(tv, pfunc->cpf_argcount, ectx);
20433
5950284a517f patch 8.2.0771: Vim9: cannot call a compiled closure from not compiled code
Bram Moolenaar <Bram@vim.org>
parents: 20427
diff changeset
2599 if (tv == &partial_tv)
5950284a517f patch 8.2.0771: Vim9: cannot call a compiled closure from not compiled code
Bram Moolenaar <Bram@vim.org>
parents: 20427
diff changeset
2600 clear_tv(&partial_tv);
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2601 if (r == FAIL)
21375
92e2ed2a2778 patch 8.2.1238: Vim9: a few remaining errors not caught by try/catch
Bram Moolenaar <Bram@vim.org>
parents: 21371
diff changeset
2602 goto on_error;
19862
846fbbacce3a patch 8.2.0487: Vim9: compiling not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19842
diff changeset
2603 }
846fbbacce3a patch 8.2.0487: Vim9: compiling not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19842
diff changeset
2604 break;
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2605
19862
846fbbacce3a patch 8.2.0487: Vim9: compiling not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19842
diff changeset
2606 case ISN_PCALL_END:
846fbbacce3a patch 8.2.0487: Vim9: compiling not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19842
diff changeset
2607 // PCALL finished, arguments have been consumed and replaced by
846fbbacce3a patch 8.2.0487: Vim9: compiling not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19842
diff changeset
2608 // the return value. Now clear the funcref from the stack,
846fbbacce3a patch 8.2.0487: Vim9: compiling not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19842
diff changeset
2609 // and move the return value in its place.
24488
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
2610 --ectx->ec_stack.ga_len;
19862
846fbbacce3a patch 8.2.0487: Vim9: compiling not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19842
diff changeset
2611 clear_tv(STACK_TV_BOT(-1));
846fbbacce3a patch 8.2.0487: Vim9: compiling not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19842
diff changeset
2612 *STACK_TV_BOT(-1) = *STACK_TV_BOT(0);
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2613 break;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2614
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2615 // call a user defined function or funcref/partial
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2616 case ISN_UCALL:
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2617 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2618 cufunc_T *cufunc = &iptr->isn_arg.ufunc;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2619
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2620 SOURCING_LNUM = iptr->isn_lnum;
24218
40e27d96e395 patch 8.2.2650: Vim9: command modifiers not handled in nested function
Bram Moolenaar <Bram@vim.org>
parents: 24146
diff changeset
2621 if (call_eval_func(cufunc->cuf_name, cufunc->cuf_argcount,
24488
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
2622 ectx, iptr) == FAIL)
21375
92e2ed2a2778 patch 8.2.1238: Vim9: a few remaining errors not caught by try/catch
Bram Moolenaar <Bram@vim.org>
parents: 21371
diff changeset
2623 goto on_error;
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2624 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2625 break;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2626
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2627 // return from a :def function call
23543
f90e429453fd patch 8.2.2314: Vim9: returning zero takes two instructions
Bram Moolenaar <Bram@vim.org>
parents: 23541
diff changeset
2628 case ISN_RETURN_ZERO:
24488
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
2629 if (GA_GROW(&ectx->ec_stack, 1) == FAIL)
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
2630 return FAIL;
23543
f90e429453fd patch 8.2.2314: Vim9: returning zero takes two instructions
Bram Moolenaar <Bram@vim.org>
parents: 23541
diff changeset
2631 tv = STACK_TV_BOT(0);
24488
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
2632 ++ectx->ec_stack.ga_len;
23543
f90e429453fd patch 8.2.2314: Vim9: returning zero takes two instructions
Bram Moolenaar <Bram@vim.org>
parents: 23541
diff changeset
2633 tv->v_type = VAR_NUMBER;
f90e429453fd patch 8.2.2314: Vim9: returning zero takes two instructions
Bram Moolenaar <Bram@vim.org>
parents: 23541
diff changeset
2634 tv->vval.v_number = 0;
f90e429453fd patch 8.2.2314: Vim9: returning zero takes two instructions
Bram Moolenaar <Bram@vim.org>
parents: 23541
diff changeset
2635 tv->v_lock = 0;
f90e429453fd patch 8.2.2314: Vim9: returning zero takes two instructions
Bram Moolenaar <Bram@vim.org>
parents: 23541
diff changeset
2636 // FALLTHROUGH
f90e429453fd patch 8.2.2314: Vim9: returning zero takes two instructions
Bram Moolenaar <Bram@vim.org>
parents: 23541
diff changeset
2637
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2638 case ISN_RETURN:
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2639 {
24488
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
2640 garray_T *trystack = &ectx->ec_trystack;
19726
ad37a198a708 patch 8.2.0419: various memory leaks in Vim9 script code
Bram Moolenaar <Bram@vim.org>
parents: 19635
diff changeset
2641 trycmd_T *trycmd = NULL;
19221
f63f3b423ad3 patch 8.2.0169: Coverity warning for dead code
Bram Moolenaar <Bram@vim.org>
parents: 19219
diff changeset
2642
f63f3b423ad3 patch 8.2.0169: Coverity warning for dead code
Bram Moolenaar <Bram@vim.org>
parents: 19219
diff changeset
2643 if (trystack->ga_len > 0)
f63f3b423ad3 patch 8.2.0169: Coverity warning for dead code
Bram Moolenaar <Bram@vim.org>
parents: 19219
diff changeset
2644 trycmd = ((trycmd_T *)trystack->ga_data)
f63f3b423ad3 patch 8.2.0169: Coverity warning for dead code
Bram Moolenaar <Bram@vim.org>
parents: 19219
diff changeset
2645 + trystack->ga_len - 1;
20247
e46e72aaff74 patch 8.2.0679: Vim9: incomplete support for closures
Bram Moolenaar <Bram@vim.org>
parents: 20244
diff changeset
2646 if (trycmd != NULL
24488
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
2647 && trycmd->tcd_frame_idx == ectx->ec_frame_idx)
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2648 {
24002
5dbed4837ea3 patch 8.2.2543: Vim9: a return inside try/catch does not restore properly
Bram Moolenaar <Bram@vim.org>
parents: 23994
diff changeset
2649 // jump to ":finally" or ":endtry"
5dbed4837ea3 patch 8.2.2543: Vim9: a return inside try/catch does not restore properly
Bram Moolenaar <Bram@vim.org>
parents: 23994
diff changeset
2650 if (trycmd->tcd_finally_idx != 0)
24488
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
2651 ectx->ec_iidx = trycmd->tcd_finally_idx;
24002
5dbed4837ea3 patch 8.2.2543: Vim9: a return inside try/catch does not restore properly
Bram Moolenaar <Bram@vim.org>
parents: 23994
diff changeset
2652 else
24488
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
2653 ectx->ec_iidx = trycmd->tcd_endtry_idx;
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2654 trycmd->tcd_return = TRUE;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2655 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2656 else
21375
92e2ed2a2778 patch 8.2.1238: Vim9: a few remaining errors not caught by try/catch
Bram Moolenaar <Bram@vim.org>
parents: 21371
diff changeset
2657 goto func_return;
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2658 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2659 break;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2660
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2661 // push a function reference to a compiled function
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2662 case ISN_FUNCREF:
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2663 {
23249
43532077b5ff patch 8.2.2170: Vim9: a global function defined in a :def function fails
Bram Moolenaar <Bram@vim.org>
parents: 23233
diff changeset
2664 partial_T *pt = ALLOC_CLEAR_ONE(partial_T);
43532077b5ff patch 8.2.2170: Vim9: a global function defined in a :def function fails
Bram Moolenaar <Bram@vim.org>
parents: 23233
diff changeset
2665 dfunc_T *pt_dfunc = ((dfunc_T *)def_functions.ga_data)
43532077b5ff patch 8.2.2170: Vim9: a global function defined in a :def function fails
Bram Moolenaar <Bram@vim.org>
parents: 23233
diff changeset
2666 + iptr->isn_arg.funcref.fr_func;
43532077b5ff patch 8.2.2170: Vim9: a global function defined in a :def function fails
Bram Moolenaar <Bram@vim.org>
parents: 23233
diff changeset
2667
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2668 if (pt == NULL)
24488
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
2669 return FAIL;
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
2670 if (GA_GROW(&ectx->ec_stack, 1) == FAIL)
20247
e46e72aaff74 patch 8.2.0679: Vim9: incomplete support for closures
Bram Moolenaar <Bram@vim.org>
parents: 20244
diff changeset
2671 {
e46e72aaff74 patch 8.2.0679: Vim9: incomplete support for closures
Bram Moolenaar <Bram@vim.org>
parents: 20244
diff changeset
2672 vim_free(pt);
24488
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
2673 return FAIL;
20247
e46e72aaff74 patch 8.2.0679: Vim9: incomplete support for closures
Bram Moolenaar <Bram@vim.org>
parents: 20244
diff changeset
2674 }
23249
43532077b5ff patch 8.2.2170: Vim9: a global function defined in a :def function fails
Bram Moolenaar <Bram@vim.org>
parents: 23233
diff changeset
2675 if (fill_partial_and_closure(pt, pt_dfunc->df_ufunc,
24488
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
2676 ectx) == FAIL)
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
2677 return FAIL;
20244
23d75968ca5e patch 8.2.0677: Vim9: no support for closures
Bram Moolenaar <Bram@vim.org>
parents: 20225
diff changeset
2678
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2679 tv = STACK_TV_BOT(0);
24488
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
2680 ++ectx->ec_stack.ga_len;
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2681 tv->vval.v_partial = pt;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2682 tv->v_type = VAR_PARTIAL;
21399
5cb6e676defd patch 8.2.1250: Vim9: cannot use the g:, b:, t: and w: namespaces
Bram Moolenaar <Bram@vim.org>
parents: 21393
diff changeset
2683 tv->v_lock = 0;
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2684 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2685 break;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2686
21558
1c4d4aa22b37 patch 8.2.1329: Vim9: cannot define global function inside :def function
Bram Moolenaar <Bram@vim.org>
parents: 21481
diff changeset
2687 // Create a global function from a lambda.
1c4d4aa22b37 patch 8.2.1329: Vim9: cannot define global function inside :def function
Bram Moolenaar <Bram@vim.org>
parents: 21481
diff changeset
2688 case ISN_NEWFUNC:
1c4d4aa22b37 patch 8.2.1329: Vim9: cannot define global function inside :def function
Bram Moolenaar <Bram@vim.org>
parents: 21481
diff changeset
2689 {
1c4d4aa22b37 patch 8.2.1329: Vim9: cannot define global function inside :def function
Bram Moolenaar <Bram@vim.org>
parents: 21481
diff changeset
2690 newfunc_T *newfunc = &iptr->isn_arg.newfunc;
23285
112fa621b127 patch 8.2.2188: Vim9: crash when calling global function from :def function
Bram Moolenaar <Bram@vim.org>
parents: 23266
diff changeset
2691
112fa621b127 patch 8.2.2188: Vim9: crash when calling global function from :def function
Bram Moolenaar <Bram@vim.org>
parents: 23266
diff changeset
2692 if (copy_func(newfunc->nf_lambda, newfunc->nf_global,
24488
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
2693 ectx) == FAIL)
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
2694 return FAIL;
21558
1c4d4aa22b37 patch 8.2.1329: Vim9: cannot define global function inside :def function
Bram Moolenaar <Bram@vim.org>
parents: 21481
diff changeset
2695 }
1c4d4aa22b37 patch 8.2.1329: Vim9: cannot define global function inside :def function
Bram Moolenaar <Bram@vim.org>
parents: 21481
diff changeset
2696 break;
1c4d4aa22b37 patch 8.2.1329: Vim9: cannot define global function inside :def function
Bram Moolenaar <Bram@vim.org>
parents: 21481
diff changeset
2697
22973
4c97c0747017 patch 8.2.2033: Vim9: :def without argument gives compilation error
Bram Moolenaar <Bram@vim.org>
parents: 22952
diff changeset
2698 // List functions
4c97c0747017 patch 8.2.2033: Vim9: :def without argument gives compilation error
Bram Moolenaar <Bram@vim.org>
parents: 22952
diff changeset
2699 case ISN_DEF:
4c97c0747017 patch 8.2.2033: Vim9: :def without argument gives compilation error
Bram Moolenaar <Bram@vim.org>
parents: 22952
diff changeset
2700 if (iptr->isn_arg.string == NULL)
4c97c0747017 patch 8.2.2033: Vim9: :def without argument gives compilation error
Bram Moolenaar <Bram@vim.org>
parents: 22952
diff changeset
2701 list_functions(NULL);
4c97c0747017 patch 8.2.2033: Vim9: :def without argument gives compilation error
Bram Moolenaar <Bram@vim.org>
parents: 22952
diff changeset
2702 else
4c97c0747017 patch 8.2.2033: Vim9: :def without argument gives compilation error
Bram Moolenaar <Bram@vim.org>
parents: 22952
diff changeset
2703 {
4c97c0747017 patch 8.2.2033: Vim9: :def without argument gives compilation error
Bram Moolenaar <Bram@vim.org>
parents: 22952
diff changeset
2704 exarg_T ea;
4c97c0747017 patch 8.2.2033: Vim9: :def without argument gives compilation error
Bram Moolenaar <Bram@vim.org>
parents: 22952
diff changeset
2705
4c97c0747017 patch 8.2.2033: Vim9: :def without argument gives compilation error
Bram Moolenaar <Bram@vim.org>
parents: 22952
diff changeset
2706 CLEAR_FIELD(ea);
4c97c0747017 patch 8.2.2033: Vim9: :def without argument gives compilation error
Bram Moolenaar <Bram@vim.org>
parents: 22952
diff changeset
2707 ea.cmd = ea.arg = iptr->isn_arg.string;
4c97c0747017 patch 8.2.2033: Vim9: :def without argument gives compilation error
Bram Moolenaar <Bram@vim.org>
parents: 22952
diff changeset
2708 define_function(&ea, NULL);
4c97c0747017 patch 8.2.2033: Vim9: :def without argument gives compilation error
Bram Moolenaar <Bram@vim.org>
parents: 22952
diff changeset
2709 }
4c97c0747017 patch 8.2.2033: Vim9: :def without argument gives compilation error
Bram Moolenaar <Bram@vim.org>
parents: 22952
diff changeset
2710 break;
4c97c0747017 patch 8.2.2033: Vim9: :def without argument gives compilation error
Bram Moolenaar <Bram@vim.org>
parents: 22952
diff changeset
2711
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2712 // jump if a condition is met
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2713 case ISN_JUMP:
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2714 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2715 jumpwhen_T when = iptr->isn_arg.jump.jump_when;
22494
4c21f7f6f9e3 patch 8.2.1795: Vim9: operators && and || have a confusing result
Bram Moolenaar <Bram@vim.org>
parents: 22460
diff changeset
2716 int error = FALSE;
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2717 int jump = TRUE;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2718
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2719 if (when != JUMP_ALWAYS)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2720 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2721 tv = STACK_TV_BOT(-1);
22494
4c21f7f6f9e3 patch 8.2.1795: Vim9: operators && and || have a confusing result
Bram Moolenaar <Bram@vim.org>
parents: 22460
diff changeset
2722 if (when == JUMP_IF_COND_FALSE
22500
ef8a3177edc1 patch 8.2.1798: Vim9: trinary operator condition is too permissive
Bram Moolenaar <Bram@vim.org>
parents: 22494
diff changeset
2723 || when == JUMP_IF_FALSE
22494
4c21f7f6f9e3 patch 8.2.1795: Vim9: operators && and || have a confusing result
Bram Moolenaar <Bram@vim.org>
parents: 22460
diff changeset
2724 || when == JUMP_IF_COND_TRUE)
4c21f7f6f9e3 patch 8.2.1795: Vim9: operators && and || have a confusing result
Bram Moolenaar <Bram@vim.org>
parents: 22460
diff changeset
2725 {
4c21f7f6f9e3 patch 8.2.1795: Vim9: operators && and || have a confusing result
Bram Moolenaar <Bram@vim.org>
parents: 22460
diff changeset
2726 SOURCING_LNUM = iptr->isn_lnum;
4c21f7f6f9e3 patch 8.2.1795: Vim9: operators && and || have a confusing result
Bram Moolenaar <Bram@vim.org>
parents: 22460
diff changeset
2727 jump = tv_get_bool_chk(tv, &error);
4c21f7f6f9e3 patch 8.2.1795: Vim9: operators && and || have a confusing result
Bram Moolenaar <Bram@vim.org>
parents: 22460
diff changeset
2728 if (error)
4c21f7f6f9e3 patch 8.2.1795: Vim9: operators && and || have a confusing result
Bram Moolenaar <Bram@vim.org>
parents: 22460
diff changeset
2729 goto on_error;
4c21f7f6f9e3 patch 8.2.1795: Vim9: operators && and || have a confusing result
Bram Moolenaar <Bram@vim.org>
parents: 22460
diff changeset
2730 }
4c21f7f6f9e3 patch 8.2.1795: Vim9: operators && and || have a confusing result
Bram Moolenaar <Bram@vim.org>
parents: 22460
diff changeset
2731 else
4c21f7f6f9e3 patch 8.2.1795: Vim9: operators && and || have a confusing result
Bram Moolenaar <Bram@vim.org>
parents: 22460
diff changeset
2732 jump = tv2bool(tv);
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2733 if (when == JUMP_IF_FALSE
22494
4c21f7f6f9e3 patch 8.2.1795: Vim9: operators && and || have a confusing result
Bram Moolenaar <Bram@vim.org>
parents: 22460
diff changeset
2734 || when == JUMP_AND_KEEP_IF_FALSE
4c21f7f6f9e3 patch 8.2.1795: Vim9: operators && and || have a confusing result
Bram Moolenaar <Bram@vim.org>
parents: 22460
diff changeset
2735 || when == JUMP_IF_COND_FALSE)
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2736 jump = !jump;
19334
61646c189622 patch 8.2.0225: compiling lambda not tested yet
Bram Moolenaar <Bram@vim.org>
parents: 19328
diff changeset
2737 if (when == JUMP_IF_FALSE || !jump)
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2738 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2739 // drop the value from the stack
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2740 clear_tv(tv);
24488
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
2741 --ectx->ec_stack.ga_len;
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2742 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2743 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2744 if (jump)
24488
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
2745 ectx->ec_iidx = iptr->isn_arg.jump.jump_where;
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2746 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2747 break;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2748
24272
cabed216cc2f patch 8.2.2677: Vim9: cannot use only some of the default arguments
Bram Moolenaar <Bram@vim.org>
parents: 24234
diff changeset
2749 // Jump if an argument with a default value was already set and not
cabed216cc2f patch 8.2.2677: Vim9: cannot use only some of the default arguments
Bram Moolenaar <Bram@vim.org>
parents: 24234
diff changeset
2750 // v:none.
cabed216cc2f patch 8.2.2677: Vim9: cannot use only some of the default arguments
Bram Moolenaar <Bram@vim.org>
parents: 24234
diff changeset
2751 case ISN_JUMP_IF_ARG_SET:
cabed216cc2f patch 8.2.2677: Vim9: cannot use only some of the default arguments
Bram Moolenaar <Bram@vim.org>
parents: 24234
diff changeset
2752 tv = STACK_TV_VAR(iptr->isn_arg.jumparg.jump_arg_off);
cabed216cc2f patch 8.2.2677: Vim9: cannot use only some of the default arguments
Bram Moolenaar <Bram@vim.org>
parents: 24234
diff changeset
2753 if (tv->v_type != VAR_UNKNOWN
cabed216cc2f patch 8.2.2677: Vim9: cannot use only some of the default arguments
Bram Moolenaar <Bram@vim.org>
parents: 24234
diff changeset
2754 && !(tv->v_type == VAR_SPECIAL
cabed216cc2f patch 8.2.2677: Vim9: cannot use only some of the default arguments
Bram Moolenaar <Bram@vim.org>
parents: 24234
diff changeset
2755 && tv->vval.v_number == VVAL_NONE))
24488
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
2756 ectx->ec_iidx = iptr->isn_arg.jumparg.jump_where;
24272
cabed216cc2f patch 8.2.2677: Vim9: cannot use only some of the default arguments
Bram Moolenaar <Bram@vim.org>
parents: 24234
diff changeset
2757 break;
cabed216cc2f patch 8.2.2677: Vim9: cannot use only some of the default arguments
Bram Moolenaar <Bram@vim.org>
parents: 24234
diff changeset
2758
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2759 // top of a for loop
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2760 case ISN_FOR:
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2761 {
24234
7ffc795288dd patch 8.2.2658: :for cannot loop over a string
Bram Moolenaar <Bram@vim.org>
parents: 24226
diff changeset
2762 typval_T *ltv = STACK_TV_BOT(-1);
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2763 typval_T *idxtv =
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2764 STACK_TV_VAR(iptr->isn_arg.forloop.for_idx);
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2765
24488
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
2766 if (GA_GROW(&ectx->ec_stack, 1) == FAIL)
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
2767 return FAIL;
24234
7ffc795288dd patch 8.2.2658: :for cannot loop over a string
Bram Moolenaar <Bram@vim.org>
parents: 24226
diff changeset
2768 if (ltv->v_type == VAR_LIST)
24220
a7a9176bb542 patch 8.2.2651: Vim9: restoring command modifiers happens after jump
Bram Moolenaar <Bram@vim.org>
parents: 24218
diff changeset
2769 {
24234
7ffc795288dd patch 8.2.2658: :for cannot loop over a string
Bram Moolenaar <Bram@vim.org>
parents: 24226
diff changeset
2770 list_T *list = ltv->vval.v_list;
7ffc795288dd patch 8.2.2658: :for cannot loop over a string
Bram Moolenaar <Bram@vim.org>
parents: 24226
diff changeset
2771
7ffc795288dd patch 8.2.2658: :for cannot loop over a string
Bram Moolenaar <Bram@vim.org>
parents: 24226
diff changeset
2772 // push the next item from the list
7ffc795288dd patch 8.2.2658: :for cannot loop over a string
Bram Moolenaar <Bram@vim.org>
parents: 24226
diff changeset
2773 ++idxtv->vval.v_number;
7ffc795288dd patch 8.2.2658: :for cannot loop over a string
Bram Moolenaar <Bram@vim.org>
parents: 24226
diff changeset
2774 if (list == NULL
7ffc795288dd patch 8.2.2658: :for cannot loop over a string
Bram Moolenaar <Bram@vim.org>
parents: 24226
diff changeset
2775 || idxtv->vval.v_number >= list->lv_len)
7ffc795288dd patch 8.2.2658: :for cannot loop over a string
Bram Moolenaar <Bram@vim.org>
parents: 24226
diff changeset
2776 {
7ffc795288dd patch 8.2.2658: :for cannot loop over a string
Bram Moolenaar <Bram@vim.org>
parents: 24226
diff changeset
2777 // past the end of the list, jump to "endfor"
24488
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
2778 ectx->ec_iidx = iptr->isn_arg.forloop.for_end;
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
2779 may_restore_cmdmod(&ectx->ec_funclocal);
24234
7ffc795288dd patch 8.2.2658: :for cannot loop over a string
Bram Moolenaar <Bram@vim.org>
parents: 24226
diff changeset
2780 }
7ffc795288dd patch 8.2.2658: :for cannot loop over a string
Bram Moolenaar <Bram@vim.org>
parents: 24226
diff changeset
2781 else if (list->lv_first == &range_list_item)
7ffc795288dd patch 8.2.2658: :for cannot loop over a string
Bram Moolenaar <Bram@vim.org>
parents: 24226
diff changeset
2782 {
7ffc795288dd patch 8.2.2658: :for cannot loop over a string
Bram Moolenaar <Bram@vim.org>
parents: 24226
diff changeset
2783 // non-materialized range() list
7ffc795288dd patch 8.2.2658: :for cannot loop over a string
Bram Moolenaar <Bram@vim.org>
parents: 24226
diff changeset
2784 tv = STACK_TV_BOT(0);
7ffc795288dd patch 8.2.2658: :for cannot loop over a string
Bram Moolenaar <Bram@vim.org>
parents: 24226
diff changeset
2785 tv->v_type = VAR_NUMBER;
7ffc795288dd patch 8.2.2658: :for cannot loop over a string
Bram Moolenaar <Bram@vim.org>
parents: 24226
diff changeset
2786 tv->v_lock = 0;
7ffc795288dd patch 8.2.2658: :for cannot loop over a string
Bram Moolenaar <Bram@vim.org>
parents: 24226
diff changeset
2787 tv->vval.v_number = list_find_nr(
7ffc795288dd patch 8.2.2658: :for cannot loop over a string
Bram Moolenaar <Bram@vim.org>
parents: 24226
diff changeset
2788 list, idxtv->vval.v_number, NULL);
24488
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
2789 ++ectx->ec_stack.ga_len;
24234
7ffc795288dd patch 8.2.2658: :for cannot loop over a string
Bram Moolenaar <Bram@vim.org>
parents: 24226
diff changeset
2790 }
7ffc795288dd patch 8.2.2658: :for cannot loop over a string
Bram Moolenaar <Bram@vim.org>
parents: 24226
diff changeset
2791 else
7ffc795288dd patch 8.2.2658: :for cannot loop over a string
Bram Moolenaar <Bram@vim.org>
parents: 24226
diff changeset
2792 {
7ffc795288dd patch 8.2.2658: :for cannot loop over a string
Bram Moolenaar <Bram@vim.org>
parents: 24226
diff changeset
2793 listitem_T *li = list_find(list,
7ffc795288dd patch 8.2.2658: :for cannot loop over a string
Bram Moolenaar <Bram@vim.org>
parents: 24226
diff changeset
2794 idxtv->vval.v_number);
7ffc795288dd patch 8.2.2658: :for cannot loop over a string
Bram Moolenaar <Bram@vim.org>
parents: 24226
diff changeset
2795
7ffc795288dd patch 8.2.2658: :for cannot loop over a string
Bram Moolenaar <Bram@vim.org>
parents: 24226
diff changeset
2796 copy_tv(&li->li_tv, STACK_TV_BOT(0));
24488
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
2797 ++ectx->ec_stack.ga_len;
24234
7ffc795288dd patch 8.2.2658: :for cannot loop over a string
Bram Moolenaar <Bram@vim.org>
parents: 24226
diff changeset
2798 }
24220
a7a9176bb542 patch 8.2.2651: Vim9: restoring command modifiers happens after jump
Bram Moolenaar <Bram@vim.org>
parents: 24218
diff changeset
2799 }
24234
7ffc795288dd patch 8.2.2658: :for cannot loop over a string
Bram Moolenaar <Bram@vim.org>
parents: 24226
diff changeset
2800 else if (ltv->v_type == VAR_STRING)
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2801 {
24234
7ffc795288dd patch 8.2.2658: :for cannot loop over a string
Bram Moolenaar <Bram@vim.org>
parents: 24226
diff changeset
2802 char_u *str = ltv->vval.v_string;
7ffc795288dd patch 8.2.2658: :for cannot loop over a string
Bram Moolenaar <Bram@vim.org>
parents: 24226
diff changeset
2803
24480
943e9b1d2d16 patch 8.2.2780: Vim9: for loop over blob doesn't work
Bram Moolenaar <Bram@vim.org>
parents: 24475
diff changeset
2804 // The index is for the last byte of the previous
943e9b1d2d16 patch 8.2.2780: Vim9: for loop over blob doesn't work
Bram Moolenaar <Bram@vim.org>
parents: 24475
diff changeset
2805 // character.
24234
7ffc795288dd patch 8.2.2658: :for cannot loop over a string
Bram Moolenaar <Bram@vim.org>
parents: 24226
diff changeset
2806 ++idxtv->vval.v_number;
24392
79fda175df83 patch 8.2.2736: Vim9: for loop over string is a bit slow
Bram Moolenaar <Bram@vim.org>
parents: 24339
diff changeset
2807 if (str == NULL || str[idxtv->vval.v_number] == NUL)
24234
7ffc795288dd patch 8.2.2658: :for cannot loop over a string
Bram Moolenaar <Bram@vim.org>
parents: 24226
diff changeset
2808 {
7ffc795288dd patch 8.2.2658: :for cannot loop over a string
Bram Moolenaar <Bram@vim.org>
parents: 24226
diff changeset
2809 // past the end of the string, jump to "endfor"
24488
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
2810 ectx->ec_iidx = iptr->isn_arg.forloop.for_end;
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
2811 may_restore_cmdmod(&ectx->ec_funclocal);
24234
7ffc795288dd patch 8.2.2658: :for cannot loop over a string
Bram Moolenaar <Bram@vim.org>
parents: 24226
diff changeset
2812 }
7ffc795288dd patch 8.2.2658: :for cannot loop over a string
Bram Moolenaar <Bram@vim.org>
parents: 24226
diff changeset
2813 else
7ffc795288dd patch 8.2.2658: :for cannot loop over a string
Bram Moolenaar <Bram@vim.org>
parents: 24226
diff changeset
2814 {
7ffc795288dd patch 8.2.2658: :for cannot loop over a string
Bram Moolenaar <Bram@vim.org>
parents: 24226
diff changeset
2815 int clen = mb_ptr2len(str + idxtv->vval.v_number);
7ffc795288dd patch 8.2.2658: :for cannot loop over a string
Bram Moolenaar <Bram@vim.org>
parents: 24226
diff changeset
2816
24480
943e9b1d2d16 patch 8.2.2780: Vim9: for loop over blob doesn't work
Bram Moolenaar <Bram@vim.org>
parents: 24475
diff changeset
2817 // Push the next character from the string.
24234
7ffc795288dd patch 8.2.2658: :for cannot loop over a string
Bram Moolenaar <Bram@vim.org>
parents: 24226
diff changeset
2818 tv = STACK_TV_BOT(0);
7ffc795288dd patch 8.2.2658: :for cannot loop over a string
Bram Moolenaar <Bram@vim.org>
parents: 24226
diff changeset
2819 tv->v_type = VAR_STRING;
7ffc795288dd patch 8.2.2658: :for cannot loop over a string
Bram Moolenaar <Bram@vim.org>
parents: 24226
diff changeset
2820 tv->vval.v_string = vim_strnsave(
7ffc795288dd patch 8.2.2658: :for cannot loop over a string
Bram Moolenaar <Bram@vim.org>
parents: 24226
diff changeset
2821 str + idxtv->vval.v_number, clen);
24488
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
2822 ++ectx->ec_stack.ga_len;
24234
7ffc795288dd patch 8.2.2658: :for cannot loop over a string
Bram Moolenaar <Bram@vim.org>
parents: 24226
diff changeset
2823 idxtv->vval.v_number += clen - 1;
7ffc795288dd patch 8.2.2658: :for cannot loop over a string
Bram Moolenaar <Bram@vim.org>
parents: 24226
diff changeset
2824 }
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2825 }
24480
943e9b1d2d16 patch 8.2.2780: Vim9: for loop over blob doesn't work
Bram Moolenaar <Bram@vim.org>
parents: 24475
diff changeset
2826 else if (ltv->v_type == VAR_BLOB)
943e9b1d2d16 patch 8.2.2780: Vim9: for loop over blob doesn't work
Bram Moolenaar <Bram@vim.org>
parents: 24475
diff changeset
2827 {
943e9b1d2d16 patch 8.2.2780: Vim9: for loop over blob doesn't work
Bram Moolenaar <Bram@vim.org>
parents: 24475
diff changeset
2828 blob_T *blob = ltv->vval.v_blob;
943e9b1d2d16 patch 8.2.2780: Vim9: for loop over blob doesn't work
Bram Moolenaar <Bram@vim.org>
parents: 24475
diff changeset
2829
943e9b1d2d16 patch 8.2.2780: Vim9: for loop over blob doesn't work
Bram Moolenaar <Bram@vim.org>
parents: 24475
diff changeset
2830 // When we get here the first time make a copy of the
943e9b1d2d16 patch 8.2.2780: Vim9: for loop over blob doesn't work
Bram Moolenaar <Bram@vim.org>
parents: 24475
diff changeset
2831 // blob, so that the iteration still works when it is
943e9b1d2d16 patch 8.2.2780: Vim9: for loop over blob doesn't work
Bram Moolenaar <Bram@vim.org>
parents: 24475
diff changeset
2832 // changed.
943e9b1d2d16 patch 8.2.2780: Vim9: for loop over blob doesn't work
Bram Moolenaar <Bram@vim.org>
parents: 24475
diff changeset
2833 if (idxtv->vval.v_number == -1 && blob != NULL)
943e9b1d2d16 patch 8.2.2780: Vim9: for loop over blob doesn't work
Bram Moolenaar <Bram@vim.org>
parents: 24475
diff changeset
2834 {
943e9b1d2d16 patch 8.2.2780: Vim9: for loop over blob doesn't work
Bram Moolenaar <Bram@vim.org>
parents: 24475
diff changeset
2835 blob_copy(blob, ltv);
943e9b1d2d16 patch 8.2.2780: Vim9: for loop over blob doesn't work
Bram Moolenaar <Bram@vim.org>
parents: 24475
diff changeset
2836 blob_unref(blob);
943e9b1d2d16 patch 8.2.2780: Vim9: for loop over blob doesn't work
Bram Moolenaar <Bram@vim.org>
parents: 24475
diff changeset
2837 blob = ltv->vval.v_blob;
943e9b1d2d16 patch 8.2.2780: Vim9: for loop over blob doesn't work
Bram Moolenaar <Bram@vim.org>
parents: 24475
diff changeset
2838 }
943e9b1d2d16 patch 8.2.2780: Vim9: for loop over blob doesn't work
Bram Moolenaar <Bram@vim.org>
parents: 24475
diff changeset
2839
943e9b1d2d16 patch 8.2.2780: Vim9: for loop over blob doesn't work
Bram Moolenaar <Bram@vim.org>
parents: 24475
diff changeset
2840 // The index is for the previous byte.
943e9b1d2d16 patch 8.2.2780: Vim9: for loop over blob doesn't work
Bram Moolenaar <Bram@vim.org>
parents: 24475
diff changeset
2841 ++idxtv->vval.v_number;
943e9b1d2d16 patch 8.2.2780: Vim9: for loop over blob doesn't work
Bram Moolenaar <Bram@vim.org>
parents: 24475
diff changeset
2842 if (blob == NULL
943e9b1d2d16 patch 8.2.2780: Vim9: for loop over blob doesn't work
Bram Moolenaar <Bram@vim.org>
parents: 24475
diff changeset
2843 || idxtv->vval.v_number >= blob_len(blob))
943e9b1d2d16 patch 8.2.2780: Vim9: for loop over blob doesn't work
Bram Moolenaar <Bram@vim.org>
parents: 24475
diff changeset
2844 {
943e9b1d2d16 patch 8.2.2780: Vim9: for loop over blob doesn't work
Bram Moolenaar <Bram@vim.org>
parents: 24475
diff changeset
2845 // past the end of the blob, jump to "endfor"
24488
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
2846 ectx->ec_iidx = iptr->isn_arg.forloop.for_end;
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
2847 may_restore_cmdmod(&ectx->ec_funclocal);
24480
943e9b1d2d16 patch 8.2.2780: Vim9: for loop over blob doesn't work
Bram Moolenaar <Bram@vim.org>
parents: 24475
diff changeset
2848 }
943e9b1d2d16 patch 8.2.2780: Vim9: for loop over blob doesn't work
Bram Moolenaar <Bram@vim.org>
parents: 24475
diff changeset
2849 else
943e9b1d2d16 patch 8.2.2780: Vim9: for loop over blob doesn't work
Bram Moolenaar <Bram@vim.org>
parents: 24475
diff changeset
2850 {
943e9b1d2d16 patch 8.2.2780: Vim9: for loop over blob doesn't work
Bram Moolenaar <Bram@vim.org>
parents: 24475
diff changeset
2851 // Push the next byte from the blob.
943e9b1d2d16 patch 8.2.2780: Vim9: for loop over blob doesn't work
Bram Moolenaar <Bram@vim.org>
parents: 24475
diff changeset
2852 tv = STACK_TV_BOT(0);
943e9b1d2d16 patch 8.2.2780: Vim9: for loop over blob doesn't work
Bram Moolenaar <Bram@vim.org>
parents: 24475
diff changeset
2853 tv->v_type = VAR_NUMBER;
943e9b1d2d16 patch 8.2.2780: Vim9: for loop over blob doesn't work
Bram Moolenaar <Bram@vim.org>
parents: 24475
diff changeset
2854 tv->vval.v_number = blob_get(blob,
943e9b1d2d16 patch 8.2.2780: Vim9: for loop over blob doesn't work
Bram Moolenaar <Bram@vim.org>
parents: 24475
diff changeset
2855 idxtv->vval.v_number);
24488
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
2856 ++ectx->ec_stack.ga_len;
24480
943e9b1d2d16 patch 8.2.2780: Vim9: for loop over blob doesn't work
Bram Moolenaar <Bram@vim.org>
parents: 24475
diff changeset
2857 }
943e9b1d2d16 patch 8.2.2780: Vim9: for loop over blob doesn't work
Bram Moolenaar <Bram@vim.org>
parents: 24475
diff changeset
2858 }
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2859 else
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2860 {
24234
7ffc795288dd patch 8.2.2658: :for cannot loop over a string
Bram Moolenaar <Bram@vim.org>
parents: 24226
diff changeset
2861 semsg(_(e_for_loop_on_str_not_supported),
7ffc795288dd patch 8.2.2658: :for cannot loop over a string
Bram Moolenaar <Bram@vim.org>
parents: 24226
diff changeset
2862 vartype_name(ltv->v_type));
24488
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
2863 return FAIL;
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2864 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2865 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2866 break;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2867
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2868 // start of ":try" block
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2869 case ISN_TRY:
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2870 {
19726
ad37a198a708 patch 8.2.0419: various memory leaks in Vim9 script code
Bram Moolenaar <Bram@vim.org>
parents: 19635
diff changeset
2871 trycmd_T *trycmd = NULL;
ad37a198a708 patch 8.2.0419: various memory leaks in Vim9 script code
Bram Moolenaar <Bram@vim.org>
parents: 19635
diff changeset
2872
24488
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
2873 if (GA_GROW(&ectx->ec_trystack, 1) == FAIL)
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
2874 return FAIL;
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
2875 trycmd = ((trycmd_T *)ectx->ec_trystack.ga_data)
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
2876 + ectx->ec_trystack.ga_len;
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
2877 ++ectx->ec_trystack.ga_len;
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2878 ++trylevel;
23934
f9a4ede76237 patch 8.2.2509: tests fail on s390 build
Bram Moolenaar <Bram@vim.org>
parents: 23927
diff changeset
2879 CLEAR_POINTER(trycmd);
24488
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
2880 trycmd->tcd_frame_idx = ectx->ec_frame_idx;
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
2881 trycmd->tcd_stack_len = ectx->ec_stack.ga_len;
24220
a7a9176bb542 patch 8.2.2651: Vim9: restoring command modifiers happens after jump
Bram Moolenaar <Bram@vim.org>
parents: 24218
diff changeset
2882 trycmd->tcd_catch_idx =
a7a9176bb542 patch 8.2.2651: Vim9: restoring command modifiers happens after jump
Bram Moolenaar <Bram@vim.org>
parents: 24218
diff changeset
2883 iptr->isn_arg.try.try_ref->try_catch;
a7a9176bb542 patch 8.2.2651: Vim9: restoring command modifiers happens after jump
Bram Moolenaar <Bram@vim.org>
parents: 24218
diff changeset
2884 trycmd->tcd_finally_idx =
a7a9176bb542 patch 8.2.2651: Vim9: restoring command modifiers happens after jump
Bram Moolenaar <Bram@vim.org>
parents: 24218
diff changeset
2885 iptr->isn_arg.try.try_ref->try_finally;
a7a9176bb542 patch 8.2.2651: Vim9: restoring command modifiers happens after jump
Bram Moolenaar <Bram@vim.org>
parents: 24218
diff changeset
2886 trycmd->tcd_endtry_idx =
a7a9176bb542 patch 8.2.2651: Vim9: restoring command modifiers happens after jump
Bram Moolenaar <Bram@vim.org>
parents: 24218
diff changeset
2887 iptr->isn_arg.try.try_ref->try_endtry;
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2888 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2889 break;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2890
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2891 case ISN_PUSHEXC:
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2892 if (current_exception == NULL)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2893 {
21793
0706bd071fa3 patch 8.2.1446: Vim9: line number in error message is not correct
Bram Moolenaar <Bram@vim.org>
parents: 21789
diff changeset
2894 SOURCING_LNUM = iptr->isn_lnum;
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2895 iemsg("Evaluating catch while current_exception is NULL");
24488
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
2896 return FAIL;
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2897 }
24488
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
2898 if (GA_GROW(&ectx->ec_stack, 1) == FAIL)
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
2899 return FAIL;
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2900 tv = STACK_TV_BOT(0);
24488
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
2901 ++ectx->ec_stack.ga_len;
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2902 tv->v_type = VAR_STRING;
21399
5cb6e676defd patch 8.2.1250: Vim9: cannot use the g:, b:, t: and w: namespaces
Bram Moolenaar <Bram@vim.org>
parents: 21393
diff changeset
2903 tv->v_lock = 0;
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2904 tv->vval.v_string = vim_strsave(
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2905 (char_u *)current_exception->value);
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2906 break;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2907
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2908 case ISN_CATCH:
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2909 {
24488
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
2910 garray_T *trystack = &ectx->ec_trystack;
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
2911
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
2912 may_restore_cmdmod(&ectx->ec_funclocal);
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2913 if (trystack->ga_len > 0)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2914 {
19726
ad37a198a708 patch 8.2.0419: various memory leaks in Vim9 script code
Bram Moolenaar <Bram@vim.org>
parents: 19635
diff changeset
2915 trycmd_T *trycmd = ((trycmd_T *)trystack->ga_data)
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2916 + trystack->ga_len - 1;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2917 trycmd->tcd_caught = TRUE;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2918 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2919 did_emsg = got_int = did_throw = FALSE;
23656
c6f7df86cd9d patch 8.2.2370: Vim9: command fails in catch block
Bram Moolenaar <Bram@vim.org>
parents: 23650
diff changeset
2920 force_abort = need_rethrow = FALSE;
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2921 catch_exception(current_exception);
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2922 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2923 break;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2924
23927
5e5780e3f75d patch 8.2.2506: Vim9: :continue does not work correctly in a :try block
Bram Moolenaar <Bram@vim.org>
parents: 23921
diff changeset
2925 case ISN_TRYCONT:
5e5780e3f75d patch 8.2.2506: Vim9: :continue does not work correctly in a :try block
Bram Moolenaar <Bram@vim.org>
parents: 23921
diff changeset
2926 {
24488
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
2927 garray_T *trystack = &ectx->ec_trystack;
23927
5e5780e3f75d patch 8.2.2506: Vim9: :continue does not work correctly in a :try block
Bram Moolenaar <Bram@vim.org>
parents: 23921
diff changeset
2928 trycont_T *trycont = &iptr->isn_arg.trycont;
5e5780e3f75d patch 8.2.2506: Vim9: :continue does not work correctly in a :try block
Bram Moolenaar <Bram@vim.org>
parents: 23921
diff changeset
2929 int i;
5e5780e3f75d patch 8.2.2506: Vim9: :continue does not work correctly in a :try block
Bram Moolenaar <Bram@vim.org>
parents: 23921
diff changeset
2930 trycmd_T *trycmd;
5e5780e3f75d patch 8.2.2506: Vim9: :continue does not work correctly in a :try block
Bram Moolenaar <Bram@vim.org>
parents: 23921
diff changeset
2931 int iidx = trycont->tct_where;
5e5780e3f75d patch 8.2.2506: Vim9: :continue does not work correctly in a :try block
Bram Moolenaar <Bram@vim.org>
parents: 23921
diff changeset
2932
5e5780e3f75d patch 8.2.2506: Vim9: :continue does not work correctly in a :try block
Bram Moolenaar <Bram@vim.org>
parents: 23921
diff changeset
2933 if (trystack->ga_len < trycont->tct_levels)
5e5780e3f75d patch 8.2.2506: Vim9: :continue does not work correctly in a :try block
Bram Moolenaar <Bram@vim.org>
parents: 23921
diff changeset
2934 {
5e5780e3f75d patch 8.2.2506: Vim9: :continue does not work correctly in a :try block
Bram Moolenaar <Bram@vim.org>
parents: 23921
diff changeset
2935 siemsg("TRYCONT: expected %d levels, found %d",
5e5780e3f75d patch 8.2.2506: Vim9: :continue does not work correctly in a :try block
Bram Moolenaar <Bram@vim.org>
parents: 23921
diff changeset
2936 trycont->tct_levels, trystack->ga_len);
24488
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
2937 return FAIL;
23927
5e5780e3f75d patch 8.2.2506: Vim9: :continue does not work correctly in a :try block
Bram Moolenaar <Bram@vim.org>
parents: 23921
diff changeset
2938 }
5e5780e3f75d patch 8.2.2506: Vim9: :continue does not work correctly in a :try block
Bram Moolenaar <Bram@vim.org>
parents: 23921
diff changeset
2939 // Make :endtry jump to any outer try block and the last
5e5780e3f75d patch 8.2.2506: Vim9: :continue does not work correctly in a :try block
Bram Moolenaar <Bram@vim.org>
parents: 23921
diff changeset
2940 // :endtry inside the loop to the loop start.
5e5780e3f75d patch 8.2.2506: Vim9: :continue does not work correctly in a :try block
Bram Moolenaar <Bram@vim.org>
parents: 23921
diff changeset
2941 for (i = trycont->tct_levels; i > 0; --i)
5e5780e3f75d patch 8.2.2506: Vim9: :continue does not work correctly in a :try block
Bram Moolenaar <Bram@vim.org>
parents: 23921
diff changeset
2942 {
5e5780e3f75d patch 8.2.2506: Vim9: :continue does not work correctly in a :try block
Bram Moolenaar <Bram@vim.org>
parents: 23921
diff changeset
2943 trycmd = ((trycmd_T *)trystack->ga_data)
5e5780e3f75d patch 8.2.2506: Vim9: :continue does not work correctly in a :try block
Bram Moolenaar <Bram@vim.org>
parents: 23921
diff changeset
2944 + trystack->ga_len - i;
24122
e8b21a3bb0d5 patch 8.2.2602: Vim9: continue doesn't work if :while is very first command
Bram Moolenaar <Bram@vim.org>
parents: 24112
diff changeset
2945 // Add one to tcd_cont to be able to jump to
e8b21a3bb0d5 patch 8.2.2602: Vim9: continue doesn't work if :while is very first command
Bram Moolenaar <Bram@vim.org>
parents: 24112
diff changeset
2946 // instruction with index zero.
e8b21a3bb0d5 patch 8.2.2602: Vim9: continue doesn't work if :while is very first command
Bram Moolenaar <Bram@vim.org>
parents: 24112
diff changeset
2947 trycmd->tcd_cont = iidx + 1;
23994
3daeb2060f25 patch 8.2.2539: Vim9: return from finally block causes a hang
Bram Moolenaar <Bram@vim.org>
parents: 23982
diff changeset
2948 iidx = trycmd->tcd_finally_idx == 0
3daeb2060f25 patch 8.2.2539: Vim9: return from finally block causes a hang
Bram Moolenaar <Bram@vim.org>
parents: 23982
diff changeset
2949 ? trycmd->tcd_endtry_idx : trycmd->tcd_finally_idx;
23927
5e5780e3f75d patch 8.2.2506: Vim9: :continue does not work correctly in a :try block
Bram Moolenaar <Bram@vim.org>
parents: 23921
diff changeset
2950 }
5e5780e3f75d patch 8.2.2506: Vim9: :continue does not work correctly in a :try block
Bram Moolenaar <Bram@vim.org>
parents: 23921
diff changeset
2951 // jump to :finally or :endtry of current try statement
24488
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
2952 ectx->ec_iidx = iidx;
23927
5e5780e3f75d patch 8.2.2506: Vim9: :continue does not work correctly in a :try block
Bram Moolenaar <Bram@vim.org>
parents: 23921
diff changeset
2953 }
5e5780e3f75d patch 8.2.2506: Vim9: :continue does not work correctly in a :try block
Bram Moolenaar <Bram@vim.org>
parents: 23921
diff changeset
2954 break;
5e5780e3f75d patch 8.2.2506: Vim9: :continue does not work correctly in a :try block
Bram Moolenaar <Bram@vim.org>
parents: 23921
diff changeset
2955
23994
3daeb2060f25 patch 8.2.2539: Vim9: return from finally block causes a hang
Bram Moolenaar <Bram@vim.org>
parents: 23982
diff changeset
2956 case ISN_FINALLY:
3daeb2060f25 patch 8.2.2539: Vim9: return from finally block causes a hang
Bram Moolenaar <Bram@vim.org>
parents: 23982
diff changeset
2957 {
24488
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
2958 garray_T *trystack = &ectx->ec_trystack;
23994
3daeb2060f25 patch 8.2.2539: Vim9: return from finally block causes a hang
Bram Moolenaar <Bram@vim.org>
parents: 23982
diff changeset
2959 trycmd_T *trycmd = ((trycmd_T *)trystack->ga_data)
3daeb2060f25 patch 8.2.2539: Vim9: return from finally block causes a hang
Bram Moolenaar <Bram@vim.org>
parents: 23982
diff changeset
2960 + trystack->ga_len - 1;
3daeb2060f25 patch 8.2.2539: Vim9: return from finally block causes a hang
Bram Moolenaar <Bram@vim.org>
parents: 23982
diff changeset
2961
3daeb2060f25 patch 8.2.2539: Vim9: return from finally block causes a hang
Bram Moolenaar <Bram@vim.org>
parents: 23982
diff changeset
2962 // Reset the index to avoid a return statement jumps here
3daeb2060f25 patch 8.2.2539: Vim9: return from finally block causes a hang
Bram Moolenaar <Bram@vim.org>
parents: 23982
diff changeset
2963 // again.
3daeb2060f25 patch 8.2.2539: Vim9: return from finally block causes a hang
Bram Moolenaar <Bram@vim.org>
parents: 23982
diff changeset
2964 trycmd->tcd_finally_idx = 0;
3daeb2060f25 patch 8.2.2539: Vim9: return from finally block causes a hang
Bram Moolenaar <Bram@vim.org>
parents: 23982
diff changeset
2965 break;
3daeb2060f25 patch 8.2.2539: Vim9: return from finally block causes a hang
Bram Moolenaar <Bram@vim.org>
parents: 23982
diff changeset
2966 }
3daeb2060f25 patch 8.2.2539: Vim9: return from finally block causes a hang
Bram Moolenaar <Bram@vim.org>
parents: 23982
diff changeset
2967
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2968 // end of ":try" block
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2969 case ISN_ENDTRY:
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2970 {
24488
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
2971 garray_T *trystack = &ectx->ec_trystack;
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2972
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2973 if (trystack->ga_len > 0)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2974 {
23725
f98692ae09a0 patch 8.2.2404: Vim9: profiling try/catch not correct
Bram Moolenaar <Bram@vim.org>
parents: 23719
diff changeset
2975 trycmd_T *trycmd;
19726
ad37a198a708 patch 8.2.0419: various memory leaks in Vim9 script code
Bram Moolenaar <Bram@vim.org>
parents: 19635
diff changeset
2976
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2977 --trystack->ga_len;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2978 --trylevel;
24488
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
2979 ectx->ec_in_catch = FALSE;
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2980 trycmd = ((trycmd_T *)trystack->ga_data)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2981 + trystack->ga_len;
19459
423b27246383 patch 8.2.0287: Vim9: return in try block not tested; catch not tested
Bram Moolenaar <Bram@vim.org>
parents: 19455
diff changeset
2982 if (trycmd->tcd_caught && current_exception != NULL)
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2983 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2984 // discard the exception
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2985 if (caught_stack == current_exception)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2986 caught_stack = caught_stack->caught;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2987 discard_current_exception();
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2988 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2989
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2990 if (trycmd->tcd_return)
21375
92e2ed2a2778 patch 8.2.1238: Vim9: a few remaining errors not caught by try/catch
Bram Moolenaar <Bram@vim.org>
parents: 21371
diff changeset
2991 goto func_return;
23921
a834f9c082e3 patch 8.2.2503: Vim9: a caught error may leave something on the stack
Bram Moolenaar <Bram@vim.org>
parents: 23917
diff changeset
2992
24488
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
2993 while (ectx->ec_stack.ga_len > trycmd->tcd_stack_len)
23921
a834f9c082e3 patch 8.2.2503: Vim9: a caught error may leave something on the stack
Bram Moolenaar <Bram@vim.org>
parents: 23917
diff changeset
2994 {
24488
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
2995 --ectx->ec_stack.ga_len;
23921
a834f9c082e3 patch 8.2.2503: Vim9: a caught error may leave something on the stack
Bram Moolenaar <Bram@vim.org>
parents: 23917
diff changeset
2996 clear_tv(STACK_TV_BOT(0));
a834f9c082e3 patch 8.2.2503: Vim9: a caught error may leave something on the stack
Bram Moolenaar <Bram@vim.org>
parents: 23917
diff changeset
2997 }
23934
f9a4ede76237 patch 8.2.2509: tests fail on s390 build
Bram Moolenaar <Bram@vim.org>
parents: 23927
diff changeset
2998 if (trycmd->tcd_cont != 0)
23927
5e5780e3f75d patch 8.2.2506: Vim9: :continue does not work correctly in a :try block
Bram Moolenaar <Bram@vim.org>
parents: 23921
diff changeset
2999 // handling :continue: jump to outer try block or
5e5780e3f75d patch 8.2.2506: Vim9: :continue does not work correctly in a :try block
Bram Moolenaar <Bram@vim.org>
parents: 23921
diff changeset
3000 // start of the loop
24488
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
3001 ectx->ec_iidx = trycmd->tcd_cont - 1;
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3002 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3003 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3004 break;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3005
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3006 case ISN_THROW:
23618
d228ca435f3a patch 8.2.2351: Vim9: error msg for "throw" in function called with "silent!"
Bram Moolenaar <Bram@vim.org>
parents: 23604
diff changeset
3007 {
24488
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
3008 garray_T *trystack = &ectx->ec_trystack;
23725
f98692ae09a0 patch 8.2.2404: Vim9: profiling try/catch not correct
Bram Moolenaar <Bram@vim.org>
parents: 23719
diff changeset
3009
f98692ae09a0 patch 8.2.2404: Vim9: profiling try/catch not correct
Bram Moolenaar <Bram@vim.org>
parents: 23719
diff changeset
3010 if (trystack->ga_len == 0 && trylevel == 0 && emsg_silent)
f98692ae09a0 patch 8.2.2404: Vim9: profiling try/catch not correct
Bram Moolenaar <Bram@vim.org>
parents: 23719
diff changeset
3011 {
f98692ae09a0 patch 8.2.2404: Vim9: profiling try/catch not correct
Bram Moolenaar <Bram@vim.org>
parents: 23719
diff changeset
3012 // throwing an exception while using "silent!" causes
f98692ae09a0 patch 8.2.2404: Vim9: profiling try/catch not correct
Bram Moolenaar <Bram@vim.org>
parents: 23719
diff changeset
3013 // the function to abort but not display an error.
f98692ae09a0 patch 8.2.2404: Vim9: profiling try/catch not correct
Bram Moolenaar <Bram@vim.org>
parents: 23719
diff changeset
3014 tv = STACK_TV_BOT(-1);
f98692ae09a0 patch 8.2.2404: Vim9: profiling try/catch not correct
Bram Moolenaar <Bram@vim.org>
parents: 23719
diff changeset
3015 clear_tv(tv);
f98692ae09a0 patch 8.2.2404: Vim9: profiling try/catch not correct
Bram Moolenaar <Bram@vim.org>
parents: 23719
diff changeset
3016 tv->v_type = VAR_NUMBER;
f98692ae09a0 patch 8.2.2404: Vim9: profiling try/catch not correct
Bram Moolenaar <Bram@vim.org>
parents: 23719
diff changeset
3017 tv->vval.v_number = 0;
f98692ae09a0 patch 8.2.2404: Vim9: profiling try/catch not correct
Bram Moolenaar <Bram@vim.org>
parents: 23719
diff changeset
3018 goto done;
f98692ae09a0 patch 8.2.2404: Vim9: profiling try/catch not correct
Bram Moolenaar <Bram@vim.org>
parents: 23719
diff changeset
3019 }
24488
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
3020 --ectx->ec_stack.ga_len;
23725
f98692ae09a0 patch 8.2.2404: Vim9: profiling try/catch not correct
Bram Moolenaar <Bram@vim.org>
parents: 23719
diff changeset
3021 tv = STACK_TV_BOT(0);
f98692ae09a0 patch 8.2.2404: Vim9: profiling try/catch not correct
Bram Moolenaar <Bram@vim.org>
parents: 23719
diff changeset
3022 if (tv->vval.v_string == NULL
f98692ae09a0 patch 8.2.2404: Vim9: profiling try/catch not correct
Bram Moolenaar <Bram@vim.org>
parents: 23719
diff changeset
3023 || *skipwhite(tv->vval.v_string) == NUL)
f98692ae09a0 patch 8.2.2404: Vim9: profiling try/catch not correct
Bram Moolenaar <Bram@vim.org>
parents: 23719
diff changeset
3024 {
f98692ae09a0 patch 8.2.2404: Vim9: profiling try/catch not correct
Bram Moolenaar <Bram@vim.org>
parents: 23719
diff changeset
3025 vim_free(tv->vval.v_string);
f98692ae09a0 patch 8.2.2404: Vim9: profiling try/catch not correct
Bram Moolenaar <Bram@vim.org>
parents: 23719
diff changeset
3026 SOURCING_LNUM = iptr->isn_lnum;
f98692ae09a0 patch 8.2.2404: Vim9: profiling try/catch not correct
Bram Moolenaar <Bram@vim.org>
parents: 23719
diff changeset
3027 emsg(_(e_throw_with_empty_string));
24488
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
3028 return FAIL;
23725
f98692ae09a0 patch 8.2.2404: Vim9: profiling try/catch not correct
Bram Moolenaar <Bram@vim.org>
parents: 23719
diff changeset
3029 }
f98692ae09a0 patch 8.2.2404: Vim9: profiling try/catch not correct
Bram Moolenaar <Bram@vim.org>
parents: 23719
diff changeset
3030
f98692ae09a0 patch 8.2.2404: Vim9: profiling try/catch not correct
Bram Moolenaar <Bram@vim.org>
parents: 23719
diff changeset
3031 // Inside a "catch" we need to first discard the caught
f98692ae09a0 patch 8.2.2404: Vim9: profiling try/catch not correct
Bram Moolenaar <Bram@vim.org>
parents: 23719
diff changeset
3032 // exception.
f98692ae09a0 patch 8.2.2404: Vim9: profiling try/catch not correct
Bram Moolenaar <Bram@vim.org>
parents: 23719
diff changeset
3033 if (trystack->ga_len > 0)
f98692ae09a0 patch 8.2.2404: Vim9: profiling try/catch not correct
Bram Moolenaar <Bram@vim.org>
parents: 23719
diff changeset
3034 {
f98692ae09a0 patch 8.2.2404: Vim9: profiling try/catch not correct
Bram Moolenaar <Bram@vim.org>
parents: 23719
diff changeset
3035 trycmd_T *trycmd = ((trycmd_T *)trystack->ga_data)
f98692ae09a0 patch 8.2.2404: Vim9: profiling try/catch not correct
Bram Moolenaar <Bram@vim.org>
parents: 23719
diff changeset
3036 + trystack->ga_len - 1;
f98692ae09a0 patch 8.2.2404: Vim9: profiling try/catch not correct
Bram Moolenaar <Bram@vim.org>
parents: 23719
diff changeset
3037 if (trycmd->tcd_caught && current_exception != NULL)
f98692ae09a0 patch 8.2.2404: Vim9: profiling try/catch not correct
Bram Moolenaar <Bram@vim.org>
parents: 23719
diff changeset
3038 {
f98692ae09a0 patch 8.2.2404: Vim9: profiling try/catch not correct
Bram Moolenaar <Bram@vim.org>
parents: 23719
diff changeset
3039 // discard the exception
f98692ae09a0 patch 8.2.2404: Vim9: profiling try/catch not correct
Bram Moolenaar <Bram@vim.org>
parents: 23719
diff changeset
3040 if (caught_stack == current_exception)
f98692ae09a0 patch 8.2.2404: Vim9: profiling try/catch not correct
Bram Moolenaar <Bram@vim.org>
parents: 23719
diff changeset
3041 caught_stack = caught_stack->caught;
f98692ae09a0 patch 8.2.2404: Vim9: profiling try/catch not correct
Bram Moolenaar <Bram@vim.org>
parents: 23719
diff changeset
3042 discard_current_exception();
f98692ae09a0 patch 8.2.2404: Vim9: profiling try/catch not correct
Bram Moolenaar <Bram@vim.org>
parents: 23719
diff changeset
3043 trycmd->tcd_caught = FALSE;
f98692ae09a0 patch 8.2.2404: Vim9: profiling try/catch not correct
Bram Moolenaar <Bram@vim.org>
parents: 23719
diff changeset
3044 }
f98692ae09a0 patch 8.2.2404: Vim9: profiling try/catch not correct
Bram Moolenaar <Bram@vim.org>
parents: 23719
diff changeset
3045 }
f98692ae09a0 patch 8.2.2404: Vim9: profiling try/catch not correct
Bram Moolenaar <Bram@vim.org>
parents: 23719
diff changeset
3046
f98692ae09a0 patch 8.2.2404: Vim9: profiling try/catch not correct
Bram Moolenaar <Bram@vim.org>
parents: 23719
diff changeset
3047 if (throw_exception(tv->vval.v_string, ET_USER, NULL)
f98692ae09a0 patch 8.2.2404: Vim9: profiling try/catch not correct
Bram Moolenaar <Bram@vim.org>
parents: 23719
diff changeset
3048 == FAIL)
f98692ae09a0 patch 8.2.2404: Vim9: profiling try/catch not correct
Bram Moolenaar <Bram@vim.org>
parents: 23719
diff changeset
3049 {
f98692ae09a0 patch 8.2.2404: Vim9: profiling try/catch not correct
Bram Moolenaar <Bram@vim.org>
parents: 23719
diff changeset
3050 vim_free(tv->vval.v_string);
24488
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
3051 return FAIL;
23725
f98692ae09a0 patch 8.2.2404: Vim9: profiling try/catch not correct
Bram Moolenaar <Bram@vim.org>
parents: 23719
diff changeset
3052 }
f98692ae09a0 patch 8.2.2404: Vim9: profiling try/catch not correct
Bram Moolenaar <Bram@vim.org>
parents: 23719
diff changeset
3053 did_throw = TRUE;
23618
d228ca435f3a patch 8.2.2351: Vim9: error msg for "throw" in function called with "silent!"
Bram Moolenaar <Bram@vim.org>
parents: 23604
diff changeset
3054 }
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3055 break;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3056
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3057 // compare with special values
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3058 case ISN_COMPAREBOOL:
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3059 case ISN_COMPARESPECIAL:
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3060 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3061 typval_T *tv1 = STACK_TV_BOT(-2);
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3062 typval_T *tv2 = STACK_TV_BOT(-1);
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3063 varnumber_T arg1 = tv1->vval.v_number;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3064 varnumber_T arg2 = tv2->vval.v_number;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3065 int res;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3066
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3067 switch (iptr->isn_arg.op.op_type)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3068 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3069 case EXPR_EQUAL: res = arg1 == arg2; break;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3070 case EXPR_NEQUAL: res = arg1 != arg2; break;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3071 default: res = 0; break;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3072 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3073
24488
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
3074 --ectx->ec_stack.ga_len;
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3075 tv1->v_type = VAR_BOOL;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3076 tv1->vval.v_number = res ? VVAL_TRUE : VVAL_FALSE;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3077 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3078 break;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3079
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3080 // Operation with two number arguments
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3081 case ISN_OPNR:
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3082 case ISN_COMPARENR:
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3083 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3084 typval_T *tv1 = STACK_TV_BOT(-2);
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3085 typval_T *tv2 = STACK_TV_BOT(-1);
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3086 varnumber_T arg1 = tv1->vval.v_number;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3087 varnumber_T arg2 = tv2->vval.v_number;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3088 varnumber_T res;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3089
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3090 switch (iptr->isn_arg.op.op_type)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3091 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3092 case EXPR_MULT: res = arg1 * arg2; break;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3093 case EXPR_DIV: res = arg1 / arg2; break;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3094 case EXPR_REM: res = arg1 % arg2; break;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3095 case EXPR_SUB: res = arg1 - arg2; break;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3096 case EXPR_ADD: res = arg1 + arg2; break;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3097
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3098 case EXPR_EQUAL: res = arg1 == arg2; break;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3099 case EXPR_NEQUAL: res = arg1 != arg2; break;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3100 case EXPR_GREATER: res = arg1 > arg2; break;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3101 case EXPR_GEQUAL: res = arg1 >= arg2; break;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3102 case EXPR_SMALLER: res = arg1 < arg2; break;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3103 case EXPR_SEQUAL: res = arg1 <= arg2; break;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3104 default: res = 0; break;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3105 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3106
24488
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
3107 --ectx->ec_stack.ga_len;
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3108 if (iptr->isn_type == ISN_COMPARENR)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3109 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3110 tv1->v_type = VAR_BOOL;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3111 tv1->vval.v_number = res ? VVAL_TRUE : VVAL_FALSE;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3112 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3113 else
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3114 tv1->vval.v_number = res;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3115 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3116 break;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3117
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3118 // Computation with two float arguments
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3119 case ISN_OPFLOAT:
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3120 case ISN_COMPAREFLOAT:
19193
9f98957582d6 patch 8.2.0155: warnings from MinGW compiler; tests fail without +float
Bram Moolenaar <Bram@vim.org>
parents: 19191
diff changeset
3121 #ifdef FEAT_FLOAT
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3122 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3123 typval_T *tv1 = STACK_TV_BOT(-2);
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3124 typval_T *tv2 = STACK_TV_BOT(-1);
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3125 float_T arg1 = tv1->vval.v_float;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3126 float_T arg2 = tv2->vval.v_float;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3127 float_T res = 0;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3128 int cmp = FALSE;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3129
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3130 switch (iptr->isn_arg.op.op_type)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3131 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3132 case EXPR_MULT: res = arg1 * arg2; break;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3133 case EXPR_DIV: res = arg1 / arg2; break;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3134 case EXPR_SUB: res = arg1 - arg2; break;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3135 case EXPR_ADD: res = arg1 + arg2; break;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3136
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3137 case EXPR_EQUAL: cmp = arg1 == arg2; break;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3138 case EXPR_NEQUAL: cmp = arg1 != arg2; break;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3139 case EXPR_GREATER: cmp = arg1 > arg2; break;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3140 case EXPR_GEQUAL: cmp = arg1 >= arg2; break;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3141 case EXPR_SMALLER: cmp = arg1 < arg2; break;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3142 case EXPR_SEQUAL: cmp = arg1 <= arg2; break;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3143 default: cmp = 0; break;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3144 }
24488
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
3145 --ectx->ec_stack.ga_len;
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3146 if (iptr->isn_type == ISN_COMPAREFLOAT)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3147 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3148 tv1->v_type = VAR_BOOL;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3149 tv1->vval.v_number = cmp ? VVAL_TRUE : VVAL_FALSE;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3150 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3151 else
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3152 tv1->vval.v_float = res;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3153 }
19193
9f98957582d6 patch 8.2.0155: warnings from MinGW compiler; tests fail without +float
Bram Moolenaar <Bram@vim.org>
parents: 19191
diff changeset
3154 #endif
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3155 break;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3156
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3157 case ISN_COMPARELIST:
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3158 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3159 typval_T *tv1 = STACK_TV_BOT(-2);
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3160 typval_T *tv2 = STACK_TV_BOT(-1);
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3161 list_T *arg1 = tv1->vval.v_list;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3162 list_T *arg2 = tv2->vval.v_list;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3163 int cmp = FALSE;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3164 int ic = iptr->isn_arg.op.op_ic;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3165
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3166 switch (iptr->isn_arg.op.op_type)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3167 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3168 case EXPR_EQUAL: cmp =
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3169 list_equal(arg1, arg2, ic, FALSE); break;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3170 case EXPR_NEQUAL: cmp =
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3171 !list_equal(arg1, arg2, ic, FALSE); break;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3172 case EXPR_IS: cmp = arg1 == arg2; break;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3173 case EXPR_ISNOT: cmp = arg1 != arg2; break;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3174 default: cmp = 0; break;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3175 }
24488
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
3176 --ectx->ec_stack.ga_len;
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3177 clear_tv(tv1);
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3178 clear_tv(tv2);
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3179 tv1->v_type = VAR_BOOL;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3180 tv1->vval.v_number = cmp ? VVAL_TRUE : VVAL_FALSE;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3181 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3182 break;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3183
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3184 case ISN_COMPAREBLOB:
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3185 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3186 typval_T *tv1 = STACK_TV_BOT(-2);
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3187 typval_T *tv2 = STACK_TV_BOT(-1);
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3188 blob_T *arg1 = tv1->vval.v_blob;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3189 blob_T *arg2 = tv2->vval.v_blob;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3190 int cmp = FALSE;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3191
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3192 switch (iptr->isn_arg.op.op_type)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3193 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3194 case EXPR_EQUAL: cmp = blob_equal(arg1, arg2); break;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3195 case EXPR_NEQUAL: cmp = !blob_equal(arg1, arg2); break;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3196 case EXPR_IS: cmp = arg1 == arg2; break;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3197 case EXPR_ISNOT: cmp = arg1 != arg2; break;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3198 default: cmp = 0; break;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3199 }
24488
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
3200 --ectx->ec_stack.ga_len;
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3201 clear_tv(tv1);
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3202 clear_tv(tv2);
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3203 tv1->v_type = VAR_BOOL;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3204 tv1->vval.v_number = cmp ? VVAL_TRUE : VVAL_FALSE;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3205 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3206 break;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3207
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3208 // TODO: handle separately
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3209 case ISN_COMPARESTRING:
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3210 case ISN_COMPAREDICT:
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3211 case ISN_COMPAREFUNC:
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3212 case ISN_COMPAREANY:
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3213 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3214 typval_T *tv1 = STACK_TV_BOT(-2);
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3215 typval_T *tv2 = STACK_TV_BOT(-1);
23553
5c094273c015 patch 8.2.2319: "exptype_T" can be read as "expected type"
Bram Moolenaar <Bram@vim.org>
parents: 23551
diff changeset
3216 exprtype_T exprtype = iptr->isn_arg.op.op_type;
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3217 int ic = iptr->isn_arg.op.op_ic;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3218
22262
3f082bd15d29 patch 8.2.1680: Vim9: line number for compare error is wrong
Bram Moolenaar <Bram@vim.org>
parents: 22238
diff changeset
3219 SOURCING_LNUM = iptr->isn_lnum;
23553
5c094273c015 patch 8.2.2319: "exptype_T" can be read as "expected type"
Bram Moolenaar <Bram@vim.org>
parents: 23551
diff changeset
3220 typval_compare(tv1, tv2, exprtype, ic);
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3221 clear_tv(tv2);
24488
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
3222 --ectx->ec_stack.ga_len;
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3223 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3224 break;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3225
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3226 case ISN_ADDLIST:
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3227 case ISN_ADDBLOB:
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3228 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3229 typval_T *tv1 = STACK_TV_BOT(-2);
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3230 typval_T *tv2 = STACK_TV_BOT(-1);
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3231
22633
6589dae9696c patch 8.2.1865: Vim9: add() does not check type of argument
Bram Moolenaar <Bram@vim.org>
parents: 22623
diff changeset
3232 // add two lists or blobs
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3233 if (iptr->isn_type == ISN_ADDLIST)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3234 eval_addlist(tv1, tv2);
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3235 else
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3236 eval_addblob(tv1, tv2);
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3237 clear_tv(tv2);
24488
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
3238 --ectx->ec_stack.ga_len;
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3239 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3240 break;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3241
22633
6589dae9696c patch 8.2.1865: Vim9: add() does not check type of argument
Bram Moolenaar <Bram@vim.org>
parents: 22623
diff changeset
3242 case ISN_LISTAPPEND:
6589dae9696c patch 8.2.1865: Vim9: add() does not check type of argument
Bram Moolenaar <Bram@vim.org>
parents: 22623
diff changeset
3243 {
6589dae9696c patch 8.2.1865: Vim9: add() does not check type of argument
Bram Moolenaar <Bram@vim.org>
parents: 22623
diff changeset
3244 typval_T *tv1 = STACK_TV_BOT(-2);
6589dae9696c patch 8.2.1865: Vim9: add() does not check type of argument
Bram Moolenaar <Bram@vim.org>
parents: 22623
diff changeset
3245 typval_T *tv2 = STACK_TV_BOT(-1);
6589dae9696c patch 8.2.1865: Vim9: add() does not check type of argument
Bram Moolenaar <Bram@vim.org>
parents: 22623
diff changeset
3246 list_T *l = tv1->vval.v_list;
6589dae9696c patch 8.2.1865: Vim9: add() does not check type of argument
Bram Moolenaar <Bram@vim.org>
parents: 22623
diff changeset
3247
6589dae9696c patch 8.2.1865: Vim9: add() does not check type of argument
Bram Moolenaar <Bram@vim.org>
parents: 22623
diff changeset
3248 // add an item to a list
6589dae9696c patch 8.2.1865: Vim9: add() does not check type of argument
Bram Moolenaar <Bram@vim.org>
parents: 22623
diff changeset
3249 if (l == NULL)
6589dae9696c patch 8.2.1865: Vim9: add() does not check type of argument
Bram Moolenaar <Bram@vim.org>
parents: 22623
diff changeset
3250 {
6589dae9696c patch 8.2.1865: Vim9: add() does not check type of argument
Bram Moolenaar <Bram@vim.org>
parents: 22623
diff changeset
3251 SOURCING_LNUM = iptr->isn_lnum;
6589dae9696c patch 8.2.1865: Vim9: add() does not check type of argument
Bram Moolenaar <Bram@vim.org>
parents: 22623
diff changeset
3252 emsg(_(e_cannot_add_to_null_list));
6589dae9696c patch 8.2.1865: Vim9: add() does not check type of argument
Bram Moolenaar <Bram@vim.org>
parents: 22623
diff changeset
3253 goto on_error;
6589dae9696c patch 8.2.1865: Vim9: add() does not check type of argument
Bram Moolenaar <Bram@vim.org>
parents: 22623
diff changeset
3254 }
6589dae9696c patch 8.2.1865: Vim9: add() does not check type of argument
Bram Moolenaar <Bram@vim.org>
parents: 22623
diff changeset
3255 if (list_append_tv(l, tv2) == FAIL)
24488
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
3256 return FAIL;
22641
6dce588f7a46 patch 8.2.1869: Vim9: memory leak when using add()
Bram Moolenaar <Bram@vim.org>
parents: 22637
diff changeset
3257 clear_tv(tv2);
24488
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
3258 --ectx->ec_stack.ga_len;
22633
6589dae9696c patch 8.2.1865: Vim9: add() does not check type of argument
Bram Moolenaar <Bram@vim.org>
parents: 22623
diff changeset
3259 }
6589dae9696c patch 8.2.1865: Vim9: add() does not check type of argument
Bram Moolenaar <Bram@vim.org>
parents: 22623
diff changeset
3260 break;
6589dae9696c patch 8.2.1865: Vim9: add() does not check type of argument
Bram Moolenaar <Bram@vim.org>
parents: 22623
diff changeset
3261
22637
4d4042683371 patch 8.2.1867: Vim9: argument to add() not checked for blob
Bram Moolenaar <Bram@vim.org>
parents: 22633
diff changeset
3262 case ISN_BLOBAPPEND:
4d4042683371 patch 8.2.1867: Vim9: argument to add() not checked for blob
Bram Moolenaar <Bram@vim.org>
parents: 22633
diff changeset
3263 {
4d4042683371 patch 8.2.1867: Vim9: argument to add() not checked for blob
Bram Moolenaar <Bram@vim.org>
parents: 22633
diff changeset
3264 typval_T *tv1 = STACK_TV_BOT(-2);
4d4042683371 patch 8.2.1867: Vim9: argument to add() not checked for blob
Bram Moolenaar <Bram@vim.org>
parents: 22633
diff changeset
3265 typval_T *tv2 = STACK_TV_BOT(-1);
4d4042683371 patch 8.2.1867: Vim9: argument to add() not checked for blob
Bram Moolenaar <Bram@vim.org>
parents: 22633
diff changeset
3266 blob_T *b = tv1->vval.v_blob;
4d4042683371 patch 8.2.1867: Vim9: argument to add() not checked for blob
Bram Moolenaar <Bram@vim.org>
parents: 22633
diff changeset
3267 int error = FALSE;
4d4042683371 patch 8.2.1867: Vim9: argument to add() not checked for blob
Bram Moolenaar <Bram@vim.org>
parents: 22633
diff changeset
3268 varnumber_T n;
4d4042683371 patch 8.2.1867: Vim9: argument to add() not checked for blob
Bram Moolenaar <Bram@vim.org>
parents: 22633
diff changeset
3269
4d4042683371 patch 8.2.1867: Vim9: argument to add() not checked for blob
Bram Moolenaar <Bram@vim.org>
parents: 22633
diff changeset
3270 // add a number to a blob
4d4042683371 patch 8.2.1867: Vim9: argument to add() not checked for blob
Bram Moolenaar <Bram@vim.org>
parents: 22633
diff changeset
3271 if (b == NULL)
4d4042683371 patch 8.2.1867: Vim9: argument to add() not checked for blob
Bram Moolenaar <Bram@vim.org>
parents: 22633
diff changeset
3272 {
4d4042683371 patch 8.2.1867: Vim9: argument to add() not checked for blob
Bram Moolenaar <Bram@vim.org>
parents: 22633
diff changeset
3273 SOURCING_LNUM = iptr->isn_lnum;
4d4042683371 patch 8.2.1867: Vim9: argument to add() not checked for blob
Bram Moolenaar <Bram@vim.org>
parents: 22633
diff changeset
3274 emsg(_(e_cannot_add_to_null_blob));
4d4042683371 patch 8.2.1867: Vim9: argument to add() not checked for blob
Bram Moolenaar <Bram@vim.org>
parents: 22633
diff changeset
3275 goto on_error;
4d4042683371 patch 8.2.1867: Vim9: argument to add() not checked for blob
Bram Moolenaar <Bram@vim.org>
parents: 22633
diff changeset
3276 }
4d4042683371 patch 8.2.1867: Vim9: argument to add() not checked for blob
Bram Moolenaar <Bram@vim.org>
parents: 22633
diff changeset
3277 n = tv_get_number_chk(tv2, &error);
4d4042683371 patch 8.2.1867: Vim9: argument to add() not checked for blob
Bram Moolenaar <Bram@vim.org>
parents: 22633
diff changeset
3278 if (error)
4d4042683371 patch 8.2.1867: Vim9: argument to add() not checked for blob
Bram Moolenaar <Bram@vim.org>
parents: 22633
diff changeset
3279 goto on_error;
4d4042683371 patch 8.2.1867: Vim9: argument to add() not checked for blob
Bram Moolenaar <Bram@vim.org>
parents: 22633
diff changeset
3280 ga_append(&b->bv_ga, (int)n);
24488
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
3281 --ectx->ec_stack.ga_len;
22637
4d4042683371 patch 8.2.1867: Vim9: argument to add() not checked for blob
Bram Moolenaar <Bram@vim.org>
parents: 22633
diff changeset
3282 }
4d4042683371 patch 8.2.1867: Vim9: argument to add() not checked for blob
Bram Moolenaar <Bram@vim.org>
parents: 22633
diff changeset
3283 break;
4d4042683371 patch 8.2.1867: Vim9: argument to add() not checked for blob
Bram Moolenaar <Bram@vim.org>
parents: 22633
diff changeset
3284
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3285 // Computation with two arguments of unknown type
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3286 case ISN_OPANY:
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3287 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3288 typval_T *tv1 = STACK_TV_BOT(-2);
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3289 typval_T *tv2 = STACK_TV_BOT(-1);
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3290 varnumber_T n1, n2;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3291 #ifdef FEAT_FLOAT
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3292 float_T f1 = 0, f2 = 0;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3293 #endif
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3294 int error = FALSE;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3295
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3296 if (iptr->isn_arg.op.op_type == EXPR_ADD)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3297 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3298 if (tv1->v_type == VAR_LIST && tv2->v_type == VAR_LIST)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3299 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3300 eval_addlist(tv1, tv2);
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3301 clear_tv(tv2);
24488
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
3302 --ectx->ec_stack.ga_len;
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3303 break;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3304 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3305 else if (tv1->v_type == VAR_BLOB
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3306 && tv2->v_type == VAR_BLOB)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3307 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3308 eval_addblob(tv1, tv2);
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3309 clear_tv(tv2);
24488
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
3310 --ectx->ec_stack.ga_len;
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3311 break;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3312 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3313 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3314 #ifdef FEAT_FLOAT
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3315 if (tv1->v_type == VAR_FLOAT)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3316 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3317 f1 = tv1->vval.v_float;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3318 n1 = 0;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3319 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3320 else
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3321 #endif
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3322 {
23100
9c3a6c33c0e5 patch 8.2.2096: Vim9: command modifiers not restored after assignment
Bram Moolenaar <Bram@vim.org>
parents: 23098
diff changeset
3323 SOURCING_LNUM = iptr->isn_lnum;
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3324 n1 = tv_get_number_chk(tv1, &error);
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3325 if (error)
21375
92e2ed2a2778 patch 8.2.1238: Vim9: a few remaining errors not caught by try/catch
Bram Moolenaar <Bram@vim.org>
parents: 21371
diff changeset
3326 goto on_error;
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3327 #ifdef FEAT_FLOAT
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3328 if (tv2->v_type == VAR_FLOAT)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3329 f1 = n1;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3330 #endif
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3331 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3332 #ifdef FEAT_FLOAT
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3333 if (tv2->v_type == VAR_FLOAT)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3334 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3335 f2 = tv2->vval.v_float;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3336 n2 = 0;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3337 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3338 else
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3339 #endif
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3340 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3341 n2 = tv_get_number_chk(tv2, &error);
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3342 if (error)
21375
92e2ed2a2778 patch 8.2.1238: Vim9: a few remaining errors not caught by try/catch
Bram Moolenaar <Bram@vim.org>
parents: 21371
diff changeset
3343 goto on_error;
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3344 #ifdef FEAT_FLOAT
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3345 if (tv1->v_type == VAR_FLOAT)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3346 f2 = n2;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3347 #endif
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3348 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3349 #ifdef FEAT_FLOAT
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3350 // if there is a float on either side the result is a float
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3351 if (tv1->v_type == VAR_FLOAT || tv2->v_type == VAR_FLOAT)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3352 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3353 switch (iptr->isn_arg.op.op_type)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3354 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3355 case EXPR_MULT: f1 = f1 * f2; break;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3356 case EXPR_DIV: f1 = f1 / f2; break;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3357 case EXPR_SUB: f1 = f1 - f2; break;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3358 case EXPR_ADD: f1 = f1 + f2; break;
21793
0706bd071fa3 patch 8.2.1446: Vim9: line number in error message is not correct
Bram Moolenaar <Bram@vim.org>
parents: 21789
diff changeset
3359 default: SOURCING_LNUM = iptr->isn_lnum;
0706bd071fa3 patch 8.2.1446: Vim9: line number in error message is not correct
Bram Moolenaar <Bram@vim.org>
parents: 21789
diff changeset
3360 emsg(_(e_modulus));
21365
fca850f4d603 patch 8.2.1233: Vim9: various errors not caught by try/catch
Bram Moolenaar <Bram@vim.org>
parents: 21359
diff changeset
3361 goto on_error;
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3362 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3363 clear_tv(tv1);
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3364 clear_tv(tv2);
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3365 tv1->v_type = VAR_FLOAT;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3366 tv1->vval.v_float = f1;
24488
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
3367 --ectx->ec_stack.ga_len;
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3368 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3369 else
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3370 #endif
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3371 {
23681
423af0f7beae patch 8.2.2382: build failure
Bram Moolenaar <Bram@vim.org>
parents: 23673
diff changeset
3372 int failed = FALSE;
423af0f7beae patch 8.2.2382: build failure
Bram Moolenaar <Bram@vim.org>
parents: 23673
diff changeset
3373
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3374 switch (iptr->isn_arg.op.op_type)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3375 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3376 case EXPR_MULT: n1 = n1 * n2; break;
23681
423af0f7beae patch 8.2.2382: build failure
Bram Moolenaar <Bram@vim.org>
parents: 23673
diff changeset
3377 case EXPR_DIV: n1 = num_divide(n1, n2, &failed);
423af0f7beae patch 8.2.2382: build failure
Bram Moolenaar <Bram@vim.org>
parents: 23673
diff changeset
3378 if (failed)
23673
6d35bc0f161e patch 8.2.2378: Vim9: no error message for dividing by zero
Bram Moolenaar <Bram@vim.org>
parents: 23671
diff changeset
3379 goto on_error;
6d35bc0f161e patch 8.2.2378: Vim9: no error message for dividing by zero
Bram Moolenaar <Bram@vim.org>
parents: 23671
diff changeset
3380 break;
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3381 case EXPR_SUB: n1 = n1 - n2; break;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3382 case EXPR_ADD: n1 = n1 + n2; break;
23681
423af0f7beae patch 8.2.2382: build failure
Bram Moolenaar <Bram@vim.org>
parents: 23673
diff changeset
3383 default: n1 = num_modulus(n1, n2, &failed);
423af0f7beae patch 8.2.2382: build failure
Bram Moolenaar <Bram@vim.org>
parents: 23673
diff changeset
3384 if (failed)
23673
6d35bc0f161e patch 8.2.2378: Vim9: no error message for dividing by zero
Bram Moolenaar <Bram@vim.org>
parents: 23671
diff changeset
3385 goto on_error;
6d35bc0f161e patch 8.2.2378: Vim9: no error message for dividing by zero
Bram Moolenaar <Bram@vim.org>
parents: 23671
diff changeset
3386 break;
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3387 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3388 clear_tv(tv1);
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3389 clear_tv(tv2);
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3390 tv1->v_type = VAR_NUMBER;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3391 tv1->vval.v_number = n1;
24488
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
3392 --ectx->ec_stack.ga_len;
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3393 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3394 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3395 break;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3396
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3397 case ISN_CONCAT:
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3398 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3399 char_u *str1 = STACK_TV_BOT(-2)->vval.v_string;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3400 char_u *str2 = STACK_TV_BOT(-1)->vval.v_string;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3401 char_u *res;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3402
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3403 res = concat_str(str1, str2);
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3404 clear_tv(STACK_TV_BOT(-2));
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3405 clear_tv(STACK_TV_BOT(-1));
24488
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
3406 --ectx->ec_stack.ga_len;
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3407 STACK_TV_BOT(-1)->vval.v_string = res;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3408 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3409 break;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3410
21393
320581a133d9 patch 8.2.1247: Vim9: cannot index a character in a string
Bram Moolenaar <Bram@vim.org>
parents: 21383
diff changeset
3411 case ISN_STRINDEX:
21826
ccad66ac6c3e patch 8.2.1462: Vim9: string slice not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 21823
diff changeset
3412 case ISN_STRSLICE:
21393
320581a133d9 patch 8.2.1247: Vim9: cannot index a character in a string
Bram Moolenaar <Bram@vim.org>
parents: 21383
diff changeset
3413 {
21826
ccad66ac6c3e patch 8.2.1462: Vim9: string slice not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 21823
diff changeset
3414 int is_slice = iptr->isn_type == ISN_STRSLICE;
ccad66ac6c3e patch 8.2.1462: Vim9: string slice not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 21823
diff changeset
3415 varnumber_T n1 = 0, n2;
21393
320581a133d9 patch 8.2.1247: Vim9: cannot index a character in a string
Bram Moolenaar <Bram@vim.org>
parents: 21383
diff changeset
3416 char_u *res;
320581a133d9 patch 8.2.1247: Vim9: cannot index a character in a string
Bram Moolenaar <Bram@vim.org>
parents: 21383
diff changeset
3417
320581a133d9 patch 8.2.1247: Vim9: cannot index a character in a string
Bram Moolenaar <Bram@vim.org>
parents: 21383
diff changeset
3418 // string index: string is at stack-2, index at stack-1
21826
ccad66ac6c3e patch 8.2.1462: Vim9: string slice not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 21823
diff changeset
3419 // string slice: string is at stack-3, first index at
ccad66ac6c3e patch 8.2.1462: Vim9: string slice not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 21823
diff changeset
3420 // stack-2, second index at stack-1
ccad66ac6c3e patch 8.2.1462: Vim9: string slice not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 21823
diff changeset
3421 if (is_slice)
ccad66ac6c3e patch 8.2.1462: Vim9: string slice not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 21823
diff changeset
3422 {
ccad66ac6c3e patch 8.2.1462: Vim9: string slice not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 21823
diff changeset
3423 tv = STACK_TV_BOT(-2);
ccad66ac6c3e patch 8.2.1462: Vim9: string slice not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 21823
diff changeset
3424 n1 = tv->vval.v_number;
ccad66ac6c3e patch 8.2.1462: Vim9: string slice not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 21823
diff changeset
3425 }
ccad66ac6c3e patch 8.2.1462: Vim9: string slice not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 21823
diff changeset
3426
21393
320581a133d9 patch 8.2.1247: Vim9: cannot index a character in a string
Bram Moolenaar <Bram@vim.org>
parents: 21383
diff changeset
3427 tv = STACK_TV_BOT(-1);
21826
ccad66ac6c3e patch 8.2.1462: Vim9: string slice not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 21823
diff changeset
3428 n2 = tv->vval.v_number;
ccad66ac6c3e patch 8.2.1462: Vim9: string slice not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 21823
diff changeset
3429
24488
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
3430 ectx->ec_stack.ga_len -= is_slice ? 2 : 1;
21393
320581a133d9 patch 8.2.1247: Vim9: cannot index a character in a string
Bram Moolenaar <Bram@vim.org>
parents: 21383
diff changeset
3431 tv = STACK_TV_BOT(-1);
21826
ccad66ac6c3e patch 8.2.1462: Vim9: string slice not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 21823
diff changeset
3432 if (is_slice)
ccad66ac6c3e patch 8.2.1462: Vim9: string slice not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 21823
diff changeset
3433 // Slice: Select the characters from the string
23604
1816ea68c022 patch 8.2.2344: using inclusive index for slice is not always desired
Bram Moolenaar <Bram@vim.org>
parents: 23582
diff changeset
3434 res = string_slice(tv->vval.v_string, n1, n2, FALSE);
21826
ccad66ac6c3e patch 8.2.1462: Vim9: string slice not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 21823
diff changeset
3435 else
ccad66ac6c3e patch 8.2.1462: Vim9: string slice not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 21823
diff changeset
3436 // Index: The resulting variable is a string of a
24128
fcbb1d4df15b patch 8.2.2605: Vim9: string index and slice does not include composing chars
Bram Moolenaar <Bram@vim.org>
parents: 24122
diff changeset
3437 // single character (including composing characters).
fcbb1d4df15b patch 8.2.2605: Vim9: string index and slice does not include composing chars
Bram Moolenaar <Bram@vim.org>
parents: 24122
diff changeset
3438 // If the index is too big or negative the result is
fcbb1d4df15b patch 8.2.2605: Vim9: string index and slice does not include composing chars
Bram Moolenaar <Bram@vim.org>
parents: 24122
diff changeset
3439 // empty.
21826
ccad66ac6c3e patch 8.2.1462: Vim9: string slice not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 21823
diff changeset
3440 res = char_from_string(tv->vval.v_string, n2);
21393
320581a133d9 patch 8.2.1247: Vim9: cannot index a character in a string
Bram Moolenaar <Bram@vim.org>
parents: 21383
diff changeset
3441 vim_free(tv->vval.v_string);
320581a133d9 patch 8.2.1247: Vim9: cannot index a character in a string
Bram Moolenaar <Bram@vim.org>
parents: 21383
diff changeset
3442 tv->vval.v_string = res;
320581a133d9 patch 8.2.1247: Vim9: cannot index a character in a string
Bram Moolenaar <Bram@vim.org>
parents: 21383
diff changeset
3443 }
320581a133d9 patch 8.2.1247: Vim9: cannot index a character in a string
Bram Moolenaar <Bram@vim.org>
parents: 21383
diff changeset
3444 break;
320581a133d9 patch 8.2.1247: Vim9: cannot index a character in a string
Bram Moolenaar <Bram@vim.org>
parents: 21383
diff changeset
3445
320581a133d9 patch 8.2.1247: Vim9: cannot index a character in a string
Bram Moolenaar <Bram@vim.org>
parents: 21383
diff changeset
3446 case ISN_LISTINDEX:
21828
af5db9b6d210 patch 8.2.1463: Vim9: list slice not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 21826
diff changeset
3447 case ISN_LISTSLICE:
24432
aa150abca273 patch 8.2.2756: Vim9: blob index and slice not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 24416
diff changeset
3448 case ISN_BLOBINDEX:
aa150abca273 patch 8.2.2756: Vim9: blob index and slice not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 24416
diff changeset
3449 case ISN_BLOBSLICE:
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3450 {
24432
aa150abca273 patch 8.2.2756: Vim9: blob index and slice not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 24416
diff changeset
3451 int is_slice = iptr->isn_type == ISN_LISTSLICE
aa150abca273 patch 8.2.2756: Vim9: blob index and slice not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 24416
diff changeset
3452 || iptr->isn_type == ISN_BLOBSLICE;
aa150abca273 patch 8.2.2756: Vim9: blob index and slice not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 24416
diff changeset
3453 int is_blob = iptr->isn_type == ISN_BLOBINDEX
aa150abca273 patch 8.2.2756: Vim9: blob index and slice not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 24416
diff changeset
3454 || iptr->isn_type == ISN_BLOBSLICE;
21828
af5db9b6d210 patch 8.2.1463: Vim9: list slice not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 21826
diff changeset
3455 varnumber_T n1, n2;
24432
aa150abca273 patch 8.2.2756: Vim9: blob index and slice not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 24416
diff changeset
3456 typval_T *val_tv;
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3457
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3458 // list index: list is at stack-2, index at stack-1
21828
af5db9b6d210 patch 8.2.1463: Vim9: list slice not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 21826
diff changeset
3459 // list slice: list is at stack-3, indexes at stack-2 and
af5db9b6d210 patch 8.2.1463: Vim9: list slice not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 21826
diff changeset
3460 // stack-1
24432
aa150abca273 patch 8.2.2756: Vim9: blob index and slice not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 24416
diff changeset
3461 // Same for blob.
aa150abca273 patch 8.2.2756: Vim9: blob index and slice not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 24416
diff changeset
3462 val_tv = is_slice ? STACK_TV_BOT(-3) : STACK_TV_BOT(-2);
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3463
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3464 tv = STACK_TV_BOT(-1);
21828
af5db9b6d210 patch 8.2.1463: Vim9: list slice not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 21826
diff changeset
3465 n1 = n2 = tv->vval.v_number;
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3466 clear_tv(tv);
21828
af5db9b6d210 patch 8.2.1463: Vim9: list slice not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 21826
diff changeset
3467
af5db9b6d210 patch 8.2.1463: Vim9: list slice not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 21826
diff changeset
3468 if (is_slice)
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3469 {
21828
af5db9b6d210 patch 8.2.1463: Vim9: list slice not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 21826
diff changeset
3470 tv = STACK_TV_BOT(-2);
af5db9b6d210 patch 8.2.1463: Vim9: list slice not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 21826
diff changeset
3471 n1 = tv->vval.v_number;
af5db9b6d210 patch 8.2.1463: Vim9: list slice not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 21826
diff changeset
3472 clear_tv(tv);
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3473 }
21828
af5db9b6d210 patch 8.2.1463: Vim9: list slice not supported yet
Bram Moolenaar <Bram@vim.org>
parents: 21826
diff changeset
3474
24488
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
3475 ectx->ec_stack.ga_len -= is_slice ? 2 : 1;
21166
64f664f9b23a patch 8.2.1134: Vim9: getting a list member may not work
Bram Moolenaar <Bram@vim.org>
parents: 21152
diff changeset
3476 tv = STACK_TV_BOT(-1);
21859
3e5d0832a2e7 patch 8.2.1479: Vim9: error for list index uses wrong line number
Bram Moolenaar <Bram@vim.org>
parents: 21835
diff changeset
3477 SOURCING_LNUM = iptr->isn_lnum;
24432
aa150abca273 patch 8.2.2756: Vim9: blob index and slice not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 24416
diff changeset
3478 if (is_blob)
aa150abca273 patch 8.2.2756: Vim9: blob index and slice not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 24416
diff changeset
3479 {
aa150abca273 patch 8.2.2756: Vim9: blob index and slice not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 24416
diff changeset
3480 if (blob_slice_or_index(val_tv->vval.v_blob, is_slice,
aa150abca273 patch 8.2.2756: Vim9: blob index and slice not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 24416
diff changeset
3481 n1, n2, FALSE, tv) == FAIL)
aa150abca273 patch 8.2.2756: Vim9: blob index and slice not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 24416
diff changeset
3482 goto on_error;
aa150abca273 patch 8.2.2756: Vim9: blob index and slice not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 24416
diff changeset
3483 }
aa150abca273 patch 8.2.2756: Vim9: blob index and slice not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 24416
diff changeset
3484 else
aa150abca273 patch 8.2.2756: Vim9: blob index and slice not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 24416
diff changeset
3485 {
aa150abca273 patch 8.2.2756: Vim9: blob index and slice not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 24416
diff changeset
3486 if (list_slice_or_index(val_tv->vval.v_list, is_slice,
aa150abca273 patch 8.2.2756: Vim9: blob index and slice not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 24416
diff changeset
3487 n1, n2, FALSE, tv, TRUE) == FAIL)
aa150abca273 patch 8.2.2756: Vim9: blob index and slice not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 24416
diff changeset
3488 goto on_error;
aa150abca273 patch 8.2.2756: Vim9: blob index and slice not implemented yet
Bram Moolenaar <Bram@vim.org>
parents: 24416
diff changeset
3489 }
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3490 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3491 break;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3492
21833
e3f9528bddda patch 8.2.1466: Vim9: cannot index or slice a variable with type "any"
Bram Moolenaar <Bram@vim.org>
parents: 21831
diff changeset
3493 case ISN_ANYINDEX:
e3f9528bddda patch 8.2.1466: Vim9: cannot index or slice a variable with type "any"
Bram Moolenaar <Bram@vim.org>
parents: 21831
diff changeset
3494 case ISN_ANYSLICE:
e3f9528bddda patch 8.2.1466: Vim9: cannot index or slice a variable with type "any"
Bram Moolenaar <Bram@vim.org>
parents: 21831
diff changeset
3495 {
e3f9528bddda patch 8.2.1466: Vim9: cannot index or slice a variable with type "any"
Bram Moolenaar <Bram@vim.org>
parents: 21831
diff changeset
3496 int is_slice = iptr->isn_type == ISN_ANYSLICE;
e3f9528bddda patch 8.2.1466: Vim9: cannot index or slice a variable with type "any"
Bram Moolenaar <Bram@vim.org>
parents: 21831
diff changeset
3497 typval_T *var1, *var2;
e3f9528bddda patch 8.2.1466: Vim9: cannot index or slice a variable with type "any"
Bram Moolenaar <Bram@vim.org>
parents: 21831
diff changeset
3498 int res;
e3f9528bddda patch 8.2.1466: Vim9: cannot index or slice a variable with type "any"
Bram Moolenaar <Bram@vim.org>
parents: 21831
diff changeset
3499
e3f9528bddda patch 8.2.1466: Vim9: cannot index or slice a variable with type "any"
Bram Moolenaar <Bram@vim.org>
parents: 21831
diff changeset
3500 // index: composite is at stack-2, index at stack-1
e3f9528bddda patch 8.2.1466: Vim9: cannot index or slice a variable with type "any"
Bram Moolenaar <Bram@vim.org>
parents: 21831
diff changeset
3501 // slice: composite is at stack-3, indexes at stack-2 and
e3f9528bddda patch 8.2.1466: Vim9: cannot index or slice a variable with type "any"
Bram Moolenaar <Bram@vim.org>
parents: 21831
diff changeset
3502 // stack-1
e3f9528bddda patch 8.2.1466: Vim9: cannot index or slice a variable with type "any"
Bram Moolenaar <Bram@vim.org>
parents: 21831
diff changeset
3503 tv = is_slice ? STACK_TV_BOT(-3) : STACK_TV_BOT(-2);
21863
809b1e7fbd72 patch 8.2.1481: Vim9: line number reported with error may be wrong
Bram Moolenaar <Bram@vim.org>
parents: 21859
diff changeset
3504 SOURCING_LNUM = iptr->isn_lnum;
21833
e3f9528bddda patch 8.2.1466: Vim9: cannot index or slice a variable with type "any"
Bram Moolenaar <Bram@vim.org>
parents: 21831
diff changeset
3505 if (check_can_index(tv, TRUE, TRUE) == FAIL)
e3f9528bddda patch 8.2.1466: Vim9: cannot index or slice a variable with type "any"
Bram Moolenaar <Bram@vim.org>
parents: 21831
diff changeset
3506 goto on_error;
e3f9528bddda patch 8.2.1466: Vim9: cannot index or slice a variable with type "any"
Bram Moolenaar <Bram@vim.org>
parents: 21831
diff changeset
3507 var1 = is_slice ? STACK_TV_BOT(-2) : STACK_TV_BOT(-1);
e3f9528bddda patch 8.2.1466: Vim9: cannot index or slice a variable with type "any"
Bram Moolenaar <Bram@vim.org>
parents: 21831
diff changeset
3508 var2 = is_slice ? STACK_TV_BOT(-1) : NULL;
23604
1816ea68c022 patch 8.2.2344: using inclusive index for slice is not always desired
Bram Moolenaar <Bram@vim.org>
parents: 23582
diff changeset
3509 res = eval_index_inner(tv, is_slice, var1, var2,
1816ea68c022 patch 8.2.2344: using inclusive index for slice is not always desired
Bram Moolenaar <Bram@vim.org>
parents: 23582
diff changeset
3510 FALSE, NULL, -1, TRUE);
21833
e3f9528bddda patch 8.2.1466: Vim9: cannot index or slice a variable with type "any"
Bram Moolenaar <Bram@vim.org>
parents: 21831
diff changeset
3511 clear_tv(var1);
e3f9528bddda patch 8.2.1466: Vim9: cannot index or slice a variable with type "any"
Bram Moolenaar <Bram@vim.org>
parents: 21831
diff changeset
3512 if (is_slice)
e3f9528bddda patch 8.2.1466: Vim9: cannot index or slice a variable with type "any"
Bram Moolenaar <Bram@vim.org>
parents: 21831
diff changeset
3513 clear_tv(var2);
24488
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
3514 ectx->ec_stack.ga_len -= is_slice ? 2 : 1;
21833
e3f9528bddda patch 8.2.1466: Vim9: cannot index or slice a variable with type "any"
Bram Moolenaar <Bram@vim.org>
parents: 21831
diff changeset
3515 if (res == FAIL)
e3f9528bddda patch 8.2.1466: Vim9: cannot index or slice a variable with type "any"
Bram Moolenaar <Bram@vim.org>
parents: 21831
diff changeset
3516 goto on_error;
e3f9528bddda patch 8.2.1466: Vim9: cannot index or slice a variable with type "any"
Bram Moolenaar <Bram@vim.org>
parents: 21831
diff changeset
3517 }
e3f9528bddda patch 8.2.1466: Vim9: cannot index or slice a variable with type "any"
Bram Moolenaar <Bram@vim.org>
parents: 21831
diff changeset
3518 break;
e3f9528bddda patch 8.2.1466: Vim9: cannot index or slice a variable with type "any"
Bram Moolenaar <Bram@vim.org>
parents: 21831
diff changeset
3519
20871
65d9189d4dca patch 8.2.0987: Vim9: cannot assign to [var; var]
Bram Moolenaar <Bram@vim.org>
parents: 20859
diff changeset
3520 case ISN_SLICE:
65d9189d4dca patch 8.2.0987: Vim9: cannot assign to [var; var]
Bram Moolenaar <Bram@vim.org>
parents: 20859
diff changeset
3521 {
65d9189d4dca patch 8.2.0987: Vim9: cannot assign to [var; var]
Bram Moolenaar <Bram@vim.org>
parents: 20859
diff changeset
3522 list_T *list;
65d9189d4dca patch 8.2.0987: Vim9: cannot assign to [var; var]
Bram Moolenaar <Bram@vim.org>
parents: 20859
diff changeset
3523 int count = iptr->isn_arg.number;
65d9189d4dca patch 8.2.0987: Vim9: cannot assign to [var; var]
Bram Moolenaar <Bram@vim.org>
parents: 20859
diff changeset
3524
20915
a3853794a768 patch 8.2.1009: Vim9: some failures not checked for
Bram Moolenaar <Bram@vim.org>
parents: 20871
diff changeset
3525 // type will have been checked to be a list
20871
65d9189d4dca patch 8.2.0987: Vim9: cannot assign to [var; var]
Bram Moolenaar <Bram@vim.org>
parents: 20859
diff changeset
3526 tv = STACK_TV_BOT(-1);
65d9189d4dca patch 8.2.0987: Vim9: cannot assign to [var; var]
Bram Moolenaar <Bram@vim.org>
parents: 20859
diff changeset
3527 list = tv->vval.v_list;
65d9189d4dca patch 8.2.0987: Vim9: cannot assign to [var; var]
Bram Moolenaar <Bram@vim.org>
parents: 20859
diff changeset
3528
65d9189d4dca patch 8.2.0987: Vim9: cannot assign to [var; var]
Bram Moolenaar <Bram@vim.org>
parents: 20859
diff changeset
3529 // no error for short list, expect it to be checked earlier
65d9189d4dca patch 8.2.0987: Vim9: cannot assign to [var; var]
Bram Moolenaar <Bram@vim.org>
parents: 20859
diff changeset
3530 if (list != NULL && list->lv_len >= count)
65d9189d4dca patch 8.2.0987: Vim9: cannot assign to [var; var]
Bram Moolenaar <Bram@vim.org>
parents: 20859
diff changeset
3531 {
65d9189d4dca patch 8.2.0987: Vim9: cannot assign to [var; var]
Bram Moolenaar <Bram@vim.org>
parents: 20859
diff changeset
3532 list_T *newlist = list_slice(list,
65d9189d4dca patch 8.2.0987: Vim9: cannot assign to [var; var]
Bram Moolenaar <Bram@vim.org>
parents: 20859
diff changeset
3533 count, list->lv_len - 1);
65d9189d4dca patch 8.2.0987: Vim9: cannot assign to [var; var]
Bram Moolenaar <Bram@vim.org>
parents: 20859
diff changeset
3534
65d9189d4dca patch 8.2.0987: Vim9: cannot assign to [var; var]
Bram Moolenaar <Bram@vim.org>
parents: 20859
diff changeset
3535 if (newlist != NULL)
65d9189d4dca patch 8.2.0987: Vim9: cannot assign to [var; var]
Bram Moolenaar <Bram@vim.org>
parents: 20859
diff changeset
3536 {
65d9189d4dca patch 8.2.0987: Vim9: cannot assign to [var; var]
Bram Moolenaar <Bram@vim.org>
parents: 20859
diff changeset
3537 list_unref(list);
65d9189d4dca patch 8.2.0987: Vim9: cannot assign to [var; var]
Bram Moolenaar <Bram@vim.org>
parents: 20859
diff changeset
3538 tv->vval.v_list = newlist;
65d9189d4dca patch 8.2.0987: Vim9: cannot assign to [var; var]
Bram Moolenaar <Bram@vim.org>
parents: 20859
diff changeset
3539 ++newlist->lv_refcount;
65d9189d4dca patch 8.2.0987: Vim9: cannot assign to [var; var]
Bram Moolenaar <Bram@vim.org>
parents: 20859
diff changeset
3540 }
65d9189d4dca patch 8.2.0987: Vim9: cannot assign to [var; var]
Bram Moolenaar <Bram@vim.org>
parents: 20859
diff changeset
3541 }
65d9189d4dca patch 8.2.0987: Vim9: cannot assign to [var; var]
Bram Moolenaar <Bram@vim.org>
parents: 20859
diff changeset
3542 }
65d9189d4dca patch 8.2.0987: Vim9: cannot assign to [var; var]
Bram Moolenaar <Bram@vim.org>
parents: 20859
diff changeset
3543 break;
65d9189d4dca patch 8.2.0987: Vim9: cannot assign to [var; var]
Bram Moolenaar <Bram@vim.org>
parents: 20859
diff changeset
3544
20859
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20538
diff changeset
3545 case ISN_GETITEM:
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20538
diff changeset
3546 {
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20538
diff changeset
3547 listitem_T *li;
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20538
diff changeset
3548 int index = iptr->isn_arg.number;
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20538
diff changeset
3549
20919
96bf2b304932 patch 8.2.1011: Vim9: some code not tested
Bram Moolenaar <Bram@vim.org>
parents: 20915
diff changeset
3550 // Get list item: list is at stack-1, push item.
96bf2b304932 patch 8.2.1011: Vim9: some code not tested
Bram Moolenaar <Bram@vim.org>
parents: 20915
diff changeset
3551 // List type and length is checked for when compiling.
20859
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20538
diff changeset
3552 tv = STACK_TV_BOT(-1);
20919
96bf2b304932 patch 8.2.1011: Vim9: some code not tested
Bram Moolenaar <Bram@vim.org>
parents: 20915
diff changeset
3553 li = list_find(tv->vval.v_list, index);
20859
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20538
diff changeset
3554
24488
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
3555 if (GA_GROW(&ectx->ec_stack, 1) == FAIL)
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
3556 return FAIL;
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
3557 ++ectx->ec_stack.ga_len;
20859
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20538
diff changeset
3558 copy_tv(&li->li_tv, STACK_TV_BOT(-1));
23917
4b417b776b95 patch 8.2.2501: not always clear where an error is reported
Bram Moolenaar <Bram@vim.org>
parents: 23839
diff changeset
3559
4b417b776b95 patch 8.2.2501: not always clear where an error is reported
Bram Moolenaar <Bram@vim.org>
parents: 23839
diff changeset
3560 // Useful when used in unpack assignment. Reset at
4b417b776b95 patch 8.2.2501: not always clear where an error is reported
Bram Moolenaar <Bram@vim.org>
parents: 23839
diff changeset
3561 // ISN_DROP.
24488
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
3562 ectx->ec_where.wt_index = index + 1;
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
3563 ectx->ec_where.wt_variable = TRUE;
20859
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20538
diff changeset
3564 }
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20538
diff changeset
3565 break;
876e16c48bd1 patch 8.2.0981: Vim9: cannot compile "[var, var] = list"
Bram Moolenaar <Bram@vim.org>
parents: 20538
diff changeset
3566
20349
e29b2ec8d4d2 patch 8.2.0730: Vim9: Assignment to dict member does not work
Bram Moolenaar <Bram@vim.org>
parents: 20341
diff changeset
3567 case ISN_MEMBER:
e29b2ec8d4d2 patch 8.2.0730: Vim9: Assignment to dict member does not work
Bram Moolenaar <Bram@vim.org>
parents: 20341
diff changeset
3568 {
e29b2ec8d4d2 patch 8.2.0730: Vim9: Assignment to dict member does not work
Bram Moolenaar <Bram@vim.org>
parents: 20341
diff changeset
3569 dict_T *dict;
e29b2ec8d4d2 patch 8.2.0730: Vim9: Assignment to dict member does not work
Bram Moolenaar <Bram@vim.org>
parents: 20341
diff changeset
3570 char_u *key;
e29b2ec8d4d2 patch 8.2.0730: Vim9: Assignment to dict member does not work
Bram Moolenaar <Bram@vim.org>
parents: 20341
diff changeset
3571 dictitem_T *di;
21168
f26a606e6dbc patch 8.2.1135: Vim9: getting a dict member may not work
Bram Moolenaar <Bram@vim.org>
parents: 21166
diff changeset
3572 typval_T temp_tv;
20349
e29b2ec8d4d2 patch 8.2.0730: Vim9: Assignment to dict member does not work
Bram Moolenaar <Bram@vim.org>
parents: 20341
diff changeset
3573
e29b2ec8d4d2 patch 8.2.0730: Vim9: Assignment to dict member does not work
Bram Moolenaar <Bram@vim.org>
parents: 20341
diff changeset
3574 // dict member: dict is at stack-2, key at stack-1
e29b2ec8d4d2 patch 8.2.0730: Vim9: Assignment to dict member does not work
Bram Moolenaar <Bram@vim.org>
parents: 20341
diff changeset
3575 tv = STACK_TV_BOT(-2);
20411
23af9e1a5283 patch 8.2.0760: Vim9: dict member errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 20409
diff changeset
3576 // no need to check for VAR_DICT, CHECKTYPE will check.
20349
e29b2ec8d4d2 patch 8.2.0730: Vim9: Assignment to dict member does not work
Bram Moolenaar <Bram@vim.org>
parents: 20341
diff changeset
3577 dict = tv->vval.v_dict;
e29b2ec8d4d2 patch 8.2.0730: Vim9: Assignment to dict member does not work
Bram Moolenaar <Bram@vim.org>
parents: 20341
diff changeset
3578
e29b2ec8d4d2 patch 8.2.0730: Vim9: Assignment to dict member does not work
Bram Moolenaar <Bram@vim.org>
parents: 20341
diff changeset
3579 tv = STACK_TV_BOT(-1);
20411
23af9e1a5283 patch 8.2.0760: Vim9: dict member errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 20409
diff changeset
3580 // no need to check for VAR_STRING, 2STRING will check.
20349
e29b2ec8d4d2 patch 8.2.0730: Vim9: Assignment to dict member does not work
Bram Moolenaar <Bram@vim.org>
parents: 20341
diff changeset
3581 key = tv->vval.v_string;
22752
84fca115b1bb patch 8.2.1924: Vim9: crash when indexing dict with NULL key
Bram Moolenaar <Bram@vim.org>
parents: 22742
diff changeset
3582 if (key == NULL)
84fca115b1bb patch 8.2.1924: Vim9: crash when indexing dict with NULL key
Bram Moolenaar <Bram@vim.org>
parents: 22742
diff changeset
3583 key = (char_u *)"";
20411
23af9e1a5283 patch 8.2.0760: Vim9: dict member errors not tested
Bram Moolenaar <Bram@vim.org>
parents: 20409
diff changeset
3584
20349
e29b2ec8d4d2 patch 8.2.0730: Vim9: Assignment to dict member does not work
Bram Moolenaar <Bram@vim.org>
parents: 20341
diff changeset
3585 if ((di = dict_find(dict, key, -1)) == NULL)
e29b2ec8d4d2 patch 8.2.0730: Vim9: Assignment to dict member does not work
Bram Moolenaar <Bram@vim.org>
parents: 20341
diff changeset
3586 {
21793
0706bd071fa3 patch 8.2.1446: Vim9: line number in error message is not correct
Bram Moolenaar <Bram@vim.org>
parents: 21789
diff changeset
3587 SOURCING_LNUM = iptr->isn_lnum;
20349
e29b2ec8d4d2 patch 8.2.0730: Vim9: Assignment to dict member does not work
Bram Moolenaar <Bram@vim.org>
parents: 20341
diff changeset
3588 semsg(_(e_dictkey), key);
23098
bdafc132a4a1 patch 8.2.2095: Vim9: crash when failed dict member is followed by concat
Bram Moolenaar <Bram@vim.org>
parents: 23074
diff changeset
3589
bdafc132a4a1 patch 8.2.2095: Vim9: crash when failed dict member is followed by concat
Bram Moolenaar <Bram@vim.org>
parents: 23074
diff changeset
3590 // If :silent! is used we will continue, make sure the
bdafc132a4a1 patch 8.2.2095: Vim9: crash when failed dict member is followed by concat
Bram Moolenaar <Bram@vim.org>
parents: 23074
diff changeset
3591 // stack contents makes sense.
bdafc132a4a1 patch 8.2.2095: Vim9: crash when failed dict member is followed by concat
Bram Moolenaar <Bram@vim.org>
parents: 23074
diff changeset
3592 clear_tv(tv);
24488
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
3593 --ectx->ec_stack.ga_len;
23098
bdafc132a4a1 patch 8.2.2095: Vim9: crash when failed dict member is followed by concat
Bram Moolenaar <Bram@vim.org>
parents: 23074
diff changeset
3594 tv = STACK_TV_BOT(-1);
bdafc132a4a1 patch 8.2.2095: Vim9: crash when failed dict member is followed by concat
Bram Moolenaar <Bram@vim.org>
parents: 23074
diff changeset
3595 clear_tv(tv);
bdafc132a4a1 patch 8.2.2095: Vim9: crash when failed dict member is followed by concat
Bram Moolenaar <Bram@vim.org>
parents: 23074
diff changeset
3596 tv->v_type = VAR_NUMBER;
bdafc132a4a1 patch 8.2.2095: Vim9: crash when failed dict member is followed by concat
Bram Moolenaar <Bram@vim.org>
parents: 23074
diff changeset
3597 tv->vval.v_number = 0;
23074
cd885eb0e50c patch 8.2.2083: Vim9: crash when using ":silent!" and getting member fails
Bram Moolenaar <Bram@vim.org>
parents: 23009
diff changeset
3598 goto on_fatal_error;
20349
e29b2ec8d4d2 patch 8.2.0730: Vim9: Assignment to dict member does not work
Bram Moolenaar <Bram@vim.org>
parents: 20341
diff changeset
3599 }
21168
f26a606e6dbc patch 8.2.1135: Vim9: getting a dict member may not work
Bram Moolenaar <Bram@vim.org>
parents: 21166
diff changeset
3600 clear_tv(tv);
24488
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
3601 --ectx->ec_stack.ga_len;
23074
cd885eb0e50c patch 8.2.2083: Vim9: crash when using ":silent!" and getting member fails
Bram Moolenaar <Bram@vim.org>
parents: 23009
diff changeset
3602 // Clear the dict only after getting the item, to avoid
cd885eb0e50c patch 8.2.2083: Vim9: crash when using ":silent!" and getting member fails
Bram Moolenaar <Bram@vim.org>
parents: 23009
diff changeset
3603 // that it makes the item invalid.
21168
f26a606e6dbc patch 8.2.1135: Vim9: getting a dict member may not work
Bram Moolenaar <Bram@vim.org>
parents: 21166
diff changeset
3604 tv = STACK_TV_BOT(-1);
f26a606e6dbc patch 8.2.1135: Vim9: getting a dict member may not work
Bram Moolenaar <Bram@vim.org>
parents: 21166
diff changeset
3605 temp_tv = *tv;
f26a606e6dbc patch 8.2.1135: Vim9: getting a dict member may not work
Bram Moolenaar <Bram@vim.org>
parents: 21166
diff changeset
3606 copy_tv(&di->di_tv, tv);
f26a606e6dbc patch 8.2.1135: Vim9: getting a dict member may not work
Bram Moolenaar <Bram@vim.org>
parents: 21166
diff changeset
3607 clear_tv(&temp_tv);
20349
e29b2ec8d4d2 patch 8.2.0730: Vim9: Assignment to dict member does not work
Bram Moolenaar <Bram@vim.org>
parents: 20341
diff changeset
3608 }
e29b2ec8d4d2 patch 8.2.0730: Vim9: Assignment to dict member does not work
Bram Moolenaar <Bram@vim.org>
parents: 20341
diff changeset
3609 break;
e29b2ec8d4d2 patch 8.2.0730: Vim9: Assignment to dict member does not work
Bram Moolenaar <Bram@vim.org>
parents: 20341
diff changeset
3610
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3611 // dict member with string key
20349
e29b2ec8d4d2 patch 8.2.0730: Vim9: Assignment to dict member does not work
Bram Moolenaar <Bram@vim.org>
parents: 20341
diff changeset
3612 case ISN_STRINGMEMBER:
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3613 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3614 dict_T *dict;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3615 dictitem_T *di;
21152
1561311249bb patch 8.2.1127: Vim9: getting a dict member may not work
Bram Moolenaar <Bram@vim.org>
parents: 21120
diff changeset
3616 typval_T temp_tv;
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3617
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3618 tv = STACK_TV_BOT(-1);
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3619 if (tv->v_type != VAR_DICT || tv->vval.v_dict == NULL)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3620 {
21793
0706bd071fa3 patch 8.2.1446: Vim9: line number in error message is not correct
Bram Moolenaar <Bram@vim.org>
parents: 21789
diff changeset
3621 SOURCING_LNUM = iptr->isn_lnum;
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3622 emsg(_(e_dictreq));
21375
92e2ed2a2778 patch 8.2.1238: Vim9: a few remaining errors not caught by try/catch
Bram Moolenaar <Bram@vim.org>
parents: 21371
diff changeset
3623 goto on_error;
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3624 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3625 dict = tv->vval.v_dict;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3626
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3627 if ((di = dict_find(dict, iptr->isn_arg.string, -1))
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3628 == NULL)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3629 {
21793
0706bd071fa3 patch 8.2.1446: Vim9: line number in error message is not correct
Bram Moolenaar <Bram@vim.org>
parents: 21789
diff changeset
3630 SOURCING_LNUM = iptr->isn_lnum;
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3631 semsg(_(e_dictkey), iptr->isn_arg.string);
21375
92e2ed2a2778 patch 8.2.1238: Vim9: a few remaining errors not caught by try/catch
Bram Moolenaar <Bram@vim.org>
parents: 21371
diff changeset
3632 goto on_error;
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3633 }
21152
1561311249bb patch 8.2.1127: Vim9: getting a dict member may not work
Bram Moolenaar <Bram@vim.org>
parents: 21120
diff changeset
3634 // Clear the dict after getting the item, to avoid that it
1561311249bb patch 8.2.1127: Vim9: getting a dict member may not work
Bram Moolenaar <Bram@vim.org>
parents: 21120
diff changeset
3635 // make the item invalid.
1561311249bb patch 8.2.1127: Vim9: getting a dict member may not work
Bram Moolenaar <Bram@vim.org>
parents: 21120
diff changeset
3636 temp_tv = *tv;
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3637 copy_tv(&di->di_tv, tv);
21152
1561311249bb patch 8.2.1127: Vim9: getting a dict member may not work
Bram Moolenaar <Bram@vim.org>
parents: 21120
diff changeset
3638 clear_tv(&temp_tv);
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3639 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3640 break;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3641
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3642 case ISN_NEGATENR:
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3643 tv = STACK_TV_BOT(-1);
19842
e4ade28bfaf7 patch 8.2.0477: Vim9: error messages not tested
Bram Moolenaar <Bram@vim.org>
parents: 19766
diff changeset
3644 if (tv->v_type != VAR_NUMBER
e4ade28bfaf7 patch 8.2.0477: Vim9: error messages not tested
Bram Moolenaar <Bram@vim.org>
parents: 19766
diff changeset
3645 #ifdef FEAT_FLOAT
e4ade28bfaf7 patch 8.2.0477: Vim9: error messages not tested
Bram Moolenaar <Bram@vim.org>
parents: 19766
diff changeset
3646 && tv->v_type != VAR_FLOAT
e4ade28bfaf7 patch 8.2.0477: Vim9: error messages not tested
Bram Moolenaar <Bram@vim.org>
parents: 19766
diff changeset
3647 #endif
e4ade28bfaf7 patch 8.2.0477: Vim9: error messages not tested
Bram Moolenaar <Bram@vim.org>
parents: 19766
diff changeset
3648 )
e4ade28bfaf7 patch 8.2.0477: Vim9: error messages not tested
Bram Moolenaar <Bram@vim.org>
parents: 19766
diff changeset
3649 {
21793
0706bd071fa3 patch 8.2.1446: Vim9: line number in error message is not correct
Bram Moolenaar <Bram@vim.org>
parents: 21789
diff changeset
3650 SOURCING_LNUM = iptr->isn_lnum;
19842
e4ade28bfaf7 patch 8.2.0477: Vim9: error messages not tested
Bram Moolenaar <Bram@vim.org>
parents: 19766
diff changeset
3651 emsg(_(e_number_exp));
21365
fca850f4d603 patch 8.2.1233: Vim9: various errors not caught by try/catch
Bram Moolenaar <Bram@vim.org>
parents: 21359
diff changeset
3652 goto on_error;
19842
e4ade28bfaf7 patch 8.2.0477: Vim9: error messages not tested
Bram Moolenaar <Bram@vim.org>
parents: 19766
diff changeset
3653 }
e4ade28bfaf7 patch 8.2.0477: Vim9: error messages not tested
Bram Moolenaar <Bram@vim.org>
parents: 19766
diff changeset
3654 #ifdef FEAT_FLOAT
e4ade28bfaf7 patch 8.2.0477: Vim9: error messages not tested
Bram Moolenaar <Bram@vim.org>
parents: 19766
diff changeset
3655 if (tv->v_type == VAR_FLOAT)
e4ade28bfaf7 patch 8.2.0477: Vim9: error messages not tested
Bram Moolenaar <Bram@vim.org>
parents: 19766
diff changeset
3656 tv->vval.v_float = -tv->vval.v_float;
e4ade28bfaf7 patch 8.2.0477: Vim9: error messages not tested
Bram Moolenaar <Bram@vim.org>
parents: 19766
diff changeset
3657 else
e4ade28bfaf7 patch 8.2.0477: Vim9: error messages not tested
Bram Moolenaar <Bram@vim.org>
parents: 19766
diff changeset
3658 #endif
e4ade28bfaf7 patch 8.2.0477: Vim9: error messages not tested
Bram Moolenaar <Bram@vim.org>
parents: 19766
diff changeset
3659 tv->vval.v_number = -tv->vval.v_number;
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3660 break;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3661
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3662 case ISN_CHECKNR:
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3663 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3664 int error = FALSE;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3665
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3666 tv = STACK_TV_BOT(-1);
21863
809b1e7fbd72 patch 8.2.1481: Vim9: line number reported with error may be wrong
Bram Moolenaar <Bram@vim.org>
parents: 21859
diff changeset
3667 SOURCING_LNUM = iptr->isn_lnum;
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3668 if (check_not_string(tv) == FAIL)
21365
fca850f4d603 patch 8.2.1233: Vim9: various errors not caught by try/catch
Bram Moolenaar <Bram@vim.org>
parents: 21359
diff changeset
3669 goto on_error;
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3670 (void)tv_get_number_chk(tv, &error);
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3671 if (error)
21365
fca850f4d603 patch 8.2.1233: Vim9: various errors not caught by try/catch
Bram Moolenaar <Bram@vim.org>
parents: 21359
diff changeset
3672 goto on_error;
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3673 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3674 break;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3675
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3676 case ISN_CHECKTYPE:
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3677 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3678 checktype_T *ct = &iptr->isn_arg.type;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3679
23697
19073a768852 patch 8.2.2390: Vim9: using positive offset is unexpected
Bram Moolenaar <Bram@vim.org>
parents: 23695
diff changeset
3680 tv = STACK_TV_BOT((int)ct->ct_off);
22284
6b385c2b9ff5 patch 8.2.1691: Vim9: list<any> is not accepted where list<number> is expected
Bram Moolenaar <Bram@vim.org>
parents: 22272
diff changeset
3681 SOURCING_LNUM = iptr->isn_lnum;
24488
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
3682 if (!ectx->ec_where.wt_variable)
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
3683 ectx->ec_where.wt_index = ct->ct_arg_idx;
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
3684 if (check_typval_type(ct->ct_type, tv, ectx->ec_where)
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
3685 == FAIL)
22284
6b385c2b9ff5 patch 8.2.1691: Vim9: list<any> is not accepted where list<number> is expected
Bram Moolenaar <Bram@vim.org>
parents: 22272
diff changeset
3686 goto on_error;
24488
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
3687 if (!ectx->ec_where.wt_variable)
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
3688 ectx->ec_where.wt_index = 0;
22284
6b385c2b9ff5 patch 8.2.1691: Vim9: list<any> is not accepted where list<number> is expected
Bram Moolenaar <Bram@vim.org>
parents: 22272
diff changeset
3689
6b385c2b9ff5 patch 8.2.1691: Vim9: list<any> is not accepted where list<number> is expected
Bram Moolenaar <Bram@vim.org>
parents: 22272
diff changeset
3690 // number 0 is FALSE, number 1 is TRUE
6b385c2b9ff5 patch 8.2.1691: Vim9: list<any> is not accepted where list<number> is expected
Bram Moolenaar <Bram@vim.org>
parents: 22272
diff changeset
3691 if (tv->v_type == VAR_NUMBER
6b385c2b9ff5 patch 8.2.1691: Vim9: list<any> is not accepted where list<number> is expected
Bram Moolenaar <Bram@vim.org>
parents: 22272
diff changeset
3692 && ct->ct_type->tt_type == VAR_BOOL
6b385c2b9ff5 patch 8.2.1691: Vim9: list<any> is not accepted where list<number> is expected
Bram Moolenaar <Bram@vim.org>
parents: 22272
diff changeset
3693 && (tv->vval.v_number == 0
6b385c2b9ff5 patch 8.2.1691: Vim9: list<any> is not accepted where list<number> is expected
Bram Moolenaar <Bram@vim.org>
parents: 22272
diff changeset
3694 || tv->vval.v_number == 1))
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3695 {
22284
6b385c2b9ff5 patch 8.2.1691: Vim9: list<any> is not accepted where list<number> is expected
Bram Moolenaar <Bram@vim.org>
parents: 22272
diff changeset
3696 tv->v_type = VAR_BOOL;
6b385c2b9ff5 patch 8.2.1691: Vim9: list<any> is not accepted where list<number> is expected
Bram Moolenaar <Bram@vim.org>
parents: 22272
diff changeset
3697 tv->vval.v_number = tv->vval.v_number
22238
939f7184566f patch 8.2.1668: Vim9: not accepting 0 or 1 as bool when type is any
Bram Moolenaar <Bram@vim.org>
parents: 22214
diff changeset
3698 ? VVAL_TRUE : VVAL_FALSE;
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3699 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3700 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3701 break;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3702
20871
65d9189d4dca patch 8.2.0987: Vim9: cannot assign to [var; var]
Bram Moolenaar <Bram@vim.org>
parents: 20859
diff changeset
3703 case ISN_CHECKLEN:
65d9189d4dca patch 8.2.0987: Vim9: cannot assign to [var; var]
Bram Moolenaar <Bram@vim.org>
parents: 20859
diff changeset
3704 {
65d9189d4dca patch 8.2.0987: Vim9: cannot assign to [var; var]
Bram Moolenaar <Bram@vim.org>
parents: 20859
diff changeset
3705 int min_len = iptr->isn_arg.checklen.cl_min_len;
65d9189d4dca patch 8.2.0987: Vim9: cannot assign to [var; var]
Bram Moolenaar <Bram@vim.org>
parents: 20859
diff changeset
3706 list_T *list = NULL;
65d9189d4dca patch 8.2.0987: Vim9: cannot assign to [var; var]
Bram Moolenaar <Bram@vim.org>
parents: 20859
diff changeset
3707
65d9189d4dca patch 8.2.0987: Vim9: cannot assign to [var; var]
Bram Moolenaar <Bram@vim.org>
parents: 20859
diff changeset
3708 tv = STACK_TV_BOT(-1);
65d9189d4dca patch 8.2.0987: Vim9: cannot assign to [var; var]
Bram Moolenaar <Bram@vim.org>
parents: 20859
diff changeset
3709 if (tv->v_type == VAR_LIST)
65d9189d4dca patch 8.2.0987: Vim9: cannot assign to [var; var]
Bram Moolenaar <Bram@vim.org>
parents: 20859
diff changeset
3710 list = tv->vval.v_list;
65d9189d4dca patch 8.2.0987: Vim9: cannot assign to [var; var]
Bram Moolenaar <Bram@vim.org>
parents: 20859
diff changeset
3711 if (list == NULL || list->lv_len < min_len
65d9189d4dca patch 8.2.0987: Vim9: cannot assign to [var; var]
Bram Moolenaar <Bram@vim.org>
parents: 20859
diff changeset
3712 || (list->lv_len > min_len
65d9189d4dca patch 8.2.0987: Vim9: cannot assign to [var; var]
Bram Moolenaar <Bram@vim.org>
parents: 20859
diff changeset
3713 && !iptr->isn_arg.checklen.cl_more_OK))
65d9189d4dca patch 8.2.0987: Vim9: cannot assign to [var; var]
Bram Moolenaar <Bram@vim.org>
parents: 20859
diff changeset
3714 {
21793
0706bd071fa3 patch 8.2.1446: Vim9: line number in error message is not correct
Bram Moolenaar <Bram@vim.org>
parents: 21789
diff changeset
3715 SOURCING_LNUM = iptr->isn_lnum;
21821
0deb6f96a5a3 patch 8.2.1460: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents: 21815
diff changeset
3716 semsg(_(e_expected_nr_items_but_got_nr),
20871
65d9189d4dca patch 8.2.0987: Vim9: cannot assign to [var; var]
Bram Moolenaar <Bram@vim.org>
parents: 20859
diff changeset
3717 min_len, list == NULL ? 0 : list->lv_len);
21365
fca850f4d603 patch 8.2.1233: Vim9: various errors not caught by try/catch
Bram Moolenaar <Bram@vim.org>
parents: 21359
diff changeset
3718 goto on_error;
20871
65d9189d4dca patch 8.2.0987: Vim9: cannot assign to [var; var]
Bram Moolenaar <Bram@vim.org>
parents: 20859
diff changeset
3719 }
65d9189d4dca patch 8.2.0987: Vim9: cannot assign to [var; var]
Bram Moolenaar <Bram@vim.org>
parents: 20859
diff changeset
3720 }
65d9189d4dca patch 8.2.0987: Vim9: cannot assign to [var; var]
Bram Moolenaar <Bram@vim.org>
parents: 20859
diff changeset
3721 break;
65d9189d4dca patch 8.2.0987: Vim9: cannot assign to [var; var]
Bram Moolenaar <Bram@vim.org>
parents: 20859
diff changeset
3722
23458
d2b1269c2c68 patch 8.2.2272: Vim9: extend() can violate the type of a variable
Bram Moolenaar <Bram@vim.org>
parents: 23454
diff changeset
3723 case ISN_SETTYPE:
d2b1269c2c68 patch 8.2.2272: Vim9: extend() can violate the type of a variable
Bram Moolenaar <Bram@vim.org>
parents: 23454
diff changeset
3724 {
d2b1269c2c68 patch 8.2.2272: Vim9: extend() can violate the type of a variable
Bram Moolenaar <Bram@vim.org>
parents: 23454
diff changeset
3725 checktype_T *ct = &iptr->isn_arg.type;
d2b1269c2c68 patch 8.2.2272: Vim9: extend() can violate the type of a variable
Bram Moolenaar <Bram@vim.org>
parents: 23454
diff changeset
3726
d2b1269c2c68 patch 8.2.2272: Vim9: extend() can violate the type of a variable
Bram Moolenaar <Bram@vim.org>
parents: 23454
diff changeset
3727 tv = STACK_TV_BOT(-1);
d2b1269c2c68 patch 8.2.2272: Vim9: extend() can violate the type of a variable
Bram Moolenaar <Bram@vim.org>
parents: 23454
diff changeset
3728 if (tv->v_type == VAR_DICT && tv->vval.v_dict != NULL)
d2b1269c2c68 patch 8.2.2272: Vim9: extend() can violate the type of a variable
Bram Moolenaar <Bram@vim.org>
parents: 23454
diff changeset
3729 {
d2b1269c2c68 patch 8.2.2272: Vim9: extend() can violate the type of a variable
Bram Moolenaar <Bram@vim.org>
parents: 23454
diff changeset
3730 free_type(tv->vval.v_dict->dv_type);
d2b1269c2c68 patch 8.2.2272: Vim9: extend() can violate the type of a variable
Bram Moolenaar <Bram@vim.org>
parents: 23454
diff changeset
3731 tv->vval.v_dict->dv_type = alloc_type(ct->ct_type);
d2b1269c2c68 patch 8.2.2272: Vim9: extend() can violate the type of a variable
Bram Moolenaar <Bram@vim.org>
parents: 23454
diff changeset
3732 }
d2b1269c2c68 patch 8.2.2272: Vim9: extend() can violate the type of a variable
Bram Moolenaar <Bram@vim.org>
parents: 23454
diff changeset
3733 else if (tv->v_type == VAR_LIST && tv->vval.v_list != NULL)
d2b1269c2c68 patch 8.2.2272: Vim9: extend() can violate the type of a variable
Bram Moolenaar <Bram@vim.org>
parents: 23454
diff changeset
3734 {
d2b1269c2c68 patch 8.2.2272: Vim9: extend() can violate the type of a variable
Bram Moolenaar <Bram@vim.org>
parents: 23454
diff changeset
3735 free_type(tv->vval.v_list->lv_type);
d2b1269c2c68 patch 8.2.2272: Vim9: extend() can violate the type of a variable
Bram Moolenaar <Bram@vim.org>
parents: 23454
diff changeset
3736 tv->vval.v_list->lv_type = alloc_type(ct->ct_type);
d2b1269c2c68 patch 8.2.2272: Vim9: extend() can violate the type of a variable
Bram Moolenaar <Bram@vim.org>
parents: 23454
diff changeset
3737 }
d2b1269c2c68 patch 8.2.2272: Vim9: extend() can violate the type of a variable
Bram Moolenaar <Bram@vim.org>
parents: 23454
diff changeset
3738 }
d2b1269c2c68 patch 8.2.2272: Vim9: extend() can violate the type of a variable
Bram Moolenaar <Bram@vim.org>
parents: 23454
diff changeset
3739 break;
d2b1269c2c68 patch 8.2.2272: Vim9: extend() can violate the type of a variable
Bram Moolenaar <Bram@vim.org>
parents: 23454
diff changeset
3740
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3741 case ISN_2BOOL:
22494
4c21f7f6f9e3 patch 8.2.1795: Vim9: operators && and || have a confusing result
Bram Moolenaar <Bram@vim.org>
parents: 22460
diff changeset
3742 case ISN_COND2BOOL:
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3743 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3744 int n;
22494
4c21f7f6f9e3 patch 8.2.1795: Vim9: operators && and || have a confusing result
Bram Moolenaar <Bram@vim.org>
parents: 22460
diff changeset
3745 int error = FALSE;
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3746
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3747 tv = STACK_TV_BOT(-1);
22494
4c21f7f6f9e3 patch 8.2.1795: Vim9: operators && and || have a confusing result
Bram Moolenaar <Bram@vim.org>
parents: 22460
diff changeset
3748 if (iptr->isn_type == ISN_2BOOL)
4c21f7f6f9e3 patch 8.2.1795: Vim9: operators && and || have a confusing result
Bram Moolenaar <Bram@vim.org>
parents: 22460
diff changeset
3749 {
4c21f7f6f9e3 patch 8.2.1795: Vim9: operators && and || have a confusing result
Bram Moolenaar <Bram@vim.org>
parents: 22460
diff changeset
3750 n = tv2bool(tv);
4c21f7f6f9e3 patch 8.2.1795: Vim9: operators && and || have a confusing result
Bram Moolenaar <Bram@vim.org>
parents: 22460
diff changeset
3751 if (iptr->isn_arg.number) // invert
4c21f7f6f9e3 patch 8.2.1795: Vim9: operators && and || have a confusing result
Bram Moolenaar <Bram@vim.org>
parents: 22460
diff changeset
3752 n = !n;
4c21f7f6f9e3 patch 8.2.1795: Vim9: operators && and || have a confusing result
Bram Moolenaar <Bram@vim.org>
parents: 22460
diff changeset
3753 }
4c21f7f6f9e3 patch 8.2.1795: Vim9: operators && and || have a confusing result
Bram Moolenaar <Bram@vim.org>
parents: 22460
diff changeset
3754 else
4c21f7f6f9e3 patch 8.2.1795: Vim9: operators && and || have a confusing result
Bram Moolenaar <Bram@vim.org>
parents: 22460
diff changeset
3755 {
4c21f7f6f9e3 patch 8.2.1795: Vim9: operators && and || have a confusing result
Bram Moolenaar <Bram@vim.org>
parents: 22460
diff changeset
3756 SOURCING_LNUM = iptr->isn_lnum;
4c21f7f6f9e3 patch 8.2.1795: Vim9: operators && and || have a confusing result
Bram Moolenaar <Bram@vim.org>
parents: 22460
diff changeset
3757 n = tv_get_bool_chk(tv, &error);
4c21f7f6f9e3 patch 8.2.1795: Vim9: operators && and || have a confusing result
Bram Moolenaar <Bram@vim.org>
parents: 22460
diff changeset
3758 if (error)
4c21f7f6f9e3 patch 8.2.1795: Vim9: operators && and || have a confusing result
Bram Moolenaar <Bram@vim.org>
parents: 22460
diff changeset
3759 goto on_error;
4c21f7f6f9e3 patch 8.2.1795: Vim9: operators && and || have a confusing result
Bram Moolenaar <Bram@vim.org>
parents: 22460
diff changeset
3760 }
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3761 clear_tv(tv);
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3762 tv->v_type = VAR_BOOL;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3763 tv->vval.v_number = n ? VVAL_TRUE : VVAL_FALSE;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3764 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3765 break;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3766
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3767 case ISN_2STRING:
21771
fcf978444298 patch 8.2.1435: Vim9: always converting to string for ".." leads to mistakes
Bram Moolenaar <Bram@vim.org>
parents: 21757
diff changeset
3768 case ISN_2STRING_ANY:
23523
b0a6e7325169 patch 8.2.2304: Vim9: no test for unletting an imported variable
Bram Moolenaar <Bram@vim.org>
parents: 23517
diff changeset
3769 SOURCING_LNUM = iptr->isn_lnum;
23266
00f7cd9b6033 patch 8.2.2179: Vim9: crash when indexing a dict with a number
Bram Moolenaar <Bram@vim.org>
parents: 23254
diff changeset
3770 if (do_2string(STACK_TV_BOT(iptr->isn_arg.number),
00f7cd9b6033 patch 8.2.2179: Vim9: crash when indexing a dict with a number
Bram Moolenaar <Bram@vim.org>
parents: 23254
diff changeset
3771 iptr->isn_type == ISN_2STRING_ANY) == FAIL)
00f7cd9b6033 patch 8.2.2179: Vim9: crash when indexing a dict with a number
Bram Moolenaar <Bram@vim.org>
parents: 23254
diff changeset
3772 goto on_error;
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3773 break;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3774
23156
6aa8ddf7a3fa patch 8.2.2124: Vim9: a range cannot be computed at runtime
Bram Moolenaar <Bram@vim.org>
parents: 23102
diff changeset
3775 case ISN_RANGE:
6aa8ddf7a3fa patch 8.2.2124: Vim9: a range cannot be computed at runtime
Bram Moolenaar <Bram@vim.org>
parents: 23102
diff changeset
3776 {
6aa8ddf7a3fa patch 8.2.2124: Vim9: a range cannot be computed at runtime
Bram Moolenaar <Bram@vim.org>
parents: 23102
diff changeset
3777 exarg_T ea;
6aa8ddf7a3fa patch 8.2.2124: Vim9: a range cannot be computed at runtime
Bram Moolenaar <Bram@vim.org>
parents: 23102
diff changeset
3778 char *errormsg;
6aa8ddf7a3fa patch 8.2.2124: Vim9: a range cannot be computed at runtime
Bram Moolenaar <Bram@vim.org>
parents: 23102
diff changeset
3779
23541
a2a38bc68dd9 patch 8.2.2313: Vim9: using uninitialized field when parsing range
Bram Moolenaar <Bram@vim.org>
parents: 23527
diff changeset
3780 ea.line2 = 0;
23513
872239543313 patch 8.2.2299: Vim9: invalid memory access making error message flaky
Bram Moolenaar <Bram@vim.org>
parents: 23503
diff changeset
3781 ea.addr_count = 0;
23156
6aa8ddf7a3fa patch 8.2.2124: Vim9: a range cannot be computed at runtime
Bram Moolenaar <Bram@vim.org>
parents: 23102
diff changeset
3782 ea.addr_type = ADDR_LINES;
6aa8ddf7a3fa patch 8.2.2124: Vim9: a range cannot be computed at runtime
Bram Moolenaar <Bram@vim.org>
parents: 23102
diff changeset
3783 ea.cmd = iptr->isn_arg.string;
23541
a2a38bc68dd9 patch 8.2.2313: Vim9: using uninitialized field when parsing range
Bram Moolenaar <Bram@vim.org>
parents: 23527
diff changeset
3784 ea.skip = FALSE;
23156
6aa8ddf7a3fa patch 8.2.2124: Vim9: a range cannot be computed at runtime
Bram Moolenaar <Bram@vim.org>
parents: 23102
diff changeset
3785 if (parse_cmd_address(&ea, &errormsg, FALSE) == FAIL)
23541
a2a38bc68dd9 patch 8.2.2313: Vim9: using uninitialized field when parsing range
Bram Moolenaar <Bram@vim.org>
parents: 23527
diff changeset
3786 goto on_error;
23671
9ee9c4246a7f patch 8.2.2377: Vim9: crash when using a range after another expression
Bram Moolenaar <Bram@vim.org>
parents: 23656
diff changeset
3787
24488
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
3788 if (GA_GROW(&ectx->ec_stack, 1) == FAIL)
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
3789 return FAIL;
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
3790 ++ectx->ec_stack.ga_len;
23671
9ee9c4246a7f patch 8.2.2377: Vim9: crash when using a range after another expression
Bram Moolenaar <Bram@vim.org>
parents: 23656
diff changeset
3791 tv = STACK_TV_BOT(-1);
9ee9c4246a7f patch 8.2.2377: Vim9: crash when using a range after another expression
Bram Moolenaar <Bram@vim.org>
parents: 23656
diff changeset
3792 tv->v_type = VAR_NUMBER;
9ee9c4246a7f patch 8.2.2377: Vim9: crash when using a range after another expression
Bram Moolenaar <Bram@vim.org>
parents: 23656
diff changeset
3793 tv->v_lock = 0;
23156
6aa8ddf7a3fa patch 8.2.2124: Vim9: a range cannot be computed at runtime
Bram Moolenaar <Bram@vim.org>
parents: 23102
diff changeset
3794 if (ea.addr_count == 0)
6aa8ddf7a3fa patch 8.2.2124: Vim9: a range cannot be computed at runtime
Bram Moolenaar <Bram@vim.org>
parents: 23102
diff changeset
3795 tv->vval.v_number = curwin->w_cursor.lnum;
6aa8ddf7a3fa patch 8.2.2124: Vim9: a range cannot be computed at runtime
Bram Moolenaar <Bram@vim.org>
parents: 23102
diff changeset
3796 else
6aa8ddf7a3fa patch 8.2.2124: Vim9: a range cannot be computed at runtime
Bram Moolenaar <Bram@vim.org>
parents: 23102
diff changeset
3797 tv->vval.v_number = ea.line2;
6aa8ddf7a3fa patch 8.2.2124: Vim9: a range cannot be computed at runtime
Bram Moolenaar <Bram@vim.org>
parents: 23102
diff changeset
3798 }
6aa8ddf7a3fa patch 8.2.2124: Vim9: a range cannot be computed at runtime
Bram Moolenaar <Bram@vim.org>
parents: 23102
diff changeset
3799 break;
6aa8ddf7a3fa patch 8.2.2124: Vim9: a range cannot be computed at runtime
Bram Moolenaar <Bram@vim.org>
parents: 23102
diff changeset
3800
22176
6941d3205be9 patch 8.2.1637: Vim9: :put ={expr} does not work inside :def function
Bram Moolenaar <Bram@vim.org>
parents: 22004
diff changeset
3801 case ISN_PUT:
6941d3205be9 patch 8.2.1637: Vim9: :put ={expr} does not work inside :def function
Bram Moolenaar <Bram@vim.org>
parents: 22004
diff changeset
3802 {
6941d3205be9 patch 8.2.1637: Vim9: :put ={expr} does not work inside :def function
Bram Moolenaar <Bram@vim.org>
parents: 22004
diff changeset
3803 int regname = iptr->isn_arg.put.put_regname;
6941d3205be9 patch 8.2.1637: Vim9: :put ={expr} does not work inside :def function
Bram Moolenaar <Bram@vim.org>
parents: 22004
diff changeset
3804 linenr_T lnum = iptr->isn_arg.put.put_lnum;
6941d3205be9 patch 8.2.1637: Vim9: :put ={expr} does not work inside :def function
Bram Moolenaar <Bram@vim.org>
parents: 22004
diff changeset
3805 char_u *expr = NULL;
6941d3205be9 patch 8.2.1637: Vim9: :put ={expr} does not work inside :def function
Bram Moolenaar <Bram@vim.org>
parents: 22004
diff changeset
3806 int dir = FORWARD;
6941d3205be9 patch 8.2.1637: Vim9: :put ={expr} does not work inside :def function
Bram Moolenaar <Bram@vim.org>
parents: 22004
diff changeset
3807
23156
6aa8ddf7a3fa patch 8.2.2124: Vim9: a range cannot be computed at runtime
Bram Moolenaar <Bram@vim.org>
parents: 23102
diff changeset
3808 if (lnum < -2)
6aa8ddf7a3fa patch 8.2.2124: Vim9: a range cannot be computed at runtime
Bram Moolenaar <Bram@vim.org>
parents: 23102
diff changeset
3809 {
6aa8ddf7a3fa patch 8.2.2124: Vim9: a range cannot be computed at runtime
Bram Moolenaar <Bram@vim.org>
parents: 23102
diff changeset
3810 // line number was put on the stack by ISN_RANGE
6aa8ddf7a3fa patch 8.2.2124: Vim9: a range cannot be computed at runtime
Bram Moolenaar <Bram@vim.org>
parents: 23102
diff changeset
3811 tv = STACK_TV_BOT(-1);
6aa8ddf7a3fa patch 8.2.2124: Vim9: a range cannot be computed at runtime
Bram Moolenaar <Bram@vim.org>
parents: 23102
diff changeset
3812 curwin->w_cursor.lnum = tv->vval.v_number;
6aa8ddf7a3fa patch 8.2.2124: Vim9: a range cannot be computed at runtime
Bram Moolenaar <Bram@vim.org>
parents: 23102
diff changeset
3813 if (lnum == LNUM_VARIABLE_RANGE_ABOVE)
6aa8ddf7a3fa patch 8.2.2124: Vim9: a range cannot be computed at runtime
Bram Moolenaar <Bram@vim.org>
parents: 23102
diff changeset
3814 dir = BACKWARD;
24488
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
3815 --ectx->ec_stack.ga_len;
23156
6aa8ddf7a3fa patch 8.2.2124: Vim9: a range cannot be computed at runtime
Bram Moolenaar <Bram@vim.org>
parents: 23102
diff changeset
3816 }
6aa8ddf7a3fa patch 8.2.2124: Vim9: a range cannot be computed at runtime
Bram Moolenaar <Bram@vim.org>
parents: 23102
diff changeset
3817 else if (lnum == -2)
22176
6941d3205be9 patch 8.2.1637: Vim9: :put ={expr} does not work inside :def function
Bram Moolenaar <Bram@vim.org>
parents: 22004
diff changeset
3818 // :put! above cursor
6941d3205be9 patch 8.2.1637: Vim9: :put ={expr} does not work inside :def function
Bram Moolenaar <Bram@vim.org>
parents: 22004
diff changeset
3819 dir = BACKWARD;
6941d3205be9 patch 8.2.1637: Vim9: :put ={expr} does not work inside :def function
Bram Moolenaar <Bram@vim.org>
parents: 22004
diff changeset
3820 else if (lnum >= 0)
6941d3205be9 patch 8.2.1637: Vim9: :put ={expr} does not work inside :def function
Bram Moolenaar <Bram@vim.org>
parents: 22004
diff changeset
3821 curwin->w_cursor.lnum = iptr->isn_arg.put.put_lnum;
23671
9ee9c4246a7f patch 8.2.2377: Vim9: crash when using a range after another expression
Bram Moolenaar <Bram@vim.org>
parents: 23656
diff changeset
3822
9ee9c4246a7f patch 8.2.2377: Vim9: crash when using a range after another expression
Bram Moolenaar <Bram@vim.org>
parents: 23656
diff changeset
3823 if (regname == '=')
9ee9c4246a7f patch 8.2.2377: Vim9: crash when using a range after another expression
Bram Moolenaar <Bram@vim.org>
parents: 23656
diff changeset
3824 {
9ee9c4246a7f patch 8.2.2377: Vim9: crash when using a range after another expression
Bram Moolenaar <Bram@vim.org>
parents: 23656
diff changeset
3825 tv = STACK_TV_BOT(-1);
9ee9c4246a7f patch 8.2.2377: Vim9: crash when using a range after another expression
Bram Moolenaar <Bram@vim.org>
parents: 23656
diff changeset
3826 if (tv->v_type == VAR_STRING)
9ee9c4246a7f patch 8.2.2377: Vim9: crash when using a range after another expression
Bram Moolenaar <Bram@vim.org>
parents: 23656
diff changeset
3827 expr = tv->vval.v_string;
9ee9c4246a7f patch 8.2.2377: Vim9: crash when using a range after another expression
Bram Moolenaar <Bram@vim.org>
parents: 23656
diff changeset
3828 else
9ee9c4246a7f patch 8.2.2377: Vim9: crash when using a range after another expression
Bram Moolenaar <Bram@vim.org>
parents: 23656
diff changeset
3829 {
9ee9c4246a7f patch 8.2.2377: Vim9: crash when using a range after another expression
Bram Moolenaar <Bram@vim.org>
parents: 23656
diff changeset
3830 expr = typval2string(tv, TRUE); // allocates value
9ee9c4246a7f patch 8.2.2377: Vim9: crash when using a range after another expression
Bram Moolenaar <Bram@vim.org>
parents: 23656
diff changeset
3831 clear_tv(tv);
9ee9c4246a7f patch 8.2.2377: Vim9: crash when using a range after another expression
Bram Moolenaar <Bram@vim.org>
parents: 23656
diff changeset
3832 }
24488
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
3833 --ectx->ec_stack.ga_len;
23671
9ee9c4246a7f patch 8.2.2377: Vim9: crash when using a range after another expression
Bram Moolenaar <Bram@vim.org>
parents: 23656
diff changeset
3834 }
22176
6941d3205be9 patch 8.2.1637: Vim9: :put ={expr} does not work inside :def function
Bram Moolenaar <Bram@vim.org>
parents: 22004
diff changeset
3835 check_cursor();
6941d3205be9 patch 8.2.1637: Vim9: :put ={expr} does not work inside :def function
Bram Moolenaar <Bram@vim.org>
parents: 22004
diff changeset
3836 do_put(regname, expr, dir, 1L, PUT_LINE|PUT_CURSLINE);
6941d3205be9 patch 8.2.1637: Vim9: :put ={expr} does not work inside :def function
Bram Moolenaar <Bram@vim.org>
parents: 22004
diff changeset
3837 vim_free(expr);
6941d3205be9 patch 8.2.1637: Vim9: :put ={expr} does not work inside :def function
Bram Moolenaar <Bram@vim.org>
parents: 22004
diff changeset
3838 }
6941d3205be9 patch 8.2.1637: Vim9: :put ={expr} does not work inside :def function
Bram Moolenaar <Bram@vim.org>
parents: 22004
diff changeset
3839 break;
6941d3205be9 patch 8.2.1637: Vim9: :put ={expr} does not work inside :def function
Bram Moolenaar <Bram@vim.org>
parents: 22004
diff changeset
3840
22703
f2bfee4ac356 patch 8.2.1900: Vim9: command modifiers do not work
Bram Moolenaar <Bram@vim.org>
parents: 22691
diff changeset
3841 case ISN_CMDMOD:
24488
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
3842 ectx->ec_funclocal.floc_save_cmdmod = cmdmod;
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
3843 ectx->ec_funclocal.floc_restore_cmdmod = TRUE;
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
3844 ectx->ec_funclocal.floc_restore_cmdmod_stacklen =
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
3845 ectx->ec_stack.ga_len;
22703
f2bfee4ac356 patch 8.2.1900: Vim9: command modifiers do not work
Bram Moolenaar <Bram@vim.org>
parents: 22691
diff changeset
3846 cmdmod = *iptr->isn_arg.cmdmod.cf_cmdmod;
f2bfee4ac356 patch 8.2.1900: Vim9: command modifiers do not work
Bram Moolenaar <Bram@vim.org>
parents: 22691
diff changeset
3847 apply_cmdmod(&cmdmod);
22691
dda110a14be4 patch 8.2.1894: Vim9: command modifiers are not supported
Bram Moolenaar <Bram@vim.org>
parents: 22641
diff changeset
3848 break;
dda110a14be4 patch 8.2.1894: Vim9: command modifiers are not supported
Bram Moolenaar <Bram@vim.org>
parents: 22641
diff changeset
3849
22703
f2bfee4ac356 patch 8.2.1900: Vim9: command modifiers do not work
Bram Moolenaar <Bram@vim.org>
parents: 22691
diff changeset
3850 case ISN_CMDMOD_REV:
f2bfee4ac356 patch 8.2.1900: Vim9: command modifiers do not work
Bram Moolenaar <Bram@vim.org>
parents: 22691
diff changeset
3851 // filter regprog is owned by the instruction, don't free it
f2bfee4ac356 patch 8.2.1900: Vim9: command modifiers do not work
Bram Moolenaar <Bram@vim.org>
parents: 22691
diff changeset
3852 cmdmod.cmod_filter_regmatch.regprog = NULL;
f2bfee4ac356 patch 8.2.1900: Vim9: command modifiers do not work
Bram Moolenaar <Bram@vim.org>
parents: 22691
diff changeset
3853 undo_cmdmod(&cmdmod);
24488
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
3854 cmdmod = ectx->ec_funclocal.floc_save_cmdmod;
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
3855 ectx->ec_funclocal.floc_restore_cmdmod = FALSE;
22691
dda110a14be4 patch 8.2.1894: Vim9: command modifiers are not supported
Bram Moolenaar <Bram@vim.org>
parents: 22641
diff changeset
3856 break;
dda110a14be4 patch 8.2.1894: Vim9: command modifiers are not supported
Bram Moolenaar <Bram@vim.org>
parents: 22641
diff changeset
3857
22975
a943b175586a patch 8.2.2034: Vim9: list unpack in for statement not compiled yet
Bram Moolenaar <Bram@vim.org>
parents: 22973
diff changeset
3858 case ISN_UNPACK:
a943b175586a patch 8.2.2034: Vim9: list unpack in for statement not compiled yet
Bram Moolenaar <Bram@vim.org>
parents: 22973
diff changeset
3859 {
a943b175586a patch 8.2.2034: Vim9: list unpack in for statement not compiled yet
Bram Moolenaar <Bram@vim.org>
parents: 22973
diff changeset
3860 int count = iptr->isn_arg.unpack.unp_count;
a943b175586a patch 8.2.2034: Vim9: list unpack in for statement not compiled yet
Bram Moolenaar <Bram@vim.org>
parents: 22973
diff changeset
3861 int semicolon = iptr->isn_arg.unpack.unp_semicolon;
a943b175586a patch 8.2.2034: Vim9: list unpack in for statement not compiled yet
Bram Moolenaar <Bram@vim.org>
parents: 22973
diff changeset
3862 list_T *l;
a943b175586a patch 8.2.2034: Vim9: list unpack in for statement not compiled yet
Bram Moolenaar <Bram@vim.org>
parents: 22973
diff changeset
3863 listitem_T *li;
a943b175586a patch 8.2.2034: Vim9: list unpack in for statement not compiled yet
Bram Moolenaar <Bram@vim.org>
parents: 22973
diff changeset
3864 int i;
a943b175586a patch 8.2.2034: Vim9: list unpack in for statement not compiled yet
Bram Moolenaar <Bram@vim.org>
parents: 22973
diff changeset
3865
a943b175586a patch 8.2.2034: Vim9: list unpack in for statement not compiled yet
Bram Moolenaar <Bram@vim.org>
parents: 22973
diff changeset
3866 // Check there is a valid list to unpack.
a943b175586a patch 8.2.2034: Vim9: list unpack in for statement not compiled yet
Bram Moolenaar <Bram@vim.org>
parents: 22973
diff changeset
3867 tv = STACK_TV_BOT(-1);
a943b175586a patch 8.2.2034: Vim9: list unpack in for statement not compiled yet
Bram Moolenaar <Bram@vim.org>
parents: 22973
diff changeset
3868 if (tv->v_type != VAR_LIST)
a943b175586a patch 8.2.2034: Vim9: list unpack in for statement not compiled yet
Bram Moolenaar <Bram@vim.org>
parents: 22973
diff changeset
3869 {
a943b175586a patch 8.2.2034: Vim9: list unpack in for statement not compiled yet
Bram Moolenaar <Bram@vim.org>
parents: 22973
diff changeset
3870 SOURCING_LNUM = iptr->isn_lnum;
a943b175586a patch 8.2.2034: Vim9: list unpack in for statement not compiled yet
Bram Moolenaar <Bram@vim.org>
parents: 22973
diff changeset
3871 emsg(_(e_for_argument_must_be_sequence_of_lists));
a943b175586a patch 8.2.2034: Vim9: list unpack in for statement not compiled yet
Bram Moolenaar <Bram@vim.org>
parents: 22973
diff changeset
3872 goto on_error;
a943b175586a patch 8.2.2034: Vim9: list unpack in for statement not compiled yet
Bram Moolenaar <Bram@vim.org>
parents: 22973
diff changeset
3873 }
a943b175586a patch 8.2.2034: Vim9: list unpack in for statement not compiled yet
Bram Moolenaar <Bram@vim.org>
parents: 22973
diff changeset
3874 l = tv->vval.v_list;
a943b175586a patch 8.2.2034: Vim9: list unpack in for statement not compiled yet
Bram Moolenaar <Bram@vim.org>
parents: 22973
diff changeset
3875 if (l == NULL
a943b175586a patch 8.2.2034: Vim9: list unpack in for statement not compiled yet
Bram Moolenaar <Bram@vim.org>
parents: 22973
diff changeset
3876 || l->lv_len < (semicolon ? count - 1 : count))
a943b175586a patch 8.2.2034: Vim9: list unpack in for statement not compiled yet
Bram Moolenaar <Bram@vim.org>
parents: 22973
diff changeset
3877 {
a943b175586a patch 8.2.2034: Vim9: list unpack in for statement not compiled yet
Bram Moolenaar <Bram@vim.org>
parents: 22973
diff changeset
3878 SOURCING_LNUM = iptr->isn_lnum;
a943b175586a patch 8.2.2034: Vim9: list unpack in for statement not compiled yet
Bram Moolenaar <Bram@vim.org>
parents: 22973
diff changeset
3879 emsg(_(e_list_value_does_not_have_enough_items));
a943b175586a patch 8.2.2034: Vim9: list unpack in for statement not compiled yet
Bram Moolenaar <Bram@vim.org>
parents: 22973
diff changeset
3880 goto on_error;
a943b175586a patch 8.2.2034: Vim9: list unpack in for statement not compiled yet
Bram Moolenaar <Bram@vim.org>
parents: 22973
diff changeset
3881 }
a943b175586a patch 8.2.2034: Vim9: list unpack in for statement not compiled yet
Bram Moolenaar <Bram@vim.org>
parents: 22973
diff changeset
3882 else if (!semicolon && l->lv_len > count)
a943b175586a patch 8.2.2034: Vim9: list unpack in for statement not compiled yet
Bram Moolenaar <Bram@vim.org>
parents: 22973
diff changeset
3883 {
a943b175586a patch 8.2.2034: Vim9: list unpack in for statement not compiled yet
Bram Moolenaar <Bram@vim.org>
parents: 22973
diff changeset
3884 SOURCING_LNUM = iptr->isn_lnum;
a943b175586a patch 8.2.2034: Vim9: list unpack in for statement not compiled yet
Bram Moolenaar <Bram@vim.org>
parents: 22973
diff changeset
3885 emsg(_(e_list_value_has_more_items_than_targets));
a943b175586a patch 8.2.2034: Vim9: list unpack in for statement not compiled yet
Bram Moolenaar <Bram@vim.org>
parents: 22973
diff changeset
3886 goto on_error;
a943b175586a patch 8.2.2034: Vim9: list unpack in for statement not compiled yet
Bram Moolenaar <Bram@vim.org>
parents: 22973
diff changeset
3887 }
a943b175586a patch 8.2.2034: Vim9: list unpack in for statement not compiled yet
Bram Moolenaar <Bram@vim.org>
parents: 22973
diff changeset
3888
a943b175586a patch 8.2.2034: Vim9: list unpack in for statement not compiled yet
Bram Moolenaar <Bram@vim.org>
parents: 22973
diff changeset
3889 CHECK_LIST_MATERIALIZE(l);
24488
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
3890 if (GA_GROW(&ectx->ec_stack, count - 1) == FAIL)
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
3891 return FAIL;
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
3892 ectx->ec_stack.ga_len += count - 1;
22975
a943b175586a patch 8.2.2034: Vim9: list unpack in for statement not compiled yet
Bram Moolenaar <Bram@vim.org>
parents: 22973
diff changeset
3893
a943b175586a patch 8.2.2034: Vim9: list unpack in for statement not compiled yet
Bram Moolenaar <Bram@vim.org>
parents: 22973
diff changeset
3894 // Variable after semicolon gets a list with the remaining
a943b175586a patch 8.2.2034: Vim9: list unpack in for statement not compiled yet
Bram Moolenaar <Bram@vim.org>
parents: 22973
diff changeset
3895 // items.
a943b175586a patch 8.2.2034: Vim9: list unpack in for statement not compiled yet
Bram Moolenaar <Bram@vim.org>
parents: 22973
diff changeset
3896 if (semicolon)
a943b175586a patch 8.2.2034: Vim9: list unpack in for statement not compiled yet
Bram Moolenaar <Bram@vim.org>
parents: 22973
diff changeset
3897 {
a943b175586a patch 8.2.2034: Vim9: list unpack in for statement not compiled yet
Bram Moolenaar <Bram@vim.org>
parents: 22973
diff changeset
3898 list_T *rem_list =
a943b175586a patch 8.2.2034: Vim9: list unpack in for statement not compiled yet
Bram Moolenaar <Bram@vim.org>
parents: 22973
diff changeset
3899 list_alloc_with_items(l->lv_len - count + 1);
a943b175586a patch 8.2.2034: Vim9: list unpack in for statement not compiled yet
Bram Moolenaar <Bram@vim.org>
parents: 22973
diff changeset
3900
a943b175586a patch 8.2.2034: Vim9: list unpack in for statement not compiled yet
Bram Moolenaar <Bram@vim.org>
parents: 22973
diff changeset
3901 if (rem_list == NULL)
24488
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
3902 return FAIL;
22975
a943b175586a patch 8.2.2034: Vim9: list unpack in for statement not compiled yet
Bram Moolenaar <Bram@vim.org>
parents: 22973
diff changeset
3903 tv = STACK_TV_BOT(-count);
a943b175586a patch 8.2.2034: Vim9: list unpack in for statement not compiled yet
Bram Moolenaar <Bram@vim.org>
parents: 22973
diff changeset
3904 tv->vval.v_list = rem_list;
a943b175586a patch 8.2.2034: Vim9: list unpack in for statement not compiled yet
Bram Moolenaar <Bram@vim.org>
parents: 22973
diff changeset
3905 ++rem_list->lv_refcount;
a943b175586a patch 8.2.2034: Vim9: list unpack in for statement not compiled yet
Bram Moolenaar <Bram@vim.org>
parents: 22973
diff changeset
3906 tv->v_lock = 0;
a943b175586a patch 8.2.2034: Vim9: list unpack in for statement not compiled yet
Bram Moolenaar <Bram@vim.org>
parents: 22973
diff changeset
3907 li = l->lv_first;
a943b175586a patch 8.2.2034: Vim9: list unpack in for statement not compiled yet
Bram Moolenaar <Bram@vim.org>
parents: 22973
diff changeset
3908 for (i = 0; i < count - 1; ++i)
a943b175586a patch 8.2.2034: Vim9: list unpack in for statement not compiled yet
Bram Moolenaar <Bram@vim.org>
parents: 22973
diff changeset
3909 li = li->li_next;
a943b175586a patch 8.2.2034: Vim9: list unpack in for statement not compiled yet
Bram Moolenaar <Bram@vim.org>
parents: 22973
diff changeset
3910 for (i = 0; li != NULL; ++i)
a943b175586a patch 8.2.2034: Vim9: list unpack in for statement not compiled yet
Bram Moolenaar <Bram@vim.org>
parents: 22973
diff changeset
3911 {
a943b175586a patch 8.2.2034: Vim9: list unpack in for statement not compiled yet
Bram Moolenaar <Bram@vim.org>
parents: 22973
diff changeset
3912 list_set_item(rem_list, i, &li->li_tv);
a943b175586a patch 8.2.2034: Vim9: list unpack in for statement not compiled yet
Bram Moolenaar <Bram@vim.org>
parents: 22973
diff changeset
3913 li = li->li_next;
a943b175586a patch 8.2.2034: Vim9: list unpack in for statement not compiled yet
Bram Moolenaar <Bram@vim.org>
parents: 22973
diff changeset
3914 }
a943b175586a patch 8.2.2034: Vim9: list unpack in for statement not compiled yet
Bram Moolenaar <Bram@vim.org>
parents: 22973
diff changeset
3915 --count;
a943b175586a patch 8.2.2034: Vim9: list unpack in for statement not compiled yet
Bram Moolenaar <Bram@vim.org>
parents: 22973
diff changeset
3916 }
a943b175586a patch 8.2.2034: Vim9: list unpack in for statement not compiled yet
Bram Moolenaar <Bram@vim.org>
parents: 22973
diff changeset
3917
a943b175586a patch 8.2.2034: Vim9: list unpack in for statement not compiled yet
Bram Moolenaar <Bram@vim.org>
parents: 22973
diff changeset
3918 // Produce the values in reverse order, first item last.
a943b175586a patch 8.2.2034: Vim9: list unpack in for statement not compiled yet
Bram Moolenaar <Bram@vim.org>
parents: 22973
diff changeset
3919 li = l->lv_first;
a943b175586a patch 8.2.2034: Vim9: list unpack in for statement not compiled yet
Bram Moolenaar <Bram@vim.org>
parents: 22973
diff changeset
3920 for (i = 0; i < count; ++i)
a943b175586a patch 8.2.2034: Vim9: list unpack in for statement not compiled yet
Bram Moolenaar <Bram@vim.org>
parents: 22973
diff changeset
3921 {
a943b175586a patch 8.2.2034: Vim9: list unpack in for statement not compiled yet
Bram Moolenaar <Bram@vim.org>
parents: 22973
diff changeset
3922 tv = STACK_TV_BOT(-i - 1);
a943b175586a patch 8.2.2034: Vim9: list unpack in for statement not compiled yet
Bram Moolenaar <Bram@vim.org>
parents: 22973
diff changeset
3923 copy_tv(&li->li_tv, tv);
a943b175586a patch 8.2.2034: Vim9: list unpack in for statement not compiled yet
Bram Moolenaar <Bram@vim.org>
parents: 22973
diff changeset
3924 li = li->li_next;
a943b175586a patch 8.2.2034: Vim9: list unpack in for statement not compiled yet
Bram Moolenaar <Bram@vim.org>
parents: 22973
diff changeset
3925 }
a943b175586a patch 8.2.2034: Vim9: list unpack in for statement not compiled yet
Bram Moolenaar <Bram@vim.org>
parents: 22973
diff changeset
3926
a943b175586a patch 8.2.2034: Vim9: list unpack in for statement not compiled yet
Bram Moolenaar <Bram@vim.org>
parents: 22973
diff changeset
3927 list_unref(l);
a943b175586a patch 8.2.2034: Vim9: list unpack in for statement not compiled yet
Bram Moolenaar <Bram@vim.org>
parents: 22973
diff changeset
3928 }
a943b175586a patch 8.2.2034: Vim9: list unpack in for statement not compiled yet
Bram Moolenaar <Bram@vim.org>
parents: 22973
diff changeset
3929 break;
a943b175586a patch 8.2.2034: Vim9: list unpack in for statement not compiled yet
Bram Moolenaar <Bram@vim.org>
parents: 22973
diff changeset
3930
23717
e3720756acdc patch 8.2.2400: Vim9: compiled functions are not profiled
Bram Moolenaar <Bram@vim.org>
parents: 23699
diff changeset
3931 case ISN_PROF_START:
e3720756acdc patch 8.2.2400: Vim9: compiled functions are not profiled
Bram Moolenaar <Bram@vim.org>
parents: 23699
diff changeset
3932 case ISN_PROF_END:
e3720756acdc patch 8.2.2400: Vim9: compiled functions are not profiled
Bram Moolenaar <Bram@vim.org>
parents: 23699
diff changeset
3933 {
23719
1a7c2685d780 patch 8.2.2401: build fails without +profiling feature
Bram Moolenaar <Bram@vim.org>
parents: 23717
diff changeset
3934 #ifdef FEAT_PROFILE
23717
e3720756acdc patch 8.2.2400: Vim9: compiled functions are not profiled
Bram Moolenaar <Bram@vim.org>
parents: 23699
diff changeset
3935 funccall_T cookie;
e3720756acdc patch 8.2.2400: Vim9: compiled functions are not profiled
Bram Moolenaar <Bram@vim.org>
parents: 23699
diff changeset
3936 ufunc_T *cur_ufunc =
e3720756acdc patch 8.2.2400: Vim9: compiled functions are not profiled
Bram Moolenaar <Bram@vim.org>
parents: 23699
diff changeset
3937 (((dfunc_T *)def_functions.ga_data)
24488
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
3938 + ectx->ec_dfunc_idx)->df_ufunc;
23717
e3720756acdc patch 8.2.2400: Vim9: compiled functions are not profiled
Bram Moolenaar <Bram@vim.org>
parents: 23699
diff changeset
3939
e3720756acdc patch 8.2.2400: Vim9: compiled functions are not profiled
Bram Moolenaar <Bram@vim.org>
parents: 23699
diff changeset
3940 cookie.func = cur_ufunc;
e3720756acdc patch 8.2.2400: Vim9: compiled functions are not profiled
Bram Moolenaar <Bram@vim.org>
parents: 23699
diff changeset
3941 if (iptr->isn_type == ISN_PROF_START)
e3720756acdc patch 8.2.2400: Vim9: compiled functions are not profiled
Bram Moolenaar <Bram@vim.org>
parents: 23699
diff changeset
3942 {
e3720756acdc patch 8.2.2400: Vim9: compiled functions are not profiled
Bram Moolenaar <Bram@vim.org>
parents: 23699
diff changeset
3943 func_line_start(&cookie, iptr->isn_lnum);
e3720756acdc patch 8.2.2400: Vim9: compiled functions are not profiled
Bram Moolenaar <Bram@vim.org>
parents: 23699
diff changeset
3944 // if we get here the instruction is executed
e3720756acdc patch 8.2.2400: Vim9: compiled functions are not profiled
Bram Moolenaar <Bram@vim.org>
parents: 23699
diff changeset
3945 func_line_exec(&cookie);
e3720756acdc patch 8.2.2400: Vim9: compiled functions are not profiled
Bram Moolenaar <Bram@vim.org>
parents: 23699
diff changeset
3946 }
e3720756acdc patch 8.2.2400: Vim9: compiled functions are not profiled
Bram Moolenaar <Bram@vim.org>
parents: 23699
diff changeset
3947 else
e3720756acdc patch 8.2.2400: Vim9: compiled functions are not profiled
Bram Moolenaar <Bram@vim.org>
parents: 23699
diff changeset
3948 func_line_end(&cookie);
23719
1a7c2685d780 patch 8.2.2401: build fails without +profiling feature
Bram Moolenaar <Bram@vim.org>
parents: 23717
diff changeset
3949 #endif
23717
e3720756acdc patch 8.2.2400: Vim9: compiled functions are not profiled
Bram Moolenaar <Bram@vim.org>
parents: 23699
diff changeset
3950 }
e3720756acdc patch 8.2.2400: Vim9: compiled functions are not profiled
Bram Moolenaar <Bram@vim.org>
parents: 23699
diff changeset
3951 break;
e3720756acdc patch 8.2.2400: Vim9: compiled functions are not profiled
Bram Moolenaar <Bram@vim.org>
parents: 23699
diff changeset
3952
21232
3f14e0d4a4dd patch 8.2.1167: Vim9: builtin function method call only supports first arg
Bram Moolenaar <Bram@vim.org>
parents: 21206
diff changeset
3953 case ISN_SHUFFLE:
3f14e0d4a4dd patch 8.2.1167: Vim9: builtin function method call only supports first arg
Bram Moolenaar <Bram@vim.org>
parents: 21206
diff changeset
3954 {
22975
a943b175586a patch 8.2.2034: Vim9: list unpack in for statement not compiled yet
Bram Moolenaar <Bram@vim.org>
parents: 22973
diff changeset
3955 typval_T tmp_tv;
a943b175586a patch 8.2.2034: Vim9: list unpack in for statement not compiled yet
Bram Moolenaar <Bram@vim.org>
parents: 22973
diff changeset
3956 int item = iptr->isn_arg.shuffle.shfl_item;
a943b175586a patch 8.2.2034: Vim9: list unpack in for statement not compiled yet
Bram Moolenaar <Bram@vim.org>
parents: 22973
diff changeset
3957 int up = iptr->isn_arg.shuffle.shfl_up;
21232
3f14e0d4a4dd patch 8.2.1167: Vim9: builtin function method call only supports first arg
Bram Moolenaar <Bram@vim.org>
parents: 21206
diff changeset
3958
3f14e0d4a4dd patch 8.2.1167: Vim9: builtin function method call only supports first arg
Bram Moolenaar <Bram@vim.org>
parents: 21206
diff changeset
3959 tmp_tv = *STACK_TV_BOT(-item);
3f14e0d4a4dd patch 8.2.1167: Vim9: builtin function method call only supports first arg
Bram Moolenaar <Bram@vim.org>
parents: 21206
diff changeset
3960 for ( ; up > 0 && item > 1; --up)
3f14e0d4a4dd patch 8.2.1167: Vim9: builtin function method call only supports first arg
Bram Moolenaar <Bram@vim.org>
parents: 21206
diff changeset
3961 {
3f14e0d4a4dd patch 8.2.1167: Vim9: builtin function method call only supports first arg
Bram Moolenaar <Bram@vim.org>
parents: 21206
diff changeset
3962 *STACK_TV_BOT(-item) = *STACK_TV_BOT(-item + 1);
3f14e0d4a4dd patch 8.2.1167: Vim9: builtin function method call only supports first arg
Bram Moolenaar <Bram@vim.org>
parents: 21206
diff changeset
3963 --item;
3f14e0d4a4dd patch 8.2.1167: Vim9: builtin function method call only supports first arg
Bram Moolenaar <Bram@vim.org>
parents: 21206
diff changeset
3964 }
3f14e0d4a4dd patch 8.2.1167: Vim9: builtin function method call only supports first arg
Bram Moolenaar <Bram@vim.org>
parents: 21206
diff changeset
3965 *STACK_TV_BOT(-item) = tmp_tv;
3f14e0d4a4dd patch 8.2.1167: Vim9: builtin function method call only supports first arg
Bram Moolenaar <Bram@vim.org>
parents: 21206
diff changeset
3966 }
3f14e0d4a4dd patch 8.2.1167: Vim9: builtin function method call only supports first arg
Bram Moolenaar <Bram@vim.org>
parents: 21206
diff changeset
3967 break;
3f14e0d4a4dd patch 8.2.1167: Vim9: builtin function method call only supports first arg
Bram Moolenaar <Bram@vim.org>
parents: 21206
diff changeset
3968
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3969 case ISN_DROP:
24488
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
3970 --ectx->ec_stack.ga_len;
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3971 clear_tv(STACK_TV_BOT(0));
24488
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
3972 ectx->ec_where.wt_index = 0;
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
3973 ectx->ec_where.wt_variable = FALSE;
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3974 break;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3975 }
21365
fca850f4d603 patch 8.2.1233: Vim9: various errors not caught by try/catch
Bram Moolenaar <Bram@vim.org>
parents: 21359
diff changeset
3976 continue;
fca850f4d603 patch 8.2.1233: Vim9: various errors not caught by try/catch
Bram Moolenaar <Bram@vim.org>
parents: 21359
diff changeset
3977
21375
92e2ed2a2778 patch 8.2.1238: Vim9: a few remaining errors not caught by try/catch
Bram Moolenaar <Bram@vim.org>
parents: 21371
diff changeset
3978 func_return:
22314
41e118669df3 patch 8.2.1706: Vim9: crash after running into the "Multiple closures" error
Bram Moolenaar <Bram@vim.org>
parents: 22310
diff changeset
3979 // Restore previous function. If the frame pointer is where we started
41e118669df3 patch 8.2.1706: Vim9: crash after running into the "Multiple closures" error
Bram Moolenaar <Bram@vim.org>
parents: 22310
diff changeset
3980 // then there is none and we are done.
24488
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
3981 if (ectx->ec_frame_idx == ectx->ec_initial_frame_idx)
21375
92e2ed2a2778 patch 8.2.1238: Vim9: a few remaining errors not caught by try/catch
Bram Moolenaar <Bram@vim.org>
parents: 21371
diff changeset
3982 goto done;
22314
41e118669df3 patch 8.2.1706: Vim9: crash after running into the "Multiple closures" error
Bram Moolenaar <Bram@vim.org>
parents: 22310
diff changeset
3983
24488
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
3984 if (func_return(ectx) == FAIL)
21375
92e2ed2a2778 patch 8.2.1238: Vim9: a few remaining errors not caught by try/catch
Bram Moolenaar <Bram@vim.org>
parents: 21371
diff changeset
3985 // only fails when out of memory
24488
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
3986 return FAIL;
21421
0f0fee4122d3 patch 8.2.1261: Vim9: common type of function not tested
Bram Moolenaar <Bram@vim.org>
parents: 21401
diff changeset
3987 continue;
21375
92e2ed2a2778 patch 8.2.1238: Vim9: a few remaining errors not caught by try/catch
Bram Moolenaar <Bram@vim.org>
parents: 21371
diff changeset
3988
21365
fca850f4d603 patch 8.2.1233: Vim9: various errors not caught by try/catch
Bram Moolenaar <Bram@vim.org>
parents: 21359
diff changeset
3989 on_error:
23074
cd885eb0e50c patch 8.2.2083: Vim9: crash when using ":silent!" and getting member fails
Bram Moolenaar <Bram@vim.org>
parents: 23009
diff changeset
3990 // Jump here for an error that does not require aborting execution.
23102
3239b0f3c592 patch 8.2.2097: Vim9: using :silent! when calling a function prevents abort
Bram Moolenaar <Bram@vim.org>
parents: 23100
diff changeset
3991 // If "emsg_silent" is set then ignore the error, unless it was set
3239b0f3c592 patch 8.2.2097: Vim9: using :silent! when calling a function prevents abort
Bram Moolenaar <Bram@vim.org>
parents: 23100
diff changeset
3992 // when calling the function.
24488
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
3993 if (did_emsg_cumul + did_emsg == ectx->ec_did_emsg_before
23102
3239b0f3c592 patch 8.2.2097: Vim9: using :silent! when calling a function prevents abort
Bram Moolenaar <Bram@vim.org>
parents: 23100
diff changeset
3994 && emsg_silent && did_emsg_def == 0)
23689
e7f5931b46ca patch 8.2.2386: Vim9: crash when using ":silent! put"
Bram Moolenaar <Bram@vim.org>
parents: 23681
diff changeset
3995 {
e7f5931b46ca patch 8.2.2386: Vim9: crash when using ":silent! put"
Bram Moolenaar <Bram@vim.org>
parents: 23681
diff changeset
3996 // If a sequence of instructions causes an error while ":silent!"
e7f5931b46ca patch 8.2.2386: Vim9: crash when using ":silent! put"
Bram Moolenaar <Bram@vim.org>
parents: 23681
diff changeset
3997 // was used, restore the stack length and jump ahead to restoring
e7f5931b46ca patch 8.2.2386: Vim9: crash when using ":silent! put"
Bram Moolenaar <Bram@vim.org>
parents: 23681
diff changeset
3998 // the cmdmod.
24488
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
3999 if (ectx->ec_funclocal.floc_restore_cmdmod)
23689
e7f5931b46ca patch 8.2.2386: Vim9: crash when using ":silent! put"
Bram Moolenaar <Bram@vim.org>
parents: 23681
diff changeset
4000 {
24488
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4001 while (ectx->ec_stack.ga_len
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4002 > ectx->ec_funclocal.floc_restore_cmdmod_stacklen)
23689
e7f5931b46ca patch 8.2.2386: Vim9: crash when using ":silent! put"
Bram Moolenaar <Bram@vim.org>
parents: 23681
diff changeset
4003 {
24488
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4004 --ectx->ec_stack.ga_len;
23689
e7f5931b46ca patch 8.2.2386: Vim9: crash when using ":silent! put"
Bram Moolenaar <Bram@vim.org>
parents: 23681
diff changeset
4005 clear_tv(STACK_TV_BOT(0));
e7f5931b46ca patch 8.2.2386: Vim9: crash when using ":silent! put"
Bram Moolenaar <Bram@vim.org>
parents: 23681
diff changeset
4006 }
24488
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4007 while (ectx->ec_instr[ectx->ec_iidx].isn_type != ISN_CMDMOD_REV)
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4008 ++ectx->ec_iidx;
23689
e7f5931b46ca patch 8.2.2386: Vim9: crash when using ":silent! put"
Bram Moolenaar <Bram@vim.org>
parents: 23681
diff changeset
4009 }
22760
d235c5fa0bbe patch 8.2.1928: Vim9: "silent!" not effective when list index is wrong
Bram Moolenaar <Bram@vim.org>
parents: 22758
diff changeset
4010 continue;
23689
e7f5931b46ca patch 8.2.2386: Vim9: crash when using ":silent! put"
Bram Moolenaar <Bram@vim.org>
parents: 23681
diff changeset
4011 }
23074
cd885eb0e50c patch 8.2.2083: Vim9: crash when using ":silent!" and getting member fails
Bram Moolenaar <Bram@vim.org>
parents: 23009
diff changeset
4012 on_fatal_error:
cd885eb0e50c patch 8.2.2083: Vim9: crash when using ":silent!" and getting member fails
Bram Moolenaar <Bram@vim.org>
parents: 23009
diff changeset
4013 // Jump here for an error that messes up the stack.
22736
56907027dba7 patch 8.2.1916: Vim9: function call is aborted even when "silent!" is used
Bram Moolenaar <Bram@vim.org>
parents: 22715
diff changeset
4014 // If we are not inside a try-catch started here, abort execution.
24488
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4015 if (trylevel <= ectx->ec_trylevel_at_start)
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4016 return FAIL;
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4017 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4018
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4019 done:
24488
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4020 return OK;
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4021 }
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4022
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4023 /*
24606
a4fda40e0bb9 patch 8.2.2842: Vim9: skip argument to searchpair() is not compiled
Bram Moolenaar <Bram@vim.org>
parents: 24594
diff changeset
4024 * Execute the instructions from a VAR_INSTR typeval and put the result in
a4fda40e0bb9 patch 8.2.2842: Vim9: skip argument to searchpair() is not compiled
Bram Moolenaar <Bram@vim.org>
parents: 24594
diff changeset
4025 * "rettv".
a4fda40e0bb9 patch 8.2.2842: Vim9: skip argument to searchpair() is not compiled
Bram Moolenaar <Bram@vim.org>
parents: 24594
diff changeset
4026 * Return OK or FAIL.
a4fda40e0bb9 patch 8.2.2842: Vim9: skip argument to searchpair() is not compiled
Bram Moolenaar <Bram@vim.org>
parents: 24594
diff changeset
4027 */
a4fda40e0bb9 patch 8.2.2842: Vim9: skip argument to searchpair() is not compiled
Bram Moolenaar <Bram@vim.org>
parents: 24594
diff changeset
4028 int
a4fda40e0bb9 patch 8.2.2842: Vim9: skip argument to searchpair() is not compiled
Bram Moolenaar <Bram@vim.org>
parents: 24594
diff changeset
4029 exe_typval_instr(typval_T *tv, typval_T *rettv)
a4fda40e0bb9 patch 8.2.2842: Vim9: skip argument to searchpair() is not compiled
Bram Moolenaar <Bram@vim.org>
parents: 24594
diff changeset
4030 {
a4fda40e0bb9 patch 8.2.2842: Vim9: skip argument to searchpair() is not compiled
Bram Moolenaar <Bram@vim.org>
parents: 24594
diff changeset
4031 ectx_T *ectx = tv->vval.v_instr->instr_ectx;
a4fda40e0bb9 patch 8.2.2842: Vim9: skip argument to searchpair() is not compiled
Bram Moolenaar <Bram@vim.org>
parents: 24594
diff changeset
4032 isn_T *save_instr = ectx->ec_instr;
a4fda40e0bb9 patch 8.2.2842: Vim9: skip argument to searchpair() is not compiled
Bram Moolenaar <Bram@vim.org>
parents: 24594
diff changeset
4033 int save_iidx = ectx->ec_iidx;
a4fda40e0bb9 patch 8.2.2842: Vim9: skip argument to searchpair() is not compiled
Bram Moolenaar <Bram@vim.org>
parents: 24594
diff changeset
4034 int res;
a4fda40e0bb9 patch 8.2.2842: Vim9: skip argument to searchpair() is not compiled
Bram Moolenaar <Bram@vim.org>
parents: 24594
diff changeset
4035
a4fda40e0bb9 patch 8.2.2842: Vim9: skip argument to searchpair() is not compiled
Bram Moolenaar <Bram@vim.org>
parents: 24594
diff changeset
4036 ectx->ec_instr = tv->vval.v_instr->instr_instr;
a4fda40e0bb9 patch 8.2.2842: Vim9: skip argument to searchpair() is not compiled
Bram Moolenaar <Bram@vim.org>
parents: 24594
diff changeset
4037 res = exec_instructions(ectx);
a4fda40e0bb9 patch 8.2.2842: Vim9: skip argument to searchpair() is not compiled
Bram Moolenaar <Bram@vim.org>
parents: 24594
diff changeset
4038 if (res == OK)
a4fda40e0bb9 patch 8.2.2842: Vim9: skip argument to searchpair() is not compiled
Bram Moolenaar <Bram@vim.org>
parents: 24594
diff changeset
4039 {
a4fda40e0bb9 patch 8.2.2842: Vim9: skip argument to searchpair() is not compiled
Bram Moolenaar <Bram@vim.org>
parents: 24594
diff changeset
4040 *rettv = *STACK_TV_BOT(-1);
a4fda40e0bb9 patch 8.2.2842: Vim9: skip argument to searchpair() is not compiled
Bram Moolenaar <Bram@vim.org>
parents: 24594
diff changeset
4041 --ectx->ec_stack.ga_len;
a4fda40e0bb9 patch 8.2.2842: Vim9: skip argument to searchpair() is not compiled
Bram Moolenaar <Bram@vim.org>
parents: 24594
diff changeset
4042 }
a4fda40e0bb9 patch 8.2.2842: Vim9: skip argument to searchpair() is not compiled
Bram Moolenaar <Bram@vim.org>
parents: 24594
diff changeset
4043
a4fda40e0bb9 patch 8.2.2842: Vim9: skip argument to searchpair() is not compiled
Bram Moolenaar <Bram@vim.org>
parents: 24594
diff changeset
4044 ectx->ec_instr = save_instr;
a4fda40e0bb9 patch 8.2.2842: Vim9: skip argument to searchpair() is not compiled
Bram Moolenaar <Bram@vim.org>
parents: 24594
diff changeset
4045 ectx->ec_iidx = save_iidx;
a4fda40e0bb9 patch 8.2.2842: Vim9: skip argument to searchpair() is not compiled
Bram Moolenaar <Bram@vim.org>
parents: 24594
diff changeset
4046
a4fda40e0bb9 patch 8.2.2842: Vim9: skip argument to searchpair() is not compiled
Bram Moolenaar <Bram@vim.org>
parents: 24594
diff changeset
4047 return res;
a4fda40e0bb9 patch 8.2.2842: Vim9: skip argument to searchpair() is not compiled
Bram Moolenaar <Bram@vim.org>
parents: 24594
diff changeset
4048 }
a4fda40e0bb9 patch 8.2.2842: Vim9: skip argument to searchpair() is not compiled
Bram Moolenaar <Bram@vim.org>
parents: 24594
diff changeset
4049
a4fda40e0bb9 patch 8.2.2842: Vim9: skip argument to searchpair() is not compiled
Bram Moolenaar <Bram@vim.org>
parents: 24594
diff changeset
4050 /*
24488
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4051 * Execute the instructions from an ISN_SUBSTITUTE command, which are in
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4052 * "substitute_instr".
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4053 */
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4054 char_u *
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4055 exe_substitute_instr(void)
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4056 {
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4057 ectx_T *ectx = substitute_instr->subs_ectx;
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4058 isn_T *save_instr = ectx->ec_instr;
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4059 int save_iidx = ectx->ec_iidx;
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4060 char_u *res;
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4061
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4062 ectx->ec_instr = substitute_instr->subs_instr;
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4063 if (exec_instructions(ectx) == OK)
24339
236e9ebdb30e patch 8.2.2710: Vim9: not all tests cover script and :def function
Bram Moolenaar <Bram@vim.org>
parents: 24325
diff changeset
4064 {
24488
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4065 typval_T *tv = STACK_TV_BOT(-1);
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4066
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4067 res = vim_strsave(tv_get_string(tv));
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4068 --ectx->ec_stack.ga_len;
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4069 clear_tv(tv);
24339
236e9ebdb30e patch 8.2.2710: Vim9: not all tests cover script and :def function
Bram Moolenaar <Bram@vim.org>
parents: 24325
diff changeset
4070 }
236e9ebdb30e patch 8.2.2710: Vim9: not all tests cover script and :def function
Bram Moolenaar <Bram@vim.org>
parents: 24325
diff changeset
4071 else
236e9ebdb30e patch 8.2.2710: Vim9: not all tests cover script and :def function
Bram Moolenaar <Bram@vim.org>
parents: 24325
diff changeset
4072 {
24488
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4073 substitute_instr->subs_status = FAIL;
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4074 res = vim_strsave((char_u *)"");
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4075 }
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4076
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4077 ectx->ec_instr = save_instr;
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4078 ectx->ec_iidx = save_iidx;
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4079
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4080 return res;
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4081 }
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4082
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4083 /*
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4084 * Call a "def" function from old Vim script.
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4085 * Return OK or FAIL.
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4086 */
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4087 int
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4088 call_def_function(
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4089 ufunc_T *ufunc,
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4090 int argc_arg, // nr of arguments
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4091 typval_T *argv, // arguments
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4092 partial_T *partial, // optional partial for context
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4093 typval_T *rettv) // return value
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4094 {
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4095 ectx_T ectx; // execution context
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4096 int argc = argc_arg;
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4097 typval_T *tv;
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4098 int idx;
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4099 int ret = FAIL;
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4100 int defcount = ufunc->uf_args.ga_len - argc;
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4101 sctx_T save_current_sctx = current_sctx;
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4102 int did_emsg_before = did_emsg_cumul + did_emsg;
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4103 int save_suppress_errthrow = suppress_errthrow;
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4104 msglist_T **saved_msg_list = NULL;
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4105 msglist_T *private_msg_list = NULL;
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4106 int save_emsg_silent_def = emsg_silent_def;
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4107 int save_did_emsg_def = did_emsg_def;
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4108 int orig_funcdepth;
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4109
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4110 // Get pointer to item in the stack.
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4111 #undef STACK_TV
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4112 #define STACK_TV(idx) (((typval_T *)ectx.ec_stack.ga_data) + idx)
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4113
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4114 // Get pointer to item at the bottom of the stack, -1 is the bottom.
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4115 #undef STACK_TV_BOT
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4116 #define STACK_TV_BOT(idx) (((typval_T *)ectx.ec_stack.ga_data) + ectx.ec_stack.ga_len + idx)
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4117
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4118 // Get pointer to a local variable on the stack. Negative for arguments.
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4119 #undef STACK_TV_VAR
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4120 #define STACK_TV_VAR(idx) (((typval_T *)ectx.ec_stack.ga_data) + ectx.ec_frame_idx + STACK_FRAME_SIZE + idx)
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4121
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4122 if (ufunc->uf_def_status == UF_NOT_COMPILED
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4123 || ufunc->uf_def_status == UF_COMPILE_ERROR
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4124 || (func_needs_compiling(ufunc, PROFILING(ufunc))
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4125 && compile_def_function(ufunc, FALSE, PROFILING(ufunc), NULL)
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4126 == FAIL))
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4127 {
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4128 if (did_emsg_cumul + did_emsg == did_emsg_before)
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4129 semsg(_(e_function_is_not_compiled_str),
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4130 printable_func_name(ufunc));
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4131 return FAIL;
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4132 }
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4133
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4134 {
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4135 // Check the function was really compiled.
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4136 dfunc_T *dfunc = ((dfunc_T *)def_functions.ga_data)
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4137 + ufunc->uf_dfunc_idx;
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4138 if (INSTRUCTIONS(dfunc) == NULL)
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4139 {
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4140 iemsg("using call_def_function() on not compiled function");
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4141 return FAIL;
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4142 }
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4143 }
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4144
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4145 // If depth of calling is getting too high, don't execute the function.
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4146 orig_funcdepth = funcdepth_get();
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4147 if (funcdepth_increment() == FAIL)
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4148 return FAIL;
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4149
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4150 CLEAR_FIELD(ectx);
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4151 ectx.ec_dfunc_idx = ufunc->uf_dfunc_idx;
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4152 ga_init2(&ectx.ec_stack, sizeof(typval_T), 500);
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4153 if (ga_grow(&ectx.ec_stack, 20) == FAIL)
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4154 {
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4155 funcdepth_decrement();
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4156 return FAIL;
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4157 }
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4158 ga_init2(&ectx.ec_trystack, sizeof(trycmd_T), 10);
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4159 ga_init2(&ectx.ec_funcrefs, sizeof(partial_T *), 10);
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4160 ectx.ec_did_emsg_before = did_emsg_before;
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4161 ectx.ec_trylevel_at_start = trylevel;
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4162
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4163 idx = argc - ufunc->uf_args.ga_len;
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4164 if (idx > 0 && ufunc->uf_va_name == NULL)
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4165 {
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4166 if (idx == 1)
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4167 emsg(_(e_one_argument_too_many));
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4168 else
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4169 semsg(_(e_nr_arguments_too_many), idx);
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4170 goto failed_early;
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4171 }
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4172
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4173 // Put arguments on the stack, but no more than what the function expects.
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4174 // A lambda can be called with more arguments than it uses.
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4175 for (idx = 0; idx < argc
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4176 && (ufunc->uf_va_name != NULL || idx < ufunc->uf_args.ga_len);
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4177 ++idx)
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4178 {
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4179 if (idx >= ufunc->uf_args.ga_len - ufunc->uf_def_args.ga_len
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4180 && argv[idx].v_type == VAR_SPECIAL
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4181 && argv[idx].vval.v_number == VVAL_NONE)
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4182 {
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4183 // Use the default value.
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4184 STACK_TV_BOT(0)->v_type = VAR_UNKNOWN;
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4185 }
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4186 else
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4187 {
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4188 if (ufunc->uf_arg_types != NULL && idx < ufunc->uf_args.ga_len
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4189 && check_typval_arg_type(
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4190 ufunc->uf_arg_types[idx], &argv[idx], idx + 1) == FAIL)
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4191 goto failed_early;
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4192 copy_tv(&argv[idx], STACK_TV_BOT(0));
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4193 }
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4194 ++ectx.ec_stack.ga_len;
24339
236e9ebdb30e patch 8.2.2710: Vim9: not all tests cover script and :def function
Bram Moolenaar <Bram@vim.org>
parents: 24325
diff changeset
4195 }
24488
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4196
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4197 // Turn varargs into a list. Empty list if no args.
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4198 if (ufunc->uf_va_name != NULL)
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4199 {
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4200 int vararg_count = argc - ufunc->uf_args.ga_len;
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4201
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4202 if (vararg_count < 0)
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4203 vararg_count = 0;
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4204 else
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4205 argc -= vararg_count;
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4206 if (exe_newlist(vararg_count, &ectx) == FAIL)
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4207 goto failed_early;
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4208
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4209 // Check the type of the list items.
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4210 tv = STACK_TV_BOT(-1);
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4211 if (ufunc->uf_va_type != NULL
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4212 && ufunc->uf_va_type != &t_list_any
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4213 && ufunc->uf_va_type->tt_member != &t_any
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4214 && tv->vval.v_list != NULL)
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4215 {
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4216 type_T *expected = ufunc->uf_va_type->tt_member;
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4217 listitem_T *li = tv->vval.v_list->lv_first;
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4218
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4219 for (idx = 0; idx < vararg_count; ++idx)
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4220 {
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4221 if (check_typval_arg_type(expected, &li->li_tv,
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4222 argc + idx + 1) == FAIL)
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4223 goto failed_early;
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4224 li = li->li_next;
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4225 }
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4226 }
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4227
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4228 if (defcount > 0)
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4229 // Move varargs list to below missing default arguments.
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4230 *STACK_TV_BOT(defcount - 1) = *STACK_TV_BOT(-1);
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4231 --ectx.ec_stack.ga_len;
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4232 }
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4233
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4234 // Make space for omitted arguments, will store default value below.
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4235 // Any varargs list goes after them.
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4236 if (defcount > 0)
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4237 for (idx = 0; idx < defcount; ++idx)
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4238 {
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4239 STACK_TV_BOT(0)->v_type = VAR_UNKNOWN;
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4240 ++ectx.ec_stack.ga_len;
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4241 }
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4242 if (ufunc->uf_va_name != NULL)
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4243 ++ectx.ec_stack.ga_len;
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4244
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4245 // Frame pointer points to just after arguments.
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4246 ectx.ec_frame_idx = ectx.ec_stack.ga_len;
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4247 ectx.ec_initial_frame_idx = ectx.ec_frame_idx;
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4248
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4249 {
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4250 dfunc_T *dfunc = ((dfunc_T *)def_functions.ga_data)
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4251 + ufunc->uf_dfunc_idx;
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4252 ufunc_T *base_ufunc = dfunc->df_ufunc;
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4253
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4254 // "uf_partial" is on the ufunc that "df_ufunc" points to, as is done
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4255 // by copy_func().
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4256 if (partial != NULL || base_ufunc->uf_partial != NULL)
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4257 {
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4258 ectx.ec_outer = ALLOC_CLEAR_ONE(outer_T);
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4259 if (ectx.ec_outer == NULL)
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4260 goto failed_early;
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4261 if (partial != NULL)
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4262 {
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4263 if (partial->pt_outer.out_stack == NULL && current_ectx != NULL)
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4264 {
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4265 if (current_ectx->ec_outer != NULL)
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4266 *ectx.ec_outer = *current_ectx->ec_outer;
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4267 }
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4268 else
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4269 *ectx.ec_outer = partial->pt_outer;
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4270 }
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4271 else
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4272 *ectx.ec_outer = base_ufunc->uf_partial->pt_outer;
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4273 ectx.ec_outer->out_up_is_copy = TRUE;
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4274 }
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4275 }
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4276
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4277 // dummy frame entries
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4278 for (idx = 0; idx < STACK_FRAME_SIZE; ++idx)
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4279 {
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4280 STACK_TV(ectx.ec_stack.ga_len)->v_type = VAR_UNKNOWN;
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4281 ++ectx.ec_stack.ga_len;
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4282 }
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4283
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4284 {
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4285 // Reserve space for local variables and any closure reference count.
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4286 dfunc_T *dfunc = ((dfunc_T *)def_functions.ga_data)
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4287 + ufunc->uf_dfunc_idx;
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4288
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4289 for (idx = 0; idx < dfunc->df_varcount; ++idx)
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4290 STACK_TV_VAR(idx)->v_type = VAR_UNKNOWN;
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4291 ectx.ec_stack.ga_len += dfunc->df_varcount;
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4292 if (dfunc->df_has_closure)
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4293 {
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4294 STACK_TV_VAR(idx)->v_type = VAR_NUMBER;
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4295 STACK_TV_VAR(idx)->vval.v_number = 0;
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4296 ++ectx.ec_stack.ga_len;
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4297 }
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4298
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4299 ectx.ec_instr = INSTRUCTIONS(dfunc);
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4300 }
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4301
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4302 // Following errors are in the function, not the caller.
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4303 // Commands behave like vim9script.
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4304 estack_push_ufunc(ufunc, 1);
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4305 current_sctx = ufunc->uf_script_ctx;
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4306 current_sctx.sc_version = SCRIPT_VERSION_VIM9;
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4307
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4308 // Use a specific location for storing error messages to be converted to an
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4309 // exception.
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4310 saved_msg_list = msg_list;
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4311 msg_list = &private_msg_list;
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4312
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4313 // Do turn errors into exceptions.
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4314 suppress_errthrow = FALSE;
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4315
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4316 // Do not delete the function while executing it.
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4317 ++ufunc->uf_calls;
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4318
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4319 // When ":silent!" was used before calling then we still abort the
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4320 // function. If ":silent!" is used in the function then we don't.
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4321 emsg_silent_def = emsg_silent;
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4322 did_emsg_def = 0;
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4323
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4324 ectx.ec_where.wt_index = 0;
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4325 ectx.ec_where.wt_variable = FALSE;
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4326
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4327 // Execute the instructions until done.
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4328 ret = exec_instructions(&ectx);
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4329 if (ret == OK)
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4330 {
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4331 // function finished, get result from the stack.
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4332 if (ufunc->uf_ret_type == &t_void)
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4333 {
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4334 rettv->v_type = VAR_VOID;
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4335 }
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4336 else
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4337 {
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4338 tv = STACK_TV_BOT(-1);
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4339 *rettv = *tv;
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4340 tv->v_type = VAR_UNKNOWN;
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4341 }
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4342 }
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4343
19532
b8f778dda1a1 patch 8.2.0323: Vim9: calling a function that is defined later is slow
Bram Moolenaar <Bram@vim.org>
parents: 19528
diff changeset
4344 // When failed need to unwind the call stack.
24488
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4345 while (ectx.ec_frame_idx != ectx.ec_initial_frame_idx)
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4346 func_return(&ectx);
21969
ba2415df82d7 patch 8.2.1534: Vim9: type error for argument type is not at call position
Bram Moolenaar <Bram@vim.org>
parents: 21933
diff changeset
4347
22401
df1d7a560b35 patch 8.2.1749: Vim9: crash when closure fails in nested function
Bram Moolenaar <Bram@vim.org>
parents: 22391
diff changeset
4348 // Deal with any remaining closures, they may be in use somewhere.
df1d7a560b35 patch 8.2.1749: Vim9: crash when closure fails in nested function
Bram Moolenaar <Bram@vim.org>
parents: 22391
diff changeset
4349 if (ectx.ec_funcrefs.ga_len > 0)
23249
43532077b5ff patch 8.2.2170: Vim9: a global function defined in a :def function fails
Bram Moolenaar <Bram@vim.org>
parents: 23233
diff changeset
4350 {
22401
df1d7a560b35 patch 8.2.1749: Vim9: crash when closure fails in nested function
Bram Moolenaar <Bram@vim.org>
parents: 22391
diff changeset
4351 handle_closure_in_use(&ectx, FALSE);
23249
43532077b5ff patch 8.2.2170: Vim9: a global function defined in a :def function fails
Bram Moolenaar <Bram@vim.org>
parents: 23233
diff changeset
4352 ga_clear(&ectx.ec_funcrefs); // TODO: should not be needed?
43532077b5ff patch 8.2.2170: Vim9: a global function defined in a :def function fails
Bram Moolenaar <Bram@vim.org>
parents: 23233
diff changeset
4353 }
22401
df1d7a560b35 patch 8.2.1749: Vim9: crash when closure fails in nested function
Bram Moolenaar <Bram@vim.org>
parents: 22391
diff changeset
4354
21969
ba2415df82d7 patch 8.2.1534: Vim9: type error for argument type is not at call position
Bram Moolenaar <Bram@vim.org>
parents: 21933
diff changeset
4355 estack_pop();
ba2415df82d7 patch 8.2.1534: Vim9: type error for argument type is not at call position
Bram Moolenaar <Bram@vim.org>
parents: 21933
diff changeset
4356 current_sctx = save_current_sctx;
ba2415df82d7 patch 8.2.1534: Vim9: type error for argument type is not at call position
Bram Moolenaar <Bram@vim.org>
parents: 21933
diff changeset
4357
24146
03fc95628eb0 patch 8.2.2614: Vim9: function is deleted while executing
Bram Moolenaar <Bram@vim.org>
parents: 24128
diff changeset
4358 // TODO: when is it safe to delete the function if it is no longer used?
03fc95628eb0 patch 8.2.2614: Vim9: function is deleted while executing
Bram Moolenaar <Bram@vim.org>
parents: 24128
diff changeset
4359 --ufunc->uf_calls;
03fc95628eb0 patch 8.2.2614: Vim9: function is deleted while executing
Bram Moolenaar <Bram@vim.org>
parents: 24128
diff changeset
4360
22621
576a69fc0066 patch 8.2.1859: Vim9: crash in unpack assignment
Bram Moolenaar <Bram@vim.org>
parents: 22614
diff changeset
4361 if (*msg_list != NULL && saved_msg_list != NULL)
576a69fc0066 patch 8.2.1859: Vim9: crash in unpack assignment
Bram Moolenaar <Bram@vim.org>
parents: 22614
diff changeset
4362 {
576a69fc0066 patch 8.2.1859: Vim9: crash in unpack assignment
Bram Moolenaar <Bram@vim.org>
parents: 22614
diff changeset
4363 msglist_T **plist = saved_msg_list;
576a69fc0066 patch 8.2.1859: Vim9: crash in unpack assignment
Bram Moolenaar <Bram@vim.org>
parents: 22614
diff changeset
4364
576a69fc0066 patch 8.2.1859: Vim9: crash in unpack assignment
Bram Moolenaar <Bram@vim.org>
parents: 22614
diff changeset
4365 // Append entries from the current msg_list (uncaught exceptions) to
576a69fc0066 patch 8.2.1859: Vim9: crash in unpack assignment
Bram Moolenaar <Bram@vim.org>
parents: 22614
diff changeset
4366 // the saved msg_list.
576a69fc0066 patch 8.2.1859: Vim9: crash in unpack assignment
Bram Moolenaar <Bram@vim.org>
parents: 22614
diff changeset
4367 while (*plist != NULL)
576a69fc0066 patch 8.2.1859: Vim9: crash in unpack assignment
Bram Moolenaar <Bram@vim.org>
parents: 22614
diff changeset
4368 plist = &(*plist)->next;
576a69fc0066 patch 8.2.1859: Vim9: crash in unpack assignment
Bram Moolenaar <Bram@vim.org>
parents: 22614
diff changeset
4369
576a69fc0066 patch 8.2.1859: Vim9: crash in unpack assignment
Bram Moolenaar <Bram@vim.org>
parents: 22614
diff changeset
4370 *plist = *msg_list;
576a69fc0066 patch 8.2.1859: Vim9: crash in unpack assignment
Bram Moolenaar <Bram@vim.org>
parents: 22614
diff changeset
4371 }
576a69fc0066 patch 8.2.1859: Vim9: crash in unpack assignment
Bram Moolenaar <Bram@vim.org>
parents: 22614
diff changeset
4372 msg_list = saved_msg_list;
576a69fc0066 patch 8.2.1859: Vim9: crash in unpack assignment
Bram Moolenaar <Bram@vim.org>
parents: 22614
diff changeset
4373
24488
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4374 if (ectx.ec_funclocal.floc_restore_cmdmod)
22703
f2bfee4ac356 patch 8.2.1900: Vim9: command modifiers do not work
Bram Moolenaar <Bram@vim.org>
parents: 22691
diff changeset
4375 {
f2bfee4ac356 patch 8.2.1900: Vim9: command modifiers do not work
Bram Moolenaar <Bram@vim.org>
parents: 22691
diff changeset
4376 cmdmod.cmod_filter_regmatch.regprog = NULL;
f2bfee4ac356 patch 8.2.1900: Vim9: command modifiers do not work
Bram Moolenaar <Bram@vim.org>
parents: 22691
diff changeset
4377 undo_cmdmod(&cmdmod);
24488
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4378 cmdmod = ectx.ec_funclocal.floc_save_cmdmod;
22703
f2bfee4ac356 patch 8.2.1900: Vim9: command modifiers do not work
Bram Moolenaar <Bram@vim.org>
parents: 22691
diff changeset
4379 }
23102
3239b0f3c592 patch 8.2.2097: Vim9: using :silent! when calling a function prevents abort
Bram Moolenaar <Bram@vim.org>
parents: 23100
diff changeset
4380 emsg_silent_def = save_emsg_silent_def;
3239b0f3c592 patch 8.2.2097: Vim9: using :silent! when calling a function prevents abort
Bram Moolenaar <Bram@vim.org>
parents: 23100
diff changeset
4381 did_emsg_def += save_did_emsg_def;
22691
dda110a14be4 patch 8.2.1894: Vim9: command modifiers are not supported
Bram Moolenaar <Bram@vim.org>
parents: 22641
diff changeset
4382
20021
4895e5cf1746 patch 8.2.0566: Vim9: variable can be used uninitialized
Bram Moolenaar <Bram@vim.org>
parents: 20017
diff changeset
4383 failed_early:
20247
e46e72aaff74 patch 8.2.0679: Vim9: incomplete support for closures
Bram Moolenaar <Bram@vim.org>
parents: 20244
diff changeset
4384 // Free all local variables, but not arguments.
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4385 for (idx = 0; idx < ectx.ec_stack.ga_len; ++idx)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4386 clear_tv(STACK_TV(idx));
20247
e46e72aaff74 patch 8.2.0679: Vim9: incomplete support for closures
Bram Moolenaar <Bram@vim.org>
parents: 20244
diff changeset
4387
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4388 vim_free(ectx.ec_stack.ga_data);
19726
ad37a198a708 patch 8.2.0419: various memory leaks in Vim9 script code
Bram Moolenaar <Bram@vim.org>
parents: 19635
diff changeset
4389 vim_free(ectx.ec_trystack.ga_data);
21401
aa7675a4a0cd patch 8.2.1251: Vim9: warning for pointer usage, test failure undetected
Bram Moolenaar <Bram@vim.org>
parents: 21399
diff changeset
4390
23559
64dfb69e7d46 patch 8.2.2322: Vim9: closure nested limiting to one level
Bram Moolenaar <Bram@vim.org>
parents: 23557
diff changeset
4391 while (ectx.ec_outer != NULL)
64dfb69e7d46 patch 8.2.2322: Vim9: closure nested limiting to one level
Bram Moolenaar <Bram@vim.org>
parents: 23557
diff changeset
4392 {
64dfb69e7d46 patch 8.2.2322: Vim9: closure nested limiting to one level
Bram Moolenaar <Bram@vim.org>
parents: 23557
diff changeset
4393 outer_T *up = ectx.ec_outer->out_up_is_copy
64dfb69e7d46 patch 8.2.2322: Vim9: closure nested limiting to one level
Bram Moolenaar <Bram@vim.org>
parents: 23557
diff changeset
4394 ? NULL : ectx.ec_outer->out_up;
64dfb69e7d46 patch 8.2.2322: Vim9: closure nested limiting to one level
Bram Moolenaar <Bram@vim.org>
parents: 23557
diff changeset
4395
64dfb69e7d46 patch 8.2.2322: Vim9: closure nested limiting to one level
Bram Moolenaar <Bram@vim.org>
parents: 23557
diff changeset
4396 vim_free(ectx.ec_outer);
64dfb69e7d46 patch 8.2.2322: Vim9: closure nested limiting to one level
Bram Moolenaar <Bram@vim.org>
parents: 23557
diff changeset
4397 ectx.ec_outer = up;
64dfb69e7d46 patch 8.2.2322: Vim9: closure nested limiting to one level
Bram Moolenaar <Bram@vim.org>
parents: 23557
diff changeset
4398 }
64dfb69e7d46 patch 8.2.2322: Vim9: closure nested limiting to one level
Bram Moolenaar <Bram@vim.org>
parents: 23557
diff changeset
4399
22310
74d0a7a30583 patch 8.2.1704: Vim9: crash in for loop when autoload script has an error
Bram Moolenaar <Bram@vim.org>
parents: 22302
diff changeset
4400 // Not sure if this is necessary.
74d0a7a30583 patch 8.2.1704: Vim9: crash in for loop when autoload script has an error
Bram Moolenaar <Bram@vim.org>
parents: 22302
diff changeset
4401 suppress_errthrow = save_suppress_errthrow;
74d0a7a30583 patch 8.2.1704: Vim9: crash in for loop when autoload script has an error
Bram Moolenaar <Bram@vim.org>
parents: 22302
diff changeset
4402
22948
707b90980de5 patch 8.2.2021: Vim9: get E1099 when autocommand resets did_emsg
Bram Moolenaar <Bram@vim.org>
parents: 22908
diff changeset
4403 if (ret != OK && did_emsg_cumul + did_emsg == did_emsg_before)
21821
0deb6f96a5a3 patch 8.2.1460: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents: 21815
diff changeset
4404 semsg(_(e_unknown_error_while_executing_str),
21401
aa7675a4a0cd patch 8.2.1251: Vim9: warning for pointer usage, test failure undetected
Bram Moolenaar <Bram@vim.org>
parents: 21399
diff changeset
4405 printable_func_name(ufunc));
22908
54219df706b5 patch 8.2.2001: Vim9: :def function does not apply 'maxfuncdepth'
Bram Moolenaar <Bram@vim.org>
parents: 22860
diff changeset
4406 funcdepth_restore(orig_funcdepth);
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4407 return ret;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4408 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4409
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4410 /*
24488
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4411 * List instructions "instr" up to "instr_count" or until ISN_FINISH.
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4412 * "ufunc" has the source lines, NULL for the instructions of ISN_SUBSTITUTE.
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4413 * "pfx" is prefixed to every line.
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4414 */
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4415 static void
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4416 list_instructions(char *pfx, isn_T *instr, int instr_count, ufunc_T *ufunc)
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4417 {
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4418 int line_idx = 0;
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4419 int prev_current = 0;
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4420 int current;
24504
e7577f79d6eb patch 8.2.2792: Vim9: :disas shows instructions for default args but no text
Bram Moolenaar <Bram@vim.org>
parents: 24490
diff changeset
4421 int def_arg_idx = 0;
24488
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4422
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4423 for (current = 0; current < instr_count; ++current)
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4424 {
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4425 isn_T *iptr = &instr[current];
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4426 char *line;
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4427
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4428 if (ufunc != NULL)
24504
e7577f79d6eb patch 8.2.2792: Vim9: :disas shows instructions for default args but no text
Bram Moolenaar <Bram@vim.org>
parents: 24490
diff changeset
4429 {
24488
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4430 while (line_idx < iptr->isn_lnum
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4431 && line_idx < ufunc->uf_lines.ga_len)
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4432 {
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4433 if (current > prev_current)
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4434 {
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4435 msg_puts("\n\n");
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4436 prev_current = current;
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4437 }
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4438 line = ((char **)ufunc->uf_lines.ga_data)[line_idx++];
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4439 if (line != NULL)
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4440 msg(line);
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4441 }
24504
e7577f79d6eb patch 8.2.2792: Vim9: :disas shows instructions for default args but no text
Bram Moolenaar <Bram@vim.org>
parents: 24490
diff changeset
4442 if (iptr->isn_type == ISN_JUMP_IF_ARG_SET)
e7577f79d6eb patch 8.2.2792: Vim9: :disas shows instructions for default args but no text
Bram Moolenaar <Bram@vim.org>
parents: 24490
diff changeset
4443 {
e7577f79d6eb patch 8.2.2792: Vim9: :disas shows instructions for default args but no text
Bram Moolenaar <Bram@vim.org>
parents: 24490
diff changeset
4444 int first_def_arg = ufunc->uf_args.ga_len
e7577f79d6eb patch 8.2.2792: Vim9: :disas shows instructions for default args but no text
Bram Moolenaar <Bram@vim.org>
parents: 24490
diff changeset
4445 - ufunc->uf_def_args.ga_len;
e7577f79d6eb patch 8.2.2792: Vim9: :disas shows instructions for default args but no text
Bram Moolenaar <Bram@vim.org>
parents: 24490
diff changeset
4446
e7577f79d6eb patch 8.2.2792: Vim9: :disas shows instructions for default args but no text
Bram Moolenaar <Bram@vim.org>
parents: 24490
diff changeset
4447 if (def_arg_idx > 0)
e7577f79d6eb patch 8.2.2792: Vim9: :disas shows instructions for default args but no text
Bram Moolenaar <Bram@vim.org>
parents: 24490
diff changeset
4448 msg_puts("\n\n");
e7577f79d6eb patch 8.2.2792: Vim9: :disas shows instructions for default args but no text
Bram Moolenaar <Bram@vim.org>
parents: 24490
diff changeset
4449 msg_start();
e7577f79d6eb patch 8.2.2792: Vim9: :disas shows instructions for default args but no text
Bram Moolenaar <Bram@vim.org>
parents: 24490
diff changeset
4450 msg_puts(" ");
e7577f79d6eb patch 8.2.2792: Vim9: :disas shows instructions for default args but no text
Bram Moolenaar <Bram@vim.org>
parents: 24490
diff changeset
4451 msg_puts(((char **)(ufunc->uf_args.ga_data))[
e7577f79d6eb patch 8.2.2792: Vim9: :disas shows instructions for default args but no text
Bram Moolenaar <Bram@vim.org>
parents: 24490
diff changeset
4452 first_def_arg + def_arg_idx]);
e7577f79d6eb patch 8.2.2792: Vim9: :disas shows instructions for default args but no text
Bram Moolenaar <Bram@vim.org>
parents: 24490
diff changeset
4453 msg_puts(" = ");
e7577f79d6eb patch 8.2.2792: Vim9: :disas shows instructions for default args but no text
Bram Moolenaar <Bram@vim.org>
parents: 24490
diff changeset
4454 msg_puts(((char **)(ufunc->uf_def_args.ga_data))[def_arg_idx++]);
e7577f79d6eb patch 8.2.2792: Vim9: :disas shows instructions for default args but no text
Bram Moolenaar <Bram@vim.org>
parents: 24490
diff changeset
4455 msg_clr_eos();
e7577f79d6eb patch 8.2.2792: Vim9: :disas shows instructions for default args but no text
Bram Moolenaar <Bram@vim.org>
parents: 24490
diff changeset
4456 msg_end();
e7577f79d6eb patch 8.2.2792: Vim9: :disas shows instructions for default args but no text
Bram Moolenaar <Bram@vim.org>
parents: 24490
diff changeset
4457 }
e7577f79d6eb patch 8.2.2792: Vim9: :disas shows instructions for default args but no text
Bram Moolenaar <Bram@vim.org>
parents: 24490
diff changeset
4458 }
24488
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4459
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4460 switch (iptr->isn_type)
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4461 {
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4462 case ISN_EXEC:
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4463 smsg("%s%4d EXEC %s", pfx, current, iptr->isn_arg.string);
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4464 break;
24490
08050e45bd06 patch 8.2.2785: Vim9: cannot redirect to local variable
Bram Moolenaar <Bram@vim.org>
parents: 24488
diff changeset
4465 case ISN_REDIRSTART:
08050e45bd06 patch 8.2.2785: Vim9: cannot redirect to local variable
Bram Moolenaar <Bram@vim.org>
parents: 24488
diff changeset
4466 smsg("%s%4d REDIR", pfx, current);
08050e45bd06 patch 8.2.2785: Vim9: cannot redirect to local variable
Bram Moolenaar <Bram@vim.org>
parents: 24488
diff changeset
4467 break;
08050e45bd06 patch 8.2.2785: Vim9: cannot redirect to local variable
Bram Moolenaar <Bram@vim.org>
parents: 24488
diff changeset
4468 case ISN_REDIREND:
08050e45bd06 patch 8.2.2785: Vim9: cannot redirect to local variable
Bram Moolenaar <Bram@vim.org>
parents: 24488
diff changeset
4469 smsg("%s%4d REDIR END%s", pfx, current,
08050e45bd06 patch 8.2.2785: Vim9: cannot redirect to local variable
Bram Moolenaar <Bram@vim.org>
parents: 24488
diff changeset
4470 iptr->isn_arg.number ? " append" : "");
08050e45bd06 patch 8.2.2785: Vim9: cannot redirect to local variable
Bram Moolenaar <Bram@vim.org>
parents: 24488
diff changeset
4471 break;
24590
2818f846f099 patch 8.2.2834: Vim9: :cexpr does not work with local variables
Bram Moolenaar <Bram@vim.org>
parents: 24549
diff changeset
4472 case ISN_CEXPR_AUCMD:
24594
5c456a88f651 patch 8.2.2836: build failure without the +quickfix feature
Bram Moolenaar <Bram@vim.org>
parents: 24590
diff changeset
4473 #ifdef FEAT_QUICKFIX
24590
2818f846f099 patch 8.2.2834: Vim9: :cexpr does not work with local variables
Bram Moolenaar <Bram@vim.org>
parents: 24549
diff changeset
4474 smsg("%s%4d CEXPR pre %s", pfx, current,
2818f846f099 patch 8.2.2834: Vim9: :cexpr does not work with local variables
Bram Moolenaar <Bram@vim.org>
parents: 24549
diff changeset
4475 cexpr_get_auname(iptr->isn_arg.number));
24594
5c456a88f651 patch 8.2.2836: build failure without the +quickfix feature
Bram Moolenaar <Bram@vim.org>
parents: 24590
diff changeset
4476 #endif
24590
2818f846f099 patch 8.2.2834: Vim9: :cexpr does not work with local variables
Bram Moolenaar <Bram@vim.org>
parents: 24549
diff changeset
4477 break;
2818f846f099 patch 8.2.2834: Vim9: :cexpr does not work with local variables
Bram Moolenaar <Bram@vim.org>
parents: 24549
diff changeset
4478 case ISN_CEXPR_CORE:
24594
5c456a88f651 patch 8.2.2836: build failure without the +quickfix feature
Bram Moolenaar <Bram@vim.org>
parents: 24590
diff changeset
4479 #ifdef FEAT_QUICKFIX
24590
2818f846f099 patch 8.2.2834: Vim9: :cexpr does not work with local variables
Bram Moolenaar <Bram@vim.org>
parents: 24549
diff changeset
4480 {
2818f846f099 patch 8.2.2834: Vim9: :cexpr does not work with local variables
Bram Moolenaar <Bram@vim.org>
parents: 24549
diff changeset
4481 cexprref_T *cer = iptr->isn_arg.cexpr.cexpr_ref;
2818f846f099 patch 8.2.2834: Vim9: :cexpr does not work with local variables
Bram Moolenaar <Bram@vim.org>
parents: 24549
diff changeset
4482
2818f846f099 patch 8.2.2834: Vim9: :cexpr does not work with local variables
Bram Moolenaar <Bram@vim.org>
parents: 24549
diff changeset
4483 smsg("%s%4d CEXPR core %s%s \"%s\"", pfx, current,
2818f846f099 patch 8.2.2834: Vim9: :cexpr does not work with local variables
Bram Moolenaar <Bram@vim.org>
parents: 24549
diff changeset
4484 cexpr_get_auname(cer->cer_cmdidx),
2818f846f099 patch 8.2.2834: Vim9: :cexpr does not work with local variables
Bram Moolenaar <Bram@vim.org>
parents: 24549
diff changeset
4485 cer->cer_forceit ? "!" : "",
2818f846f099 patch 8.2.2834: Vim9: :cexpr does not work with local variables
Bram Moolenaar <Bram@vim.org>
parents: 24549
diff changeset
4486 cer->cer_cmdline);
2818f846f099 patch 8.2.2834: Vim9: :cexpr does not work with local variables
Bram Moolenaar <Bram@vim.org>
parents: 24549
diff changeset
4487 }
24594
5c456a88f651 patch 8.2.2836: build failure without the +quickfix feature
Bram Moolenaar <Bram@vim.org>
parents: 24590
diff changeset
4488 #endif
24590
2818f846f099 patch 8.2.2834: Vim9: :cexpr does not work with local variables
Bram Moolenaar <Bram@vim.org>
parents: 24549
diff changeset
4489 break;
24606
a4fda40e0bb9 patch 8.2.2842: Vim9: skip argument to searchpair() is not compiled
Bram Moolenaar <Bram@vim.org>
parents: 24594
diff changeset
4490 case ISN_INSTR:
a4fda40e0bb9 patch 8.2.2842: Vim9: skip argument to searchpair() is not compiled
Bram Moolenaar <Bram@vim.org>
parents: 24594
diff changeset
4491 {
a4fda40e0bb9 patch 8.2.2842: Vim9: skip argument to searchpair() is not compiled
Bram Moolenaar <Bram@vim.org>
parents: 24594
diff changeset
4492 smsg("%s%4d INSTR", pfx, current);
a4fda40e0bb9 patch 8.2.2842: Vim9: skip argument to searchpair() is not compiled
Bram Moolenaar <Bram@vim.org>
parents: 24594
diff changeset
4493 list_instructions(" ", iptr->isn_arg.instr,
a4fda40e0bb9 patch 8.2.2842: Vim9: skip argument to searchpair() is not compiled
Bram Moolenaar <Bram@vim.org>
parents: 24594
diff changeset
4494 INT_MAX, NULL);
a4fda40e0bb9 patch 8.2.2842: Vim9: skip argument to searchpair() is not compiled
Bram Moolenaar <Bram@vim.org>
parents: 24594
diff changeset
4495 msg(" -------------");
a4fda40e0bb9 patch 8.2.2842: Vim9: skip argument to searchpair() is not compiled
Bram Moolenaar <Bram@vim.org>
parents: 24594
diff changeset
4496 }
a4fda40e0bb9 patch 8.2.2842: Vim9: skip argument to searchpair() is not compiled
Bram Moolenaar <Bram@vim.org>
parents: 24594
diff changeset
4497 break;
24488
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4498 case ISN_SUBSTITUTE:
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4499 {
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4500 subs_T *subs = &iptr->isn_arg.subs;
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4501
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4502 smsg("%s%4d SUBSTITUTE %s", pfx, current, subs->subs_cmd);
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4503 list_instructions(" ", subs->subs_instr, INT_MAX, NULL);
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4504 msg(" -------------");
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4505 }
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4506 break;
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4507 case ISN_EXECCONCAT:
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4508 smsg("%s%4d EXECCONCAT %lld", pfx, current,
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4509 (varnumber_T)iptr->isn_arg.number);
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4510 break;
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4511 case ISN_ECHO:
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4512 {
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4513 echo_T *echo = &iptr->isn_arg.echo;
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4514
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4515 smsg("%s%4d %s %d", pfx, current,
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4516 echo->echo_with_white ? "ECHO" : "ECHON",
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4517 echo->echo_count);
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4518 }
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4519 break;
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4520 case ISN_EXECUTE:
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4521 smsg("%s%4d EXECUTE %lld", pfx, current,
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4522 (varnumber_T)(iptr->isn_arg.number));
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4523 break;
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4524 case ISN_ECHOMSG:
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4525 smsg("%s%4d ECHOMSG %lld", pfx, current,
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4526 (varnumber_T)(iptr->isn_arg.number));
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4527 break;
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4528 case ISN_ECHOERR:
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4529 smsg("%s%4d ECHOERR %lld", pfx, current,
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4530 (varnumber_T)(iptr->isn_arg.number));
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4531 break;
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4532 case ISN_LOAD:
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4533 {
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4534 if (iptr->isn_arg.number < 0)
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4535 smsg("%s%4d LOAD arg[%lld]", pfx, current,
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4536 (varnumber_T)(iptr->isn_arg.number
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4537 + STACK_FRAME_SIZE));
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4538 else
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4539 smsg("%s%4d LOAD $%lld", pfx, current,
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4540 (varnumber_T)(iptr->isn_arg.number));
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4541 }
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4542 break;
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4543 case ISN_LOADOUTER:
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4544 {
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4545 if (iptr->isn_arg.number < 0)
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4546 smsg("%s%4d LOADOUTER level %d arg[%d]", pfx, current,
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4547 iptr->isn_arg.outer.outer_depth,
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4548 iptr->isn_arg.outer.outer_idx
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4549 + STACK_FRAME_SIZE);
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4550 else
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4551 smsg("%s%4d LOADOUTER level %d $%d", pfx, current,
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4552 iptr->isn_arg.outer.outer_depth,
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4553 iptr->isn_arg.outer.outer_idx);
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4554 }
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4555 break;
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4556 case ISN_LOADV:
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4557 smsg("%s%4d LOADV v:%s", pfx, current,
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4558 get_vim_var_name(iptr->isn_arg.number));
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4559 break;
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4560 case ISN_LOADSCRIPT:
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4561 {
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4562 scriptref_T *sref = iptr->isn_arg.script.scriptref;
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4563 scriptitem_T *si = SCRIPT_ITEM(sref->sref_sid);
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4564 svar_T *sv = ((svar_T *)si->sn_var_vals.ga_data)
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4565 + sref->sref_idx;
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4566
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4567 smsg("%s%4d LOADSCRIPT %s-%d from %s", pfx, current,
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4568 sv->sv_name,
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4569 sref->sref_idx,
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4570 si->sn_name);
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4571 }
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4572 break;
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4573 case ISN_LOADS:
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4574 {
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4575 scriptitem_T *si = SCRIPT_ITEM(
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4576 iptr->isn_arg.loadstore.ls_sid);
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4577
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4578 smsg("%s%4d LOADS s:%s from %s", pfx, current,
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4579 iptr->isn_arg.loadstore.ls_name, si->sn_name);
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4580 }
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4581 break;
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4582 case ISN_LOADAUTO:
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4583 smsg("%s%4d LOADAUTO %s", pfx, current, iptr->isn_arg.string);
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4584 break;
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4585 case ISN_LOADG:
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4586 smsg("%s%4d LOADG g:%s", pfx, current, iptr->isn_arg.string);
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4587 break;
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4588 case ISN_LOADB:
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4589 smsg("%s%4d LOADB b:%s", pfx, current, iptr->isn_arg.string);
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4590 break;
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4591 case ISN_LOADW:
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4592 smsg("%s%4d LOADW w:%s", pfx, current, iptr->isn_arg.string);
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4593 break;
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4594 case ISN_LOADT:
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4595 smsg("%s%4d LOADT t:%s", pfx, current, iptr->isn_arg.string);
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4596 break;
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4597 case ISN_LOADGDICT:
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4598 smsg("%s%4d LOAD g:", pfx, current);
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4599 break;
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4600 case ISN_LOADBDICT:
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4601 smsg("%s%4d LOAD b:", pfx, current);
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4602 break;
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4603 case ISN_LOADWDICT:
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4604 smsg("%s%4d LOAD w:", pfx, current);
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4605 break;
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4606 case ISN_LOADTDICT:
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4607 smsg("%s%4d LOAD t:", pfx, current);
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4608 break;
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4609 case ISN_LOADOPT:
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4610 smsg("%s%4d LOADOPT %s", pfx, current, iptr->isn_arg.string);
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4611 break;
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4612 case ISN_LOADENV:
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4613 smsg("%s%4d LOADENV %s", pfx, current, iptr->isn_arg.string);
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4614 break;
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4615 case ISN_LOADREG:
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4616 smsg("%s%4d LOADREG @%c", pfx, current, (int)(iptr->isn_arg.number));
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4617 break;
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4618
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4619 case ISN_STORE:
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4620 if (iptr->isn_arg.number < 0)
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4621 smsg("%s%4d STORE arg[%lld]", pfx, current,
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4622 iptr->isn_arg.number + STACK_FRAME_SIZE);
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4623 else
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4624 smsg("%s%4d STORE $%lld", pfx, current, iptr->isn_arg.number);
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4625 break;
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4626 case ISN_STOREOUTER:
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4627 {
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4628 if (iptr->isn_arg.number < 0)
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4629 smsg("%s%4d STOREOUTEr level %d arg[%d]", pfx, current,
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4630 iptr->isn_arg.outer.outer_depth,
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4631 iptr->isn_arg.outer.outer_idx + STACK_FRAME_SIZE);
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4632 else
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4633 smsg("%s%4d STOREOUTER level %d $%d", pfx, current,
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4634 iptr->isn_arg.outer.outer_depth,
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4635 iptr->isn_arg.outer.outer_idx);
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4636 }
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4637 break;
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4638 case ISN_STOREV:
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4639 smsg("%s%4d STOREV v:%s", pfx, current,
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4640 get_vim_var_name(iptr->isn_arg.number));
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4641 break;
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4642 case ISN_STOREAUTO:
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4643 smsg("%s%4d STOREAUTO %s", pfx, current, iptr->isn_arg.string);
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4644 break;
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4645 case ISN_STOREG:
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4646 smsg("%s%4d STOREG %s", pfx, current, iptr->isn_arg.string);
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4647 break;
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4648 case ISN_STOREB:
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4649 smsg("%s%4d STOREB %s", pfx, current, iptr->isn_arg.string);
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4650 break;
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4651 case ISN_STOREW:
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4652 smsg("%s%4d STOREW %s", pfx, current, iptr->isn_arg.string);
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4653 break;
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4654 case ISN_STORET:
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4655 smsg("%s%4d STORET %s", pfx, current, iptr->isn_arg.string);
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4656 break;
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4657 case ISN_STORES:
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4658 {
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4659 scriptitem_T *si = SCRIPT_ITEM(
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4660 iptr->isn_arg.loadstore.ls_sid);
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4661
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4662 smsg("%s%4d STORES %s in %s", pfx, current,
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4663 iptr->isn_arg.loadstore.ls_name, si->sn_name);
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4664 }
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4665 break;
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4666 case ISN_STORESCRIPT:
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4667 {
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4668 scriptref_T *sref = iptr->isn_arg.script.scriptref;
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4669 scriptitem_T *si = SCRIPT_ITEM(sref->sref_sid);
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4670 svar_T *sv = ((svar_T *)si->sn_var_vals.ga_data)
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4671 + sref->sref_idx;
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4672
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4673 smsg("%s%4d STORESCRIPT %s-%d in %s", pfx, current,
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4674 sv->sv_name,
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4675 sref->sref_idx,
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4676 si->sn_name);
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4677 }
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4678 break;
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4679 case ISN_STOREOPT:
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4680 smsg("%s%4d STOREOPT &%s", pfx, current,
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4681 iptr->isn_arg.storeopt.so_name);
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4682 break;
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4683 case ISN_STOREENV:
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4684 smsg("%s%4d STOREENV $%s", pfx, current, iptr->isn_arg.string);
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4685 break;
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4686 case ISN_STOREREG:
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4687 smsg("%s%4d STOREREG @%c", pfx, current, (int)iptr->isn_arg.number);
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4688 break;
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4689 case ISN_STORENR:
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4690 smsg("%s%4d STORE %lld in $%d", pfx, current,
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4691 iptr->isn_arg.storenr.stnr_val,
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4692 iptr->isn_arg.storenr.stnr_idx);
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4693 break;
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4694
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4695 case ISN_STOREINDEX:
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4696 smsg("%s%4d STOREINDEX %s", pfx, current,
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4697 vartype_name(iptr->isn_arg.vartype));
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4698 break;
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4699
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4700 case ISN_STORERANGE:
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4701 smsg("%s%4d STORERANGE", pfx, current);
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4702 break;
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4703
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4704 // constants
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4705 case ISN_PUSHNR:
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4706 smsg("%s%4d PUSHNR %lld", pfx, current,
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4707 (varnumber_T)(iptr->isn_arg.number));
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4708 break;
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4709 case ISN_PUSHBOOL:
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4710 case ISN_PUSHSPEC:
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4711 smsg("%s%4d PUSH %s", pfx, current,
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4712 get_var_special_name(iptr->isn_arg.number));
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4713 break;
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4714 case ISN_PUSHF:
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4715 #ifdef FEAT_FLOAT
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4716 smsg("%s%4d PUSHF %g", pfx, current, iptr->isn_arg.fnumber);
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4717 #endif
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4718 break;
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4719 case ISN_PUSHS:
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4720 smsg("%s%4d PUSHS \"%s\"", pfx, current, iptr->isn_arg.string);
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4721 break;
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4722 case ISN_PUSHBLOB:
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4723 {
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4724 char_u *r;
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4725 char_u numbuf[NUMBUFLEN];
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4726 char_u *tofree;
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4727
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4728 r = blob2string(iptr->isn_arg.blob, &tofree, numbuf);
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4729 smsg("%s%4d PUSHBLOB %s", pfx, current, r);
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4730 vim_free(tofree);
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4731 }
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4732 break;
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4733 case ISN_PUSHFUNC:
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4734 {
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4735 char *name = (char *)iptr->isn_arg.string;
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4736
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4737 smsg("%s%4d PUSHFUNC \"%s\"", pfx, current,
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4738 name == NULL ? "[none]" : name);
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4739 }
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4740 break;
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4741 case ISN_PUSHCHANNEL:
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4742 #ifdef FEAT_JOB_CHANNEL
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4743 {
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4744 channel_T *channel = iptr->isn_arg.channel;
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4745
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4746 smsg("%s%4d PUSHCHANNEL %d", pfx, current,
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4747 channel == NULL ? 0 : channel->ch_id);
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4748 }
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4749 #endif
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4750 break;
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4751 case ISN_PUSHJOB:
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4752 #ifdef FEAT_JOB_CHANNEL
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4753 {
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4754 typval_T tv;
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4755 char_u *name;
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4756
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4757 tv.v_type = VAR_JOB;
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4758 tv.vval.v_job = iptr->isn_arg.job;
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4759 name = tv_get_string(&tv);
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4760 smsg("%s%4d PUSHJOB \"%s\"", pfx, current, name);
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4761 }
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4762 #endif
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4763 break;
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4764 case ISN_PUSHEXC:
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4765 smsg("%s%4d PUSH v:exception", pfx, current);
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4766 break;
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4767 case ISN_UNLET:
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4768 smsg("%s%4d UNLET%s %s", pfx, current,
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4769 iptr->isn_arg.unlet.ul_forceit ? "!" : "",
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4770 iptr->isn_arg.unlet.ul_name);
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4771 break;
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4772 case ISN_UNLETENV:
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4773 smsg("%s%4d UNLETENV%s $%s", pfx, current,
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4774 iptr->isn_arg.unlet.ul_forceit ? "!" : "",
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4775 iptr->isn_arg.unlet.ul_name);
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4776 break;
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4777 case ISN_UNLETINDEX:
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4778 smsg("%s%4d UNLETINDEX", pfx, current);
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4779 break;
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4780 case ISN_UNLETRANGE:
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4781 smsg("%s%4d UNLETRANGE", pfx, current);
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4782 break;
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4783 case ISN_LOCKCONST:
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4784 smsg("%s%4d LOCKCONST", pfx, current);
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4785 break;
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4786 case ISN_NEWLIST:
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4787 smsg("%s%4d NEWLIST size %lld", pfx, current,
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4788 (varnumber_T)(iptr->isn_arg.number));
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4789 break;
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4790 case ISN_NEWDICT:
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4791 smsg("%s%4d NEWDICT size %lld", pfx, current,
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4792 (varnumber_T)(iptr->isn_arg.number));
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4793 break;
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4794
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4795 // function call
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4796 case ISN_BCALL:
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4797 {
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4798 cbfunc_T *cbfunc = &iptr->isn_arg.bfunc;
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4799
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4800 smsg("%s%4d BCALL %s(argc %d)", pfx, current,
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4801 internal_func_name(cbfunc->cbf_idx),
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4802 cbfunc->cbf_argcount);
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4803 }
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4804 break;
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4805 case ISN_DCALL:
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4806 {
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4807 cdfunc_T *cdfunc = &iptr->isn_arg.dfunc;
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4808 dfunc_T *df = ((dfunc_T *)def_functions.ga_data)
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4809 + cdfunc->cdf_idx;
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4810
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4811 smsg("%s%4d DCALL %s(argc %d)", pfx, current,
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4812 df->df_ufunc->uf_name_exp != NULL
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4813 ? df->df_ufunc->uf_name_exp
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4814 : df->df_ufunc->uf_name, cdfunc->cdf_argcount);
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4815 }
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4816 break;
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4817 case ISN_UCALL:
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4818 {
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4819 cufunc_T *cufunc = &iptr->isn_arg.ufunc;
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4820
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4821 smsg("%s%4d UCALL %s(argc %d)", pfx, current,
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4822 cufunc->cuf_name, cufunc->cuf_argcount);
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4823 }
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4824 break;
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4825 case ISN_PCALL:
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4826 {
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4827 cpfunc_T *cpfunc = &iptr->isn_arg.pfunc;
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4828
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4829 smsg("%s%4d PCALL%s (argc %d)", pfx, current,
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4830 cpfunc->cpf_top ? " top" : "", cpfunc->cpf_argcount);
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4831 }
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4832 break;
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4833 case ISN_PCALL_END:
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4834 smsg("%s%4d PCALL end", pfx, current);
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4835 break;
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4836 case ISN_RETURN:
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4837 smsg("%s%4d RETURN", pfx, current);
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4838 break;
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4839 case ISN_RETURN_ZERO:
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4840 smsg("%s%4d RETURN 0", pfx, current);
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4841 break;
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4842 case ISN_FUNCREF:
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4843 {
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4844 funcref_T *funcref = &iptr->isn_arg.funcref;
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4845 dfunc_T *df = ((dfunc_T *)def_functions.ga_data)
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4846 + funcref->fr_func;
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4847
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4848 smsg("%s%4d FUNCREF %s", pfx, current, df->df_ufunc->uf_name);
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4849 }
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4850 break;
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4851
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4852 case ISN_NEWFUNC:
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4853 {
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4854 newfunc_T *newfunc = &iptr->isn_arg.newfunc;
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4855
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4856 smsg("%s%4d NEWFUNC %s %s", pfx, current,
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4857 newfunc->nf_lambda, newfunc->nf_global);
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4858 }
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4859 break;
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4860
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4861 case ISN_DEF:
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4862 {
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4863 char_u *name = iptr->isn_arg.string;
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4864
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4865 smsg("%s%4d DEF %s", pfx, current,
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4866 name == NULL ? (char_u *)"" : name);
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4867 }
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4868 break;
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4869
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4870 case ISN_JUMP:
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4871 {
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4872 char *when = "?";
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4873
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4874 switch (iptr->isn_arg.jump.jump_when)
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4875 {
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4876 case JUMP_ALWAYS:
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4877 when = "JUMP";
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4878 break;
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4879 case JUMP_AND_KEEP_IF_TRUE:
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4880 when = "JUMP_AND_KEEP_IF_TRUE";
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4881 break;
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4882 case JUMP_IF_FALSE:
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4883 when = "JUMP_IF_FALSE";
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4884 break;
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4885 case JUMP_AND_KEEP_IF_FALSE:
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4886 when = "JUMP_AND_KEEP_IF_FALSE";
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4887 break;
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4888 case JUMP_IF_COND_FALSE:
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4889 when = "JUMP_IF_COND_FALSE";
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4890 break;
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4891 case JUMP_IF_COND_TRUE:
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4892 when = "JUMP_IF_COND_TRUE";
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4893 break;
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4894 }
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4895 smsg("%s%4d %s -> %d", pfx, current, when,
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4896 iptr->isn_arg.jump.jump_where);
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4897 }
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4898 break;
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4899
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4900 case ISN_JUMP_IF_ARG_SET:
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4901 smsg("%s%4d JUMP_IF_ARG_SET arg[%d] -> %d", pfx, current,
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4902 iptr->isn_arg.jumparg.jump_arg_off + STACK_FRAME_SIZE,
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4903 iptr->isn_arg.jump.jump_where);
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4904 break;
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4905
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4906 case ISN_FOR:
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4907 {
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4908 forloop_T *forloop = &iptr->isn_arg.forloop;
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4909
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4910 smsg("%s%4d FOR $%d -> %d", pfx, current,
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4911 forloop->for_idx, forloop->for_end);
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4912 }
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4913 break;
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4914
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4915 case ISN_TRY:
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4916 {
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4917 try_T *try = &iptr->isn_arg.try;
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4918
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4919 if (try->try_ref->try_finally == 0)
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4920 smsg("%s%4d TRY catch -> %d, endtry -> %d",
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4921 pfx, current,
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4922 try->try_ref->try_catch,
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4923 try->try_ref->try_endtry);
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4924 else
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4925 smsg("%s%4d TRY catch -> %d, finally -> %d, endtry -> %d",
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4926 pfx, current,
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4927 try->try_ref->try_catch,
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4928 try->try_ref->try_finally,
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4929 try->try_ref->try_endtry);
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4930 }
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4931 break;
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4932 case ISN_CATCH:
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4933 // TODO
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4934 smsg("%s%4d CATCH", pfx, current);
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4935 break;
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4936 case ISN_TRYCONT:
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4937 {
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4938 trycont_T *trycont = &iptr->isn_arg.trycont;
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4939
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4940 smsg("%s%4d TRY-CONTINUE %d level%s -> %d", pfx, current,
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4941 trycont->tct_levels,
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4942 trycont->tct_levels == 1 ? "" : "s",
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4943 trycont->tct_where);
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4944 }
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4945 break;
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4946 case ISN_FINALLY:
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4947 smsg("%s%4d FINALLY", pfx, current);
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4948 break;
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4949 case ISN_ENDTRY:
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4950 smsg("%s%4d ENDTRY", pfx, current);
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4951 break;
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4952 case ISN_THROW:
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4953 smsg("%s%4d THROW", pfx, current);
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4954 break;
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4955
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4956 // expression operations on number
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4957 case ISN_OPNR:
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4958 case ISN_OPFLOAT:
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4959 case ISN_OPANY:
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4960 {
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4961 char *what;
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4962 char *ins;
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4963
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4964 switch (iptr->isn_arg.op.op_type)
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4965 {
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4966 case EXPR_MULT: what = "*"; break;
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4967 case EXPR_DIV: what = "/"; break;
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4968 case EXPR_REM: what = "%"; break;
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4969 case EXPR_SUB: what = "-"; break;
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4970 case EXPR_ADD: what = "+"; break;
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4971 default: what = "???"; break;
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4972 }
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4973 switch (iptr->isn_type)
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4974 {
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4975 case ISN_OPNR: ins = "OPNR"; break;
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4976 case ISN_OPFLOAT: ins = "OPFLOAT"; break;
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4977 case ISN_OPANY: ins = "OPANY"; break;
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4978 default: ins = "???"; break;
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4979 }
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4980 smsg("%s%4d %s %s", pfx, current, ins, what);
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4981 }
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4982 break;
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4983
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4984 case ISN_COMPAREBOOL:
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4985 case ISN_COMPARESPECIAL:
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4986 case ISN_COMPARENR:
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4987 case ISN_COMPAREFLOAT:
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4988 case ISN_COMPARESTRING:
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4989 case ISN_COMPAREBLOB:
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4990 case ISN_COMPARELIST:
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4991 case ISN_COMPAREDICT:
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4992 case ISN_COMPAREFUNC:
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4993 case ISN_COMPAREANY:
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4994 {
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4995 char *p;
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4996 char buf[10];
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4997 char *type;
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4998
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
4999 switch (iptr->isn_arg.op.op_type)
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
5000 {
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
5001 case EXPR_EQUAL: p = "=="; break;
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
5002 case EXPR_NEQUAL: p = "!="; break;
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
5003 case EXPR_GREATER: p = ">"; break;
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
5004 case EXPR_GEQUAL: p = ">="; break;
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
5005 case EXPR_SMALLER: p = "<"; break;
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
5006 case EXPR_SEQUAL: p = "<="; break;
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
5007 case EXPR_MATCH: p = "=~"; break;
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
5008 case EXPR_IS: p = "is"; break;
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
5009 case EXPR_ISNOT: p = "isnot"; break;
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
5010 case EXPR_NOMATCH: p = "!~"; break;
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
5011 default: p = "???"; break;
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
5012 }
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
5013 STRCPY(buf, p);
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
5014 if (iptr->isn_arg.op.op_ic == TRUE)
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
5015 strcat(buf, "?");
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
5016 switch(iptr->isn_type)
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
5017 {
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
5018 case ISN_COMPAREBOOL: type = "COMPAREBOOL"; break;
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
5019 case ISN_COMPARESPECIAL:
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
5020 type = "COMPARESPECIAL"; break;
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
5021 case ISN_COMPARENR: type = "COMPARENR"; break;
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
5022 case ISN_COMPAREFLOAT: type = "COMPAREFLOAT"; break;
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
5023 case ISN_COMPARESTRING:
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
5024 type = "COMPARESTRING"; break;
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
5025 case ISN_COMPAREBLOB: type = "COMPAREBLOB"; break;
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
5026 case ISN_COMPARELIST: type = "COMPARELIST"; break;
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
5027 case ISN_COMPAREDICT: type = "COMPAREDICT"; break;
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
5028 case ISN_COMPAREFUNC: type = "COMPAREFUNC"; break;
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
5029 case ISN_COMPAREANY: type = "COMPAREANY"; break;
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
5030 default: type = "???"; break;
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
5031 }
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
5032
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
5033 smsg("%s%4d %s %s", pfx, current, type, buf);
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
5034 }
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
5035 break;
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
5036
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
5037 case ISN_ADDLIST: smsg("%s%4d ADDLIST", pfx, current); break;
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
5038 case ISN_ADDBLOB: smsg("%s%4d ADDBLOB", pfx, current); break;
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
5039
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
5040 // expression operations
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
5041 case ISN_CONCAT: smsg("%s%4d CONCAT", pfx, current); break;
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
5042 case ISN_STRINDEX: smsg("%s%4d STRINDEX", pfx, current); break;
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
5043 case ISN_STRSLICE: smsg("%s%4d STRSLICE", pfx, current); break;
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
5044 case ISN_BLOBINDEX: smsg("%s%4d BLOBINDEX", pfx, current); break;
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
5045 case ISN_BLOBSLICE: smsg("%s%4d BLOBSLICE", pfx, current); break;
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
5046 case ISN_LISTAPPEND: smsg("%s%4d LISTAPPEND", pfx, current); break;
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
5047 case ISN_BLOBAPPEND: smsg("%s%4d BLOBAPPEND", pfx, current); break;
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
5048 case ISN_LISTINDEX: smsg("%s%4d LISTINDEX", pfx, current); break;
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
5049 case ISN_LISTSLICE: smsg("%s%4d LISTSLICE", pfx, current); break;
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
5050 case ISN_ANYINDEX: smsg("%s%4d ANYINDEX", pfx, current); break;
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
5051 case ISN_ANYSLICE: smsg("%s%4d ANYSLICE", pfx, current); break;
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
5052 case ISN_SLICE: smsg("%s%4d SLICE %lld",
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
5053 pfx, current, iptr->isn_arg.number); break;
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
5054 case ISN_GETITEM: smsg("%s%4d ITEM %lld",
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
5055 pfx, current, iptr->isn_arg.number); break;
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
5056 case ISN_MEMBER: smsg("%s%4d MEMBER", pfx, current); break;
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
5057 case ISN_STRINGMEMBER: smsg("%s%4d MEMBER %s", pfx, current,
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
5058 iptr->isn_arg.string); break;
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
5059 case ISN_NEGATENR: smsg("%s%4d NEGATENR", pfx, current); break;
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
5060
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
5061 case ISN_CHECKNR: smsg("%s%4d CHECKNR", pfx, current); break;
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
5062 case ISN_CHECKTYPE:
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
5063 {
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
5064 checktype_T *ct = &iptr->isn_arg.type;
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
5065 char *tofree;
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
5066
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
5067 if (ct->ct_arg_idx == 0)
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
5068 smsg("%s%4d CHECKTYPE %s stack[%d]", pfx, current,
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
5069 type_name(ct->ct_type, &tofree),
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
5070 (int)ct->ct_off);
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
5071 else
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
5072 smsg("%s%4d CHECKTYPE %s stack[%d] arg %d", pfx, current,
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
5073 type_name(ct->ct_type, &tofree),
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
5074 (int)ct->ct_off,
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
5075 (int)ct->ct_arg_idx);
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
5076 vim_free(tofree);
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
5077 break;
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
5078 }
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
5079 case ISN_CHECKLEN: smsg("%s%4d CHECKLEN %s%d", pfx, current,
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
5080 iptr->isn_arg.checklen.cl_more_OK ? ">= " : "",
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
5081 iptr->isn_arg.checklen.cl_min_len);
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
5082 break;
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
5083 case ISN_SETTYPE:
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
5084 {
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
5085 char *tofree;
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
5086
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
5087 smsg("%s%4d SETTYPE %s", pfx, current,
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
5088 type_name(iptr->isn_arg.type.ct_type, &tofree));
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
5089 vim_free(tofree);
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
5090 break;
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
5091 }
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
5092 case ISN_COND2BOOL: smsg("%s%4d COND2BOOL", pfx, current); break;
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
5093 case ISN_2BOOL: if (iptr->isn_arg.number)
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
5094 smsg("%s%4d INVERT (!val)", pfx, current);
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
5095 else
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
5096 smsg("%s%4d 2BOOL (!!val)", pfx, current);
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
5097 break;
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
5098 case ISN_2STRING: smsg("%s%4d 2STRING stack[%lld]", pfx, current,
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
5099 (varnumber_T)(iptr->isn_arg.number));
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
5100 break;
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
5101 case ISN_2STRING_ANY: smsg("%s%4d 2STRING_ANY stack[%lld]", pfx, current,
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
5102 (varnumber_T)(iptr->isn_arg.number));
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
5103 break;
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
5104 case ISN_RANGE: smsg("%s%4d RANGE %s", pfx, current, iptr->isn_arg.string);
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
5105 break;
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
5106 case ISN_PUT:
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
5107 if (iptr->isn_arg.put.put_lnum == LNUM_VARIABLE_RANGE_ABOVE)
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
5108 smsg("%s%4d PUT %c above range",
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
5109 pfx, current, iptr->isn_arg.put.put_regname);
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
5110 else if (iptr->isn_arg.put.put_lnum == LNUM_VARIABLE_RANGE)
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
5111 smsg("%s%4d PUT %c range",
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
5112 pfx, current, iptr->isn_arg.put.put_regname);
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
5113 else
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
5114 smsg("%s%4d PUT %c %ld", pfx, current,
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
5115 iptr->isn_arg.put.put_regname,
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
5116 (long)iptr->isn_arg.put.put_lnum);
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
5117 break;
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
5118
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
5119 // TODO: summarize modifiers
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
5120 case ISN_CMDMOD:
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
5121 {
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
5122 char_u *buf;
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
5123 size_t len = produce_cmdmods(
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
5124 NULL, iptr->isn_arg.cmdmod.cf_cmdmod, FALSE);
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
5125
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
5126 buf = alloc(len + 1);
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
5127 if (buf != NULL)
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
5128 {
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
5129 (void)produce_cmdmods(
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
5130 buf, iptr->isn_arg.cmdmod.cf_cmdmod, FALSE);
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
5131 smsg("%s%4d CMDMOD %s", pfx, current, buf);
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
5132 vim_free(buf);
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
5133 }
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
5134 break;
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
5135 }
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
5136 case ISN_CMDMOD_REV: smsg("%s%4d CMDMOD_REV", pfx, current); break;
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
5137
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
5138 case ISN_PROF_START:
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
5139 smsg("%s%4d PROFILE START line %d", pfx, current, iptr->isn_lnum);
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
5140 break;
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
5141
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
5142 case ISN_PROF_END:
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
5143 smsg("%s%4d PROFILE END", pfx, current);
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
5144 break;
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
5145
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
5146 case ISN_UNPACK: smsg("%s%4d UNPACK %d%s", pfx, current,
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
5147 iptr->isn_arg.unpack.unp_count,
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
5148 iptr->isn_arg.unpack.unp_semicolon ? " semicolon" : "");
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
5149 break;
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
5150 case ISN_SHUFFLE: smsg("%s%4d SHUFFLE %d up %d", pfx, current,
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
5151 iptr->isn_arg.shuffle.shfl_item,
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
5152 iptr->isn_arg.shuffle.shfl_up);
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
5153 break;
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
5154 case ISN_DROP: smsg("%s%4d DROP", pfx, current); break;
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
5155
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
5156 case ISN_FINISH: // End of list of instructions for ISN_SUBSTITUTE.
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
5157 return;
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
5158 }
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
5159
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
5160 out_flush(); // output one line at a time
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
5161 ui_breakcheck();
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
5162 if (got_int)
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
5163 break;
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
5164 }
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
5165 }
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
5166
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
5167 /*
23229
b545334ae654 patch 8.2.2160: various typos
Bram Moolenaar <Bram@vim.org>
parents: 23227
diff changeset
5168 * ":disassemble".
19334
61646c189622 patch 8.2.0225: compiling lambda not tested yet
Bram Moolenaar <Bram@vim.org>
parents: 19328
diff changeset
5169 * We don't really need this at runtime, but we do have tests that require it,
61646c189622 patch 8.2.0225: compiling lambda not tested yet
Bram Moolenaar <Bram@vim.org>
parents: 19328
diff changeset
5170 * so always include this.
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
5171 */
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
5172 void
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
5173 ex_disassemble(exarg_T *eap)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
5174 {
19390
e4b326c9424a patch 8.2.0253: crash when using :disassamble without argument
Bram Moolenaar <Bram@vim.org>
parents: 19342
diff changeset
5175 char_u *arg = eap->arg;
19281
9fcdeaa18bd1 patch 8.2.0199: Vim9 script commands not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19221
diff changeset
5176 char_u *fname;
9fcdeaa18bd1 patch 8.2.0199: Vim9 script commands not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19221
diff changeset
5177 ufunc_T *ufunc;
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
5178 dfunc_T *dfunc;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
5179 isn_T *instr;
23717
e3720756acdc patch 8.2.2400: Vim9: compiled functions are not profiled
Bram Moolenaar <Bram@vim.org>
parents: 23699
diff changeset
5180 int instr_count;
20189
63cc54100ae4 patch 8.2.0650: Vim9: script function can be deleted
Bram Moolenaar <Bram@vim.org>
parents: 20172
diff changeset
5181 int is_global = FALSE;
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
5182
21299
883315e762b7 patch 8.2.1200: Vim9: cannot disassemble a lambda function
Bram Moolenaar <Bram@vim.org>
parents: 21232
diff changeset
5183 if (STRNCMP(arg, "<lambda>", 8) == 0)
883315e762b7 patch 8.2.1200: Vim9: cannot disassemble a lambda function
Bram Moolenaar <Bram@vim.org>
parents: 21232
diff changeset
5184 {
883315e762b7 patch 8.2.1200: Vim9: cannot disassemble a lambda function
Bram Moolenaar <Bram@vim.org>
parents: 21232
diff changeset
5185 arg += 8;
883315e762b7 patch 8.2.1200: Vim9: cannot disassemble a lambda function
Bram Moolenaar <Bram@vim.org>
parents: 21232
diff changeset
5186 (void)getdigits(&arg);
883315e762b7 patch 8.2.1200: Vim9: cannot disassemble a lambda function
Bram Moolenaar <Bram@vim.org>
parents: 21232
diff changeset
5187 fname = vim_strnsave(eap->arg, arg - eap->arg);
883315e762b7 patch 8.2.1200: Vim9: cannot disassemble a lambda function
Bram Moolenaar <Bram@vim.org>
parents: 21232
diff changeset
5188 }
883315e762b7 patch 8.2.1200: Vim9: cannot disassemble a lambda function
Bram Moolenaar <Bram@vim.org>
parents: 21232
diff changeset
5189 else
883315e762b7 patch 8.2.1200: Vim9: cannot disassemble a lambda function
Bram Moolenaar <Bram@vim.org>
parents: 21232
diff changeset
5190 fname = trans_function_name(&arg, &is_global, FALSE,
23527
27ca5534a408 patch 8.2.2306: Vim9: when using function reference type is not checked
Bram Moolenaar <Bram@vim.org>
parents: 23523
diff changeset
5191 TFN_INT | TFN_QUIET | TFN_NO_AUTOLOAD, NULL, NULL, NULL);
19390
e4b326c9424a patch 8.2.0253: crash when using :disassamble without argument
Bram Moolenaar <Bram@vim.org>
parents: 19342
diff changeset
5192 if (fname == NULL)
e4b326c9424a patch 8.2.0253: crash when using :disassamble without argument
Bram Moolenaar <Bram@vim.org>
parents: 19342
diff changeset
5193 {
e4b326c9424a patch 8.2.0253: crash when using :disassamble without argument
Bram Moolenaar <Bram@vim.org>
parents: 19342
diff changeset
5194 semsg(_(e_invarg2), eap->arg);
e4b326c9424a patch 8.2.0253: crash when using :disassamble without argument
Bram Moolenaar <Bram@vim.org>
parents: 19342
diff changeset
5195 return;
e4b326c9424a patch 8.2.0253: crash when using :disassamble without argument
Bram Moolenaar <Bram@vim.org>
parents: 19342
diff changeset
5196 }
e4b326c9424a patch 8.2.0253: crash when using :disassamble without argument
Bram Moolenaar <Bram@vim.org>
parents: 19342
diff changeset
5197
20189
63cc54100ae4 patch 8.2.0650: Vim9: script function can be deleted
Bram Moolenaar <Bram@vim.org>
parents: 20172
diff changeset
5198 ufunc = find_func(fname, is_global, NULL);
20079
336483164ca6 patch 8.2.0595: Vim9: not all commands using ends_excmd() tested
Bram Moolenaar <Bram@vim.org>
parents: 20021
diff changeset
5199 if (ufunc == NULL)
336483164ca6 patch 8.2.0595: Vim9: not all commands using ends_excmd() tested
Bram Moolenaar <Bram@vim.org>
parents: 20021
diff changeset
5200 {
336483164ca6 patch 8.2.0595: Vim9: not all commands using ends_excmd() tested
Bram Moolenaar <Bram@vim.org>
parents: 20021
diff changeset
5201 char_u *p = untrans_function_name(fname);
336483164ca6 patch 8.2.0595: Vim9: not all commands using ends_excmd() tested
Bram Moolenaar <Bram@vim.org>
parents: 20021
diff changeset
5202
336483164ca6 patch 8.2.0595: Vim9: not all commands using ends_excmd() tested
Bram Moolenaar <Bram@vim.org>
parents: 20021
diff changeset
5203 if (p != NULL)
336483164ca6 patch 8.2.0595: Vim9: not all commands using ends_excmd() tested
Bram Moolenaar <Bram@vim.org>
parents: 20021
diff changeset
5204 // Try again without making it script-local.
20189
63cc54100ae4 patch 8.2.0650: Vim9: script function can be deleted
Bram Moolenaar <Bram@vim.org>
parents: 20172
diff changeset
5205 ufunc = find_func(p, FALSE, NULL);
20079
336483164ca6 patch 8.2.0595: Vim9: not all commands using ends_excmd() tested
Bram Moolenaar <Bram@vim.org>
parents: 20021
diff changeset
5206 }
19281
9fcdeaa18bd1 patch 8.2.0199: Vim9 script commands not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19221
diff changeset
5207 vim_free(fname);
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
5208 if (ufunc == NULL)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
5209 {
21821
0deb6f96a5a3 patch 8.2.1460: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents: 21815
diff changeset
5210 semsg(_(e_cannot_find_function_str), eap->arg);
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
5211 return;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
5212 }
23717
e3720756acdc patch 8.2.2400: Vim9: compiled functions are not profiled
Bram Moolenaar <Bram@vim.org>
parents: 23699
diff changeset
5213 if (func_needs_compiling(ufunc, eap->forceit)
e3720756acdc patch 8.2.2400: Vim9: compiled functions are not profiled
Bram Moolenaar <Bram@vim.org>
parents: 23699
diff changeset
5214 && compile_def_function(ufunc, FALSE, eap->forceit, NULL) == FAIL)
20528
489cb75c76b6 patch 8.2.0818: Vim9: using a discovery phase doesn't work well
Bram Moolenaar <Bram@vim.org>
parents: 20433
diff changeset
5215 return;
20943
1693ca876049 patch 8.2.1023: Vim9: redefining a function uses a new index every time
Bram Moolenaar <Bram@vim.org>
parents: 20919
diff changeset
5216 if (ufunc->uf_def_status != UF_COMPILED)
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
5217 {
21821
0deb6f96a5a3 patch 8.2.1460: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents: 21815
diff changeset
5218 semsg(_(e_function_is_not_compiled_str), eap->arg);
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
5219 return;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
5220 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
5221 if (ufunc->uf_name_exp != NULL)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
5222 msg((char *)ufunc->uf_name_exp);
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
5223 else
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
5224 msg((char *)ufunc->uf_name);
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
5225
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
5226 dfunc = ((dfunc_T *)def_functions.ga_data) + ufunc->uf_dfunc_idx;
23719
1a7c2685d780 patch 8.2.2401: build fails without +profiling feature
Bram Moolenaar <Bram@vim.org>
parents: 23717
diff changeset
5227 #ifdef FEAT_PROFILE
23717
e3720756acdc patch 8.2.2400: Vim9: compiled functions are not profiled
Bram Moolenaar <Bram@vim.org>
parents: 23699
diff changeset
5228 instr = eap->forceit ? dfunc->df_instr_prof : dfunc->df_instr;
e3720756acdc patch 8.2.2400: Vim9: compiled functions are not profiled
Bram Moolenaar <Bram@vim.org>
parents: 23699
diff changeset
5229 instr_count = eap->forceit ? dfunc->df_instr_prof_count
e3720756acdc patch 8.2.2400: Vim9: compiled functions are not profiled
Bram Moolenaar <Bram@vim.org>
parents: 23699
diff changeset
5230 : dfunc->df_instr_count;
23719
1a7c2685d780 patch 8.2.2401: build fails without +profiling feature
Bram Moolenaar <Bram@vim.org>
parents: 23717
diff changeset
5231 #else
1a7c2685d780 patch 8.2.2401: build fails without +profiling feature
Bram Moolenaar <Bram@vim.org>
parents: 23717
diff changeset
5232 instr = dfunc->df_instr;
1a7c2685d780 patch 8.2.2401: build fails without +profiling feature
Bram Moolenaar <Bram@vim.org>
parents: 23717
diff changeset
5233 instr_count = dfunc->df_instr_count;
1a7c2685d780 patch 8.2.2401: build fails without +profiling feature
Bram Moolenaar <Bram@vim.org>
parents: 23717
diff changeset
5234 #endif
24488
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
5235
f293bb501b30 patch 8.2.2784: Vim9: cannot use =expr in :substitute
Bram Moolenaar <Bram@vim.org>
parents: 24482
diff changeset
5236 list_instructions("", instr, instr_count, ufunc);
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
5237 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
5238
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
5239 /*
22500
ef8a3177edc1 patch 8.2.1798: Vim9: trinary operator condition is too permissive
Bram Moolenaar <Bram@vim.org>
parents: 22494
diff changeset
5240 * Return TRUE when "tv" is not falsy: non-zero, non-empty string, non-empty
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
5241 * list, etc. Mostly like what JavaScript does, except that empty list and
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
5242 * empty dictionary are FALSE.
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
5243 */
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
5244 int
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
5245 tv2bool(typval_T *tv)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
5246 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
5247 switch (tv->v_type)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
5248 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
5249 case VAR_NUMBER:
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
5250 return tv->vval.v_number != 0;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
5251 case VAR_FLOAT:
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
5252 #ifdef FEAT_FLOAT
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
5253 return tv->vval.v_float != 0.0;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
5254 #else
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
5255 break;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
5256 #endif
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
5257 case VAR_PARTIAL:
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
5258 return tv->vval.v_partial != NULL;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
5259 case VAR_FUNC:
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
5260 case VAR_STRING:
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
5261 return tv->vval.v_string != NULL && *tv->vval.v_string != NUL;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
5262 case VAR_LIST:
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
5263 return tv->vval.v_list != NULL && tv->vval.v_list->lv_len > 0;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
5264 case VAR_DICT:
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
5265 return tv->vval.v_dict != NULL
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
5266 && tv->vval.v_dict->dv_hashtab.ht_used > 0;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
5267 case VAR_BOOL:
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
5268 case VAR_SPECIAL:
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
5269 return tv->vval.v_number == VVAL_TRUE ? TRUE : FALSE;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
5270 case VAR_JOB:
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
5271 #ifdef FEAT_JOB_CHANNEL
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
5272 return tv->vval.v_job != NULL;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
5273 #else
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
5274 break;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
5275 #endif
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
5276 case VAR_CHANNEL:
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
5277 #ifdef FEAT_JOB_CHANNEL
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
5278 return tv->vval.v_channel != NULL;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
5279 #else
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
5280 break;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
5281 #endif
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
5282 case VAR_BLOB:
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
5283 return tv->vval.v_blob != NULL && tv->vval.v_blob->bv_ga.ga_len > 0;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
5284 case VAR_UNKNOWN:
19922
1f42c49c3d29 patch 8.2.0517: Vim9: cannot separate "func" and "func(): void"
Bram Moolenaar <Bram@vim.org>
parents: 19912
diff changeset
5285 case VAR_ANY:
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
5286 case VAR_VOID:
24606
a4fda40e0bb9 patch 8.2.2842: Vim9: skip argument to searchpair() is not compiled
Bram Moolenaar <Bram@vim.org>
parents: 24594
diff changeset
5287 case VAR_INSTR:
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
5288 break;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
5289 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
5290 return FALSE;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
5291 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
5292
22860
53acb89ec9f2 patch 8.2.1977: Vim9: error for using a string in a condition is confusing
Bram Moolenaar <Bram@vim.org>
parents: 22810
diff changeset
5293 void
53acb89ec9f2 patch 8.2.1977: Vim9: error for using a string in a condition is confusing
Bram Moolenaar <Bram@vim.org>
parents: 22810
diff changeset
5294 emsg_using_string_as(typval_T *tv, int as_number)
53acb89ec9f2 patch 8.2.1977: Vim9: error for using a string in a condition is confusing
Bram Moolenaar <Bram@vim.org>
parents: 22810
diff changeset
5295 {
53acb89ec9f2 patch 8.2.1977: Vim9: error for using a string in a condition is confusing
Bram Moolenaar <Bram@vim.org>
parents: 22810
diff changeset
5296 semsg(_(as_number ? e_using_string_as_number_str
53acb89ec9f2 patch 8.2.1977: Vim9: error for using a string in a condition is confusing
Bram Moolenaar <Bram@vim.org>
parents: 22810
diff changeset
5297 : e_using_string_as_bool_str),
53acb89ec9f2 patch 8.2.1977: Vim9: error for using a string in a condition is confusing
Bram Moolenaar <Bram@vim.org>
parents: 22810
diff changeset
5298 tv->vval.v_string == NULL
53acb89ec9f2 patch 8.2.1977: Vim9: error for using a string in a condition is confusing
Bram Moolenaar <Bram@vim.org>
parents: 22810
diff changeset
5299 ? (char_u *)"" : tv->vval.v_string);
53acb89ec9f2 patch 8.2.1977: Vim9: error for using a string in a condition is confusing
Bram Moolenaar <Bram@vim.org>
parents: 22810
diff changeset
5300 }
53acb89ec9f2 patch 8.2.1977: Vim9: error for using a string in a condition is confusing
Bram Moolenaar <Bram@vim.org>
parents: 22810
diff changeset
5301
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
5302 /*
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
5303 * If "tv" is a string give an error and return FAIL.
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
5304 */
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
5305 int
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
5306 check_not_string(typval_T *tv)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
5307 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
5308 if (tv->v_type == VAR_STRING)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
5309 {
22860
53acb89ec9f2 patch 8.2.1977: Vim9: error for using a string in a condition is confusing
Bram Moolenaar <Bram@vim.org>
parents: 22810
diff changeset
5310 emsg_using_string_as(tv, TRUE);
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
5311 clear_tv(tv);
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
5312 return FAIL;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
5313 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
5314 return OK;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
5315 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
5316
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
5317
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
5318 #endif // FEAT_EVAL