vim-patch:8.2.0056: execution stack is incomplete and inefficient

Problem:    Execution stack is incomplete and inefficient.
Solution:   Introduce a proper execution stack and use it instead of
            sourcing_name/sourcing_lnum.  Create a string only when used.
1a47ae32cd

Omit test_debugger.vim: superseded by later patches.
Omit check_map_keycodes(): N/A.
Omit kword_test.c: N/A (converted to a unit test).
This commit is contained in:
zeertzjq
2022-08-13 13:48:11 +08:00
parent c1cbe3fb3d
commit f52c236c5b
23 changed files with 372 additions and 252 deletions

View File

@@ -3,7 +3,44 @@
#include <stdbool.h>
#include "nvim/autocmd.h"
#include "nvim/eval/typval.h"
#include "nvim/ex_cmds_defs.h"
#include "nvim/ex_eval_defs.h"
/// Entry in the execution stack "exestack".
typedef enum {
ETYPE_TOP, // toplevel
ETYPE_SCRIPT, // sourcing script, use es_info.sctx
ETYPE_UFUNC, // user function, use es_info.ufunc
ETYPE_AUCMD, // autocomand, use es_info.aucmd
ETYPE_MODELINE, // modeline, use es_info.sctx
ETYPE_EXCEPT, // exception, use es_info.exception
ETYPE_ARGS, // command line argument
ETYPE_ENV, // environment variable
ETYPE_INTERNAL, // internal operation
ETYPE_SPELL, // loading spell file
} etype_T;
typedef struct {
linenr_T es_lnum; ///< replaces "sourcing_lnum"
char *es_name; ///< replaces "sourcing_name"
etype_T es_type;
union {
sctx_T *sctx; ///< script and modeline info
ufunc_T *ufunc; ///< function info
AutoPatCmd *aucmd; ///< autocommand info
except_T *except; ///< exception info
} es_info;
} estack_T;
/// Stack of execution contexts. Each entry is an estack_T.
/// Current context is at ga_len - 1.
extern garray_T exestack;
/// name of error message source
#define SOURCING_NAME (((estack_T *)exestack.ga_data)[exestack.ga_len - 1].es_name)
/// line number in the message source or zero
#define SOURCING_LNUM (((estack_T *)exestack.ga_data)[exestack.ga_len - 1].es_lnum)
typedef struct scriptitem_S {
char_u *sn_name;