Patch 8.2.2400

2021-02-11 Fir de Conversatie Bram Moolenaar


Patch 8.2.2501
Problem:Not always clear where an error is reported.
Solution:   Add the where_T structure and pass it around. (closes #7796)
Files:  src/structs.h, src/vim9type.c, src/proto/vim9type.pro,
src/errors.h, src/evalvars.c, src/proto/evalvars.pro, src/eval.c,
src/proto/eval.pro, src/vim9execute.c, src/vim9script.c,
src/proto/vim9script.pro, src/dict.c, src/list.c,
src/vim9compile.c, src/testdir/test_vim9_assign.vim


*** ../vim-8.2.2500/src/structs.h   2021-02-07 12:12:39.377215418 +0100
--- src/structs.h   2021-02-11 20:45:26.822390345 +0100
***
*** 4387,4389 
--- 4387,4396 
  MAGIC_ON = 3, // "\m" or 'magic'
  MAGIC_ALL = 4 // "\v" very magic
  } magic_T;
+ 
+ // Struct used to pass to error messages about where the error happened.
+ typedef struct {
+ charwt_index; // argument or variable index, 0 means unknown
+ charwt_variable;// "variable" when TRUE, "argument" otherwise
+ } where_T;
+ 
*** ../vim-8.2.2500/src/vim9type.c  2021-02-07 18:06:25.266692335 +0100
--- src/vim9type.c  2021-02-11 21:05:07.873763997 +0100
***
*** 399,411 
  return typval2type(tv, type_gap);
  }
  
  
  /*
   * Return FAIL if "expected" and "actual" don't match.
   * When "argidx" > 0 it is included in the error message.
   */
  int
! check_typval_type(type_T *expected, typval_T *actual_tv, int argidx)
  {
  garray_T  type_list;
  type_T*actual_type;
--- 399,420 
  return typval2type(tv, type_gap);
  }
  
+ int
+ check_typval_arg_type(type_T *expected, typval_T *actual_tv, int arg_idx)
+ {
+ where_T   where;
+ 
+ where.wt_index = arg_idx;
+ where.wt_variable = FALSE;
+ return check_typval_type(expected, actual_tv, where);
+ }
  
  /*
   * Return FAIL if "expected" and "actual" don't match.
   * When "argidx" > 0 it is included in the error message.
   */
  int
! check_typval_type(type_T *expected, typval_T *actual_tv, where_T where)
  {
  garray_T  type_list;
  type_T*actual_type;
***
*** 414,420 
  ga_init2(&type_list, sizeof(type_T *), 10);
  actual_type = typval2type(actual_tv, &type_list);
  if (actual_type != NULL)
!   res = check_type(expected, actual_type, TRUE, argidx);
  clear_type_list(&type_list);
  return res;
  }
--- 423,429 
  ga_init2(&type_list, sizeof(type_T *), 10);
  actual_type = typval2type(actual_tv, &type_list);
  if (actual_type != NULL)
!   res = check_type(expected, actual_type, TRUE, where);
  clear_type_list(&type_list);
  return res;
  }
***
*** 426,440 
  }
  
  void
! arg_type_mismatch(type_T *expected, type_T *actual, int argidx)
  {
  char *tofree1, *tofree2;
  char *typename1 = type_name(expected, &tofree1);
  char *typename2 = type_name(actual, &tofree2);
  
! if (argidx > 0)
!   semsg(_(e_argument_nr_type_mismatch_expected_str_but_got_str),
!argidx, typename1, typename2);
  else
semsg(_(e_type_mismatch_expected_str_but_got_str),
 typename1, typename2);
--- 435,463 
  }
  
  void
! arg_type_mismatch(type_T *expected, type_T *actual, int arg_idx)
! {
! where_T   where;
! 
! where.wt_index = arg_idx;
! where.wt_variable = FALSE;
! type_mismatch_where(expected, actual, where);
! }
! 
! void
! type_mismatch_where(type_T *expected, type_T *actual, where_T where)
  {
  char *tofree1, *tofree2;
  char *typename1 = type_name(expected, &tofree1);
  char *typename2 = type_name(actual, &tofree2);
  
! if (where.wt_index > 0)
! {
!   semsg(_(where.wt_variable
!   ? e_variable_nr_type_mismatch_expected_str_but_got_str
!   : e_argument_nr_type_mismatch_expected_str_but_got_str),
!where.wt_index, typename1, typename2);
! }
  else
semsg(_(e_type_mismatch_expected_str_but_got_str),
 typename1, typename2);
***
*** 448,454 
   * When "argidx" > 0 it is included in the error message.
   */
  int
! check_type(type_T *expected, type_T *actual, int give_msg, int argidx)
  {
  int ret = OK;
  
--- 471,477 
   * When "argidx" > 0 it is included in the error message.
   */
  int
! check_type(type_T *expected, type_T *actual, int give_msg, where_T where)
  {
  int ret = OK;
  
***
*** 469,475 
// Using number 0 or 1 for bool is OK.
return OK;
if (give_msg)
!   arg_type_mismatch(expected, actual, argidx);
return FAIL;
}
if (expected->tt_type == VAR_DICT || expected->tt_type == VAR_LIST)
--- 492,498 
// Using numb

Patch 8.2.2400

2021-01-24 Fir de Conversatie Bram Moolenaar


Patch 8.2.2400
Problem:Vim9: compiled functions are not profiled.
Solution:   Add initial changes to profile compiled functions.  Fix that a
script-local function was hard to debug.
Files:  runtime/doc/repeat.txt, src/vim9.h, src/vim9compile.c,
src/vim9execute.c, src/userfunc.c, src/proto/vim9compile.pro,
src/structs.h, src/vim9type.c, src/debugger.c, src/ex_cmds.h,
src/ex_docmd.c, src/profiler.c, src/proto/profiler.pro,
src/testdir/test_vim9_disassemble.vim,
src/testdir/test_profile.vim


*** ../vim-8.2.2399/runtime/doc/repeat.txt  2020-06-17 21:47:19.912798036 
+0200
--- runtime/doc/repeat.txt  2021-01-23 19:49:22.428623691 +0100
***
*** 346,351 
--- 354,367 
Vim version, or update Vim to a newer version.  See
|vimscript-version| for what changed between versions.
  
+ :vim9[script] [noclear]   *:vim9* *:vim9script*
+   Marks a script file as containing |Vim9-script|
+   commands.  Also see |vim9-namespace|.
+   Must be the first command in the file.
+   For [noclear] see |vim9-reload|.
+   Without the |+eval| feature this changes the syntax
+   for some commands.
+
*:scr* *:scriptnames*
  :scr[iptnames]List all sourced script names, in the order 
they were
first sourced.  The number is used for the script ID
***
*** 883,890 
  matches ".../plugin/explorer.vim" and "explorer.vim" in any other directory.
  
  The match for functions is done against the name as it's shown in the output
! of ":function".  For local functions this means that something like "99_"
! is prepended.
  
  Note that functions are first loaded and later executed.  When they are loaded
  the "file" breakpoints are checked, when they are executed the "func"
--- 899,907 
  matches ".../plugin/explorer.vim" and "explorer.vim" in any other directory.
  
  The match for functions is done against the name as it's shown in the output
! of ":function".  However, for local functions the script-specific prefix such
! as "99_" is ignored to make it easier to match script-local functions
! without knowing the ID of the script.
  
  Note that functions are first loaded and later executed.  When they are loaded
  the "file" breakpoints are checked, when they are executed the "func"
***
*** 939,948 
  
  Profiling means that Vim measures the time that is spent on executing
  functions and/or scripts.  The |+profile| feature is required for this.
! It is only included when Vim was compiled with "huge" features.
  
  You can also use the |reltime()| function to measure time.  This only requires
! the |+reltime| feature, which is present more often.
  
  For profiling syntax highlighting see |:syntime|.
  
--- 956,965 
  
  Profiling means that Vim measures the time that is spent on executing
  functions and/or scripts.  The |+profile| feature is required for this.
! It is included when Vim was compiled with "huge" features.
  
  You can also use the |reltime()| function to measure time.  This only requires
! the |+reltime| feature, which is present in more builds.
  
  For profiling syntax highlighting see |:syntime|.
  
***
*** 989,995 
  
  
  You must always start with a ":profile start fname" command.  The resulting
! file is written when Vim exits.  Here is an example of the output, with line
  numbers prepended for the explanation:
  
1 FUNCTION  Test2() ~
--- 1006,1017 
  
  
  You must always start with a ":profile start fname" command.  The resulting
! file is written when Vim exits.  For example, to profile one specific
! function: >
!   profile start /tmp/vimprofile
!   profile func MyFunc
! 
! Here is an example of the output, with line
  numbers prepended for the explanation:
  
1 FUNCTION  Test2() ~
*** ../vim-8.2.2399/src/vim9.h  2021-01-22 17:51:02.762771043 +0100
--- src/vim9.h  2021-01-23 17:52:56.108568978 +0100
***
*** 152,157 
--- 152,160 
  ISN_CMDMOD,   // set cmdmod
  ISN_CMDMOD_REV, // undo ISN_CMDMOD
  
+ ISN_PROF_START, // start a line for profiling
+ ISN_PROF_END,   // end a line for profiling
+ 
  ISN_UNPACK,   // unpack list into items, uses isn_arg.unpack
  ISN_SHUFFLE,// move item on stack up or down
  ISN_DROP  // pop stack and discard value
***
*** 366,373 
// was compiled.
  
  garray_T  df_def_args_isn;// default argument instruc