Mercurial > vim
comparison src/vim9.h @ 20247:e46e72aaff74 v8.2.0679
patch 8.2.0679: Vim9: incomplete support for closures
Commit: https://github.com/vim/vim/commit/bf67ea1af05cbb30cd8f0b665fb567c0dca79796
Author: Bram Moolenaar <Bram@vim.org>
Date: Sat May 2 17:52:42 2020 +0200
patch 8.2.0679: Vim9: incomplete support for closures
Problem: Vim9: incomplete support for closures.
Solution: At the end of a function copy arguments and local variables if
they are still used by a referenced closure.
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Sat, 02 May 2020 18:00:04 +0200 |
parents | 23d75968ca5e |
children | 683c2da4982b |
comparison
equal
deleted
inserted
replaced
20246:ef2250432801 | 20247:e46e72aaff74 |
---|---|
69 ISN_DCALL, // call def function isn_arg.dfunc | 69 ISN_DCALL, // call def function isn_arg.dfunc |
70 ISN_UCALL, // call user function or funcref/partial isn_arg.ufunc | 70 ISN_UCALL, // call user function or funcref/partial isn_arg.ufunc |
71 ISN_PCALL, // call partial, use isn_arg.pfunc | 71 ISN_PCALL, // call partial, use isn_arg.pfunc |
72 ISN_PCALL_END, // cleanup after ISN_PCALL with cpf_top set | 72 ISN_PCALL_END, // cleanup after ISN_PCALL with cpf_top set |
73 ISN_RETURN, // return, result is on top of stack | 73 ISN_RETURN, // return, result is on top of stack |
74 ISN_FUNCREF, // push a function ref to dfunc isn_arg.number | 74 ISN_FUNCREF, // push a function ref to dfunc isn_arg.funcref |
75 | 75 |
76 // expression operations | 76 // expression operations |
77 ISN_JUMP, // jump if condition is matched isn_arg.jump | 77 ISN_JUMP, // jump if condition is matched isn_arg.jump |
78 | 78 |
79 // loop | 79 // loop |
215 // arguments to ISN_UNLET | 215 // arguments to ISN_UNLET |
216 typedef struct { | 216 typedef struct { |
217 char_u *ul_name; // variable name with g:, w:, etc. | 217 char_u *ul_name; // variable name with g:, w:, etc. |
218 int ul_forceit; // forceit flag | 218 int ul_forceit; // forceit flag |
219 } unlet_T; | 219 } unlet_T; |
220 | |
221 // arguments to ISN_FUNCREF | |
222 typedef struct { | |
223 int fr_func; // function index | |
224 int fr_var_idx; // variable to store partial | |
225 } funcref_T; | |
220 | 226 |
221 /* | 227 /* |
222 * Instruction | 228 * Instruction |
223 */ | 229 */ |
224 struct isn_S { | 230 struct isn_S { |
247 storenr_T storenr; | 253 storenr_T storenr; |
248 storeopt_T storeopt; | 254 storeopt_T storeopt; |
249 loadstore_T loadstore; | 255 loadstore_T loadstore; |
250 script_T script; | 256 script_T script; |
251 unlet_T unlet; | 257 unlet_T unlet; |
258 funcref_T funcref; | |
252 } isn_arg; | 259 } isn_arg; |
253 }; | 260 }; |
261 | |
262 /* | |
263 * Structure to hold the context of a compiled function, used by closures | |
264 * defined in that function. | |
265 */ | |
266 typedef struct funcstack_S | |
267 { | |
268 garray_T fs_ga; // contains the stack, with: | |
269 // - arguments | |
270 // - frame | |
271 // - local variables | |
272 | |
273 int fs_refcount; // nr of closures referencing this funcstack | |
274 int fs_copyID; // for garray_T collection | |
275 } funcstack_T; | |
254 | 276 |
255 /* | 277 /* |
256 * Info about a function defined with :def. Used in "def_functions". | 278 * Info about a function defined with :def. Used in "def_functions". |
257 */ | 279 */ |
258 struct dfunc_S { | 280 struct dfunc_S { |
262 | 284 |
263 garray_T df_def_args_isn; // default argument instructions | 285 garray_T df_def_args_isn; // default argument instructions |
264 isn_T *df_instr; // function body to be executed | 286 isn_T *df_instr; // function body to be executed |
265 int df_instr_count; | 287 int df_instr_count; |
266 | 288 |
289 garray_T *df_ectx_stack; // where compiled closure finds local vars | |
290 int df_ectx_frame; // index of function frame in uf_ectx_stack | |
291 funcstack_T *df_funcstack; // copy of stack for closure, used after | |
292 // closure context function returns | |
293 | |
267 int df_varcount; // number of local variables | 294 int df_varcount; // number of local variables |
295 int df_closure_count; // number of closures created | |
268 }; | 296 }; |
269 | 297 |
270 // Number of entries used by stack frame for a function call. | 298 // Number of entries used by stack frame for a function call. |
299 // - function index | |
300 // - instruction index | |
301 // - previous frame index | |
271 #define STACK_FRAME_SIZE 3 | 302 #define STACK_FRAME_SIZE 3 |
272 | 303 |
273 | 304 |
274 #ifdef DEFINE_VIM9_GLOBALS | 305 #ifdef DEFINE_VIM9_GLOBALS |
275 // Functions defined with :def are stored in this growarray. | 306 // Functions defined with :def are stored in this growarray. |