From f52c236c5b432629f0e074c3511e7e9d481197b1 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Sat, 13 Aug 2022 13:48:11 +0800 Subject: 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. https://github.com/vim/vim/commit/1a47ae32cdc19b0fd5a82e19fe5fddf45db1a506 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). --- src/nvim/runtime.h | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) (limited to 'src/nvim/runtime.h') diff --git a/src/nvim/runtime.h b/src/nvim/runtime.h index fb12029693..a780abb8b1 100644 --- a/src/nvim/runtime.h +++ b/src/nvim/runtime.h @@ -3,7 +3,44 @@ #include +#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; -- cgit From ded2925b406f55223f6093544bc3a38534c1e72e Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Sat, 13 Aug 2022 16:07:05 +0800 Subject: refactor: change remaining sourcing_name/sourcing_lnum to exestack Co-Authored-By: VVKot --- src/nvim/runtime.h | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) (limited to 'src/nvim/runtime.h') diff --git a/src/nvim/runtime.h b/src/nvim/runtime.h index a780abb8b1..6f9f31c9c4 100644 --- a/src/nvim/runtime.h +++ b/src/nvim/runtime.h @@ -8,20 +8,20 @@ #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_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; +/// Entry in the execution stack "exestack". typedef struct { linenr_T es_lnum; ///< replaces "sourcing_lnum" char *es_name; ///< replaces "sourcing_name" -- cgit