Patch 9.0.1188

2023-01-12 Fir de Conversatie Bram Moolenaar


Patch 9.0.1188
Problem:Return value of type() for class and object unclear.
Solution:   Add v:t_object and v:t_class.
Files:  runtime/doc/builtin.txt, runtime/doc/eval.txt, src/evalvars.c,
src/vim.h, src/testdir/test_vim9_class.vim


*** ../vim-9.0.1187/runtime/doc/builtin.txt 2022-12-20 20:01:09.620090910 
+
--- runtime/doc/builtin.txt 2023-01-12 21:01:44.772871744 +
***
*** 9099,9104 
--- 9113,9120 
Blob0z00112233.44556677.8899
List[item, item]
Dictionary  {key: value, key: value}
+   Class   class SomeName
+   Object  object of SomeName {lnum: 1, col: 3}
  
When a |List| or |Dictionary| has a recursive reference it is
replaced by "[...]" or "{...}".  Using eval() on the result
***
*** 9931,9936 
--- 9947,9954 
Job:8  |v:t_job|
Channel:9  |v:t_channel|
Blob:  10  |v:t_blob|
+   Class  12  |v:t_class|
+   Object 13  |v:t_object|
For backward compatibility, this method can be used: >
:if type(myvar) == type(0)
:if type(myvar) == type("")
*** ../vim-9.0.1187/runtime/doc/eval.txt2022-10-11 21:51:09.958103576 
+0100
--- runtime/doc/eval.txt2023-01-12 20:52:51.940746877 +
***
*** 2498,2503 
--- 2504,2513 
  v:t_stringValue of |String| type.  Read-only.  See: |type()|
*v:t_blob* *t_blob-variable*
  v:t_blob  Value of |Blob| type.  Read-only.  See: |type()|
+   *v:t_class* *t_class-variable*
+ v:t_class Value of |class| type.  Read-only.  See: |type()|
+   *v:t_object* *t_object-variable*
+ v:t_objectValue of |object| type.  Read-only.  See: |type()|
  
*v:termresponse* *termresponse-variable*
  v:termresponseThe escape sequence returned by the terminal for the 
|t_RV|
*** ../vim-9.0.1187/src/evalvars.c  2023-01-12 20:04:47.352343705 +
--- src/evalvars.c  2023-01-12 20:55:57.640806157 +
***
*** 139,144 
--- 139,146 
  {VV_NAME("t_job",  VAR_NUMBER), NULL, VV_RO},
  {VV_NAME("t_channel",  VAR_NUMBER), NULL, VV_RO},
  {VV_NAME("t_blob", VAR_NUMBER), NULL, VV_RO},
+ {VV_NAME("t_class",VAR_NUMBER), NULL, VV_RO},
+ {VV_NAME("t_object",   VAR_NUMBER), NULL, VV_RO},
  {VV_NAME("termrfgresp",VAR_STRING), NULL, VV_RO},
  {VV_NAME("termrbgresp",VAR_STRING), NULL, VV_RO},
  {VV_NAME("termu7resp", VAR_STRING), NULL, VV_RO},
***
*** 255,260 
--- 257,264 
  set_vim_var_nr(VV_TYPE_JOB, VAR_TYPE_JOB);
  set_vim_var_nr(VV_TYPE_CHANNEL, VAR_TYPE_CHANNEL);
  set_vim_var_nr(VV_TYPE_BLOB,VAR_TYPE_BLOB);
+ set_vim_var_nr(VV_TYPE_CLASS,   VAR_TYPE_CLASS);
+ set_vim_var_nr(VV_TYPE_OBJECT,  VAR_TYPE_OBJECT);
  
  set_vim_var_nr(VV_ECHOSPACE,sc_col - 1);
  
*** ../vim-9.0.1187/src/vim.h   2023-01-05 19:59:14.003418087 +
--- src/vim.h   2023-01-12 20:55:09.504792868 +
***
*** 2083,2105 
  #define VV_TYPE_JOB   85
  #define VV_TYPE_CHANNEL   86
  #define VV_TYPE_BLOB  87
! #define VV_TERMRFGRESP88
! #define VV_TERMRBGRESP89
! #define VV_TERMU7RESP 90
! #define VV_TERMSTYLERESP 91
! #define VV_TERMBLINKRESP 92
! #define VV_EVENT  93
! #define VV_VERSIONLONG94
! #define VV_ECHOSPACE  95
! #define VV_ARGV   96
! #define VV_COLLATE  97
! #define VV_EXITING98
! #define VV_COLORNAMES   99
! #define VV_SIZEOFINT  100
! #define VV_SIZEOFLONG 101
! #define VV_SIZEOFPOINTER 102
! #define VV_MAXCOL 103
! #define VV_LEN104 // number of v: vars
  
  // used for v_number in VAR_BOOL and VAR_SPECIAL
  #define VVAL_FALSE0L  // VAR_BOOL
--- 2083,2107 
  #define VV_TYPE_JOB   85
  #define VV_TYPE_CHANNEL   86
  #define VV_TYPE_BLOB  87
! #define VV_TYPE_CLASS 88
! #define VV_TYPE_OBJECT89
! #define VV_TERMRFGRESP90
! #define VV_TERMRBGRESP91
! #define VV_TERMU7RESP 92
! #define VV_TERMSTYLERESP 93
! #define VV_TERMBLINKRESP 94
! #define VV_EVENT  95
! #define VV_VERSIONLONG96
! #define VV_ECHOSPACE  97
! #define VV_ARGV   98
! #define VV_COLLATE  99
! #define VV_EXITING100
! #define VV_COLORNAMES   101
! #define VV_SIZEOFINT  102
! #define VV_SIZEOFLONG 103
! #define VV_SIZEOFPOINTER 104
! #define VV_MAXCOL 105
! #define VV_LEN106 // number of v: vars
  
  // used for v_number in VAR_BOOL and VAR_SPECIAL
  #define 

Patch 9.0.1187

2023-01-12 Fir de Conversatie Bram Moolenaar


Patch 9.0.1187
Problem:Test for using imported class fails.
Solution:   Skip over rest of type.
Files:  src/vim9type.c


*** ../vim-9.0.1186/src/vim9type.c  2023-01-12 17:06:24.136720890 +
--- src/vim9type.c  2023-01-12 20:01:59.856393723 +
***
*** 1310,1316 
--- 1310,1321 
type->tt_type = VAR_OBJECT;
type->tt_member = (type_T *)tv.vval.v_class;
clear_tv();
+ 
*arg += len;
+   // Skip over ".ClassName".
+   while (ASCII_ISALNUM(**arg) || **arg == '_' || **arg == '.')
+   ++*arg;
+ 
return type;
}
}
*** ../vim-9.0.1186/src/version.c   2023-01-12 20:04:47.356343702 +
--- src/version.c   2023-01-12 20:38:43.540617419 +
***
*** 697,698 
--- 697,700 
  {   /* Add new patch number below this line */
+ /**/
+ 1187,
  /**/

-- 
If someone questions your market projections, simply point out that your
target market is "People who are nuts" and "People who will buy any damn
thing".  Nobody is going to tell you there aren't enough of those people
to go around.
(Scott Adams - The Dilbert principle)

 /// Bram Moolenaar -- b...@moolenaar.net -- http://www.Moolenaar.net   \\\
///  \\\
\\\sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ ///
 \\\help me help AIDS victims -- http://ICCF-Holland.org///

-- 
-- 
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

--- 
You received this message because you are subscribed to the Google Groups 
"vim_dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to vim_dev+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/vim_dev/20230112203949.D72681C42FA%40moolenaar.net.


Re: Choices for Vim9 class implementation

2023-01-12 Fir de Conversatie skywind3000
- declaring a class inside a function allows me put related code together
- can be used to simulate a closure function.

example for java:

button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
AsyncTaskRunner runner = new AsyncTaskRunner();
String sleepTime = time.getText().toString();
runner.execute(sleepTime);
}
});

and python:

def subscript(event_list):
class MyListener(EventListener):
def __init__ (self, id):
self.id = id
def on_enter (self):
# do something
return -1
def on_leave (self):
# done
for event in event_list:
x = MyListener(event)
scheduler.add_listener(x)

在2023年1月13日星期五 UTC+8 04:05:46 写道:

>
> > One more thing about vim9 class:
> > 
> > can we define a named or anonymous class inside a function ?
> > That can be used to simulate a closure,
>
> It can be made possible, but the usefulness might be minimal. Perhaps
> you can give an example (possibliy in another language) of what you want
> to do.
>
> The idea of class support is to just implement the basics, what most
> other languages also have. Not adding all kinds of "nice to have"
> features.
>
> > And maybe, someday, we can translate javascript or lua to vim9script 
> with 
> > this feature.
>
> Javascript is a bit of a weird language, it will be very hard to
> translate into another language, because it has some constructs that
> most other languages don't have.
>
> Anyway, I don't see this as a goal.
>
> -- 
> I think that you'll agree that engineers are very effective in their social
> interactions. It's the "normal" people who are nuts.
> (Scott Adams - The Dilbert principle)
>
> /// Bram Moolenaar -- br...@moolenaar.net -- http://www.Moolenaar.net \\\
> /// \\\
> \\\ sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ ///
> \\\ help me help AIDS victims -- http://ICCF-Holland.org ///
>

-- 
-- 
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

--- 
You received this message because you are subscribed to the Google Groups 
"vim_dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to vim_dev+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/vim_dev/7b3616e4-52bc-49d4-a0cf-aa699c830137n%40googlegroups.com.


Re: Choices for Vim9 class implementation

2023-01-12 Fir de Conversatie Bram Moolenaar


> One more thing about vim9 class:
> 
> can we define a named or anonymous class inside a function ?
> That can be used to simulate a closure,

It can be made possible, but the usefulness might be minimal.  Perhaps
you can give an example (possibliy in another language) of what you want
to do.

The idea of class support is to just implement the basics, what most
other languages also have.  Not adding all kinds of "nice to have"
features.

> And maybe, someday, we can translate javascript or lua to vim9script with 
> this feature.

Javascript is a bit of a weird language, it will be very hard to
translate into another language, because it has some constructs that
most other languages don't have.

Anyway, I don't see this as a goal.

-- 
I think that you'll agree that engineers are very effective in their social
interactions.  It's the "normal" people who are nuts.
(Scott Adams - The Dilbert principle)

 /// Bram Moolenaar -- b...@moolenaar.net -- http://www.Moolenaar.net   \\\
///  \\\
\\\sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ ///
 \\\help me help AIDS victims -- http://ICCF-Holland.org///

-- 
-- 
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

--- 
You received this message because you are subscribed to the Google Groups 
"vim_dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to vim_dev+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/vim_dev/20230112200537.6E98B1C7B3E%40moolenaar.net.


Patch 9.0.1186

2023-01-12 Fir de Conversatie Bram Moolenaar


Patch 9.0.1186
Problem:Imported class does not work when used twice in a line.
Solution:   Fix the type parsing.
Files:  src/evalvars.c, src/testdir/test_vim9_class.vim


*** ../vim-9.0.1185/src/evalvars.c  2023-01-12 17:06:24.136720890 +
--- src/evalvars.c  2023-01-12 20:03:24.844367971 +
***
*** 3122,3129 
return FAIL;
  if (rettv->v_type == VAR_ANY && *s == '.')
  {
int sid = rettv->vval.v_number;
!   return eval_variable(s + 1, 0, sid, rettv, NULL, 0);
  }
  return OK;
  }
--- 3122,3133 
return FAIL;
  if (rettv->v_type == VAR_ANY && *s == '.')
  {
+   char_u *ns = s + 1;
+   s = ns;
+   while (ASCII_ISALNUM(*s) || *s == '_')
+   ++s;
int sid = rettv->vval.v_number;
!   return eval_variable(ns, (int)(s - ns), sid, rettv, NULL, 0);
  }
  return OK;
  }
*** ../vim-9.0.1185/src/testdir/test_vim9_class.vim 2023-01-12 
17:06:24.136720890 +
--- src/testdir/test_vim9_class.vim 2023-01-12 19:44:13.992887085 +
***
*** 992,997 
--- 992,1001 
a = animal.Animal.new('fish', 'Eric')
assert_equal('fish', a.kind)
assert_equal('Eric', a.name)
+ 
+   var b: animal.Animal = animal.Animal.new('cat', 'Garfield')
+   assert_equal('cat', b.kind)
+   assert_equal('Garfield', b.name)
END
v9.CheckScriptSuccess(lines)
  enddef
*** ../vim-9.0.1185/src/version.c   2023-01-12 17:06:24.140720888 +
--- src/version.c   2023-01-12 19:49:02.028701873 +
***
*** 697,698 
--- 697,700 
  {   /* Add new patch number below this line */
+ /**/
+ 1186,
  /**/

-- 
I learned the customs and mannerisms of engineers by observing them, much the
way Jane Goodall learned about the great apes, but without the hassle of
grooming.
(Scott Adams - The Dilbert principle)

 /// Bram Moolenaar -- b...@moolenaar.net -- http://www.Moolenaar.net   \\\
///  \\\
\\\sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ ///
 \\\help me help AIDS victims -- http://ICCF-Holland.org///

-- 
-- 
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

--- 
You received this message because you are subscribed to the Google Groups 
"vim_dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to vim_dev+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/vim_dev/20230112200537.73C611C7B46%40moolenaar.net.


Re: vim 9 dictionary keys cannot be dictionaries, lists, funcrefs or objects

2023-01-12 Fir de Conversatie Bram Moolenaar


> Just wondering is there is a chance that a future version of vim will allow 
> dictionary keys to be not just strings but dictionaries, lists, funcrefs or 
> other objects?
> 
> Other languages do allow this, such as Emacs Lisp, Python, Javascript, Lua, 
> C (like GLib).

Well, in the long list of features that could be added, I don't think
this would be near the top.  Although it sounds nice, the practical
usage is rather limited.  In most cases using string() on whatever you
want to use as a key will do the same thing, thus there doesn't seem to
be much reason to support this internally.

-- 
A radioactive cat has eighteen half-lives.

 /// Bram Moolenaar -- b...@moolenaar.net -- http://www.Moolenaar.net   \\\
///  \\\
\\\sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ ///
 \\\help me help AIDS victims -- http://ICCF-Holland.org///

-- 
-- 
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

--- 
You received this message because you are subscribed to the Google Groups 
"vim_dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to vim_dev+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/vim_dev/20230112200537.640B31C42FA%40moolenaar.net.


Re: Choices for Vim9 class implementation

2023-01-12 Fir de Conversatie skywind3000
One more thing about vim9 class:

can we define a named or anonymous class inside a function ?
That can be used to simulate a closure,

And maybe, someday, we can translate javascript or lua to vim9script with 
this feature.

在2022年12月28日星期三 UTC+8 00:29:24 写道:

>
> > > > This following currently defines a field and is, without context,
> > > > indistinguishable from any other assignment. Is that intended?
> > >
> > > With "var" it's indistinguishable from another declaration, I don't
> > > think it matters much that it looks like an assignment otherwise.
> > >
> > 
> > There's only one declaration per class assuming either a qualified name 
> is
> > used in the declaration or normal shadowing rules apply.
> > 
> > So, ignoring subjective aesthetic issues, this would allow for tooling to
> > more easily identify the declaration.
>
> Yes, there are some reasons to declare object members with "var".
> It's hard to decide what matters most. Perhaps "making it look like a
> declaration" is more important than other reasons. The space taken up
> by the extra "var" keyword probably doesn't matter much.
>
> > > > It seems from the documentation that static fields can be referenced 
> as
> > > > bare identifiers? This feels a bit unexpected to me given that 
> instance
> > > > fields are always qualified.
> > >
> > > Static fields (class members) are totally different from object 
> members.
> > > I have always found it confusing, in many languages it's hard to tell
> > > them apart, especially if the declaration is further away. Always using
> > > "this" for object members helps a lot for this. I would not know what
> > > to use for class members. The only thing I have seen is using the class
> > > name, which can be long (and gets tricky when using inheritance).
> > > I believe most languages access class members directly, without a
> > > prefix.
> > 
> > I think they're much the same in terms of the problems the required 
> "this"
> > qualifier is attempting to address. Static fields also need 
> disambiguation
> > in shadowed contexts and could, arguably, also use better identification.
>
> Assigning to a static class member in a constructor is unusual, thus the
> common problem that an argument name matches a member name is unlikely
> to happen for a class member. We could probably disallow shadowing a
> class member. We can at least start with that and see if that doesn't
> cause annoyance.
>
> > Are methods going to need to be qualified too?
>
> Object methods are always called on an object "obj.method()".
> I suppose "this.method()" also works (don't see this very often).
> Just using "method()" probably needs to be disallowed. Especially if we
> require prefixing "this." for object members.
>
> > Cards on the table, I'm not in favour of requiring qualified
> > references. I just found it surprising that only unqualified instance
> > fields were considered a problem.
>
> That is the reality. All this is much more about what a developer
> encounters on a regular basis than theory or philosophy. Especially
> when it comes to what mistakes people tend to make and whether it's
> possible to give a helpful error for them. Every time I have started
> using a new language (usually advertised as being the best ever) I have
> run into things that don't work well in practice.
>
> -- 
> ARTHUR: Charge!
> [They all charge with swords drawn towards the RABBIT. A tremendous twenty
> second fight with Peckinpahish shots and borrowing heavily also on the
> Kung Fu and karate-type films ensues, in which some four KNIGHTS are
> comprehensively killed.]
> ARTHUR: Run away! Run away!
> "Monty Python and the Holy Grail" PYTHON (MONTY) PICTURES LTD
>
> /// Bram Moolenaar -- br...@moolenaar.net -- http://www.Moolenaar.net \\\
> /// \\\
> \\\ sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ ///
> \\\ help me help AIDS victims -- http://ICCF-Holland.org ///
>

-- 
-- 
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

--- 
You received this message because you are subscribed to the Google Groups 
"vim_dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to vim_dev+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/vim_dev/a650df7d-f737-453d-b774-ba36263a3dfen%40googlegroups.com.


Patch 9.0.1185

2023-01-12 Fir de Conversatie Bram Moolenaar


Patch 9.0.1185
Problem:Using class from imported script not tested.
Solution:   Add tests.  Implement what is missing.
Files:  src/vim9type.c, src/evalvars.c, src/proto/evalvars.pro,
src/vim9class.c, src/testdir/test_vim9_class.vim


*** ../vim-9.0.1184/src/vim9type.c  2023-01-12 15:01:28.833314453 +
--- src/vim9type.c  2023-01-12 16:12:48.754979318 +
***
*** 982,988 
  
  if (optional && *p == '?')
++p;
! while (ASCII_ISALNUM(*p) || *p == '_')
++p;
  
  // Skip over ""; this is permissive about white space.
--- 982,990 
  
  if (optional && *p == '?')
++p;
! 
! // Also skip over "." for imported classes: "import.ClassName".
! while (ASCII_ISALNUM(*p) || *p == '_' || *p == '.')
++p;
  
  // Skip over ""; this is permissive about white space.
***
*** 1091,1097 
  char_u  *p = *arg;
  size_t  len;
  
! // skip over the first word
  while (ASCII_ISALNUM(*p) || *p == '_')
++p;
  len = p - *arg;
--- 1093,1099 
  char_u  *p = *arg;
  size_t  len;
  
! // Skip over the first word.
  while (ASCII_ISALNUM(*p) || *p == '_')
++p;
  len = p - *arg;
***
*** 1293,1302 
break;
  }
  
! // It can be a class or interface name.
  typval_T tv;
  tv.v_type = VAR_UNKNOWN;
! if (eval_variable(*arg, (int)len, 0, , NULL, EVAL_VAR_IMPORT) == OK)
  {
if (tv.v_type == VAR_CLASS && tv.vval.v_class != NULL)
{
--- 1295,1304 
break;
  }
  
! // It can be a class or interface name, possibly imported.
  typval_T tv;
  tv.v_type = VAR_UNKNOWN;
! if (eval_variable_import(*arg, ) == OK)
  {
if (tv.v_type == VAR_CLASS && tv.vval.v_class != NULL)
{
*** ../vim-9.0.1184/src/evalvars.c  2023-01-06 18:42:16.430674097 +
--- src/evalvars.c  2023-01-12 16:50:30.537657495 +
***
*** 3105,3110 
--- 3105,3135 
  }
  
  /*
+  * Get the value of internal variable "name", also handling "import.name".
+  * Return OK or FAIL.  If OK is returned "rettv" must be cleared.
+  */
+ int
+ eval_variable_import(
+ char_u*name,
+ typval_T  *rettv)
+ {
+ char_u  *s = name;
+ while (ASCII_ISALNUM(*s) || *s == '_')
+   ++s;
+ int   len = (int)(s - name);
+ 
+ if (eval_variable(name, len, 0, rettv, NULL, EVAL_VAR_IMPORT) == FAIL)
+   return FAIL;
+ if (rettv->v_type == VAR_ANY && *s == '.')
+ {
+   int sid = rettv->vval.v_number;
+   return eval_variable(s + 1, 0, sid, rettv, NULL, 0);
+ }
+ return OK;
+ }
+ 
+ 
+ /*
   * Check if variable "name[len]" is a local variable or an argument.
   * If so, "*eval_lavars_used" is set to TRUE.
   */
*** ../vim-9.0.1184/src/proto/evalvars.pro  2022-09-11 15:14:00.551020049 
+0100
--- src/proto/evalvars.pro  2023-01-12 16:12:54.786981365 +
***
*** 60,65 
--- 60,66 
  char_u *v_throwpoint(char_u *oldval);
  char_u *set_cmdarg(exarg_T *eap, char_u *oldarg);
  int eval_variable(char_u *name, int len, scid_T sid, typval_T *rettv, 
dictitem_T **dip, int flags);
+ int eval_variable_import(char_u *name, typval_T *rettv);
  void check_vars(char_u *name, int len);
  dictitem_T *find_var(char_u *name, hashtab_T **htp, int no_autoload);
  dictitem_T *find_var_also_in_script(char_u *name, hashtab_T **htp, int 
no_autoload);
*** ../vim-9.0.1184/src/vim9class.c 2023-01-12 15:01:28.833314453 +
--- src/vim9class.c 2023-01-12 16:38:15.217892971 +
***
*** 244,252 
  }
  char_u *name_start = arg;
  
  // TODO:
  //generics: 
- //  handle "is_export" if it is set
  
  // Name for "extends BaseClass"
  char_u *extends = NULL;
--- 244,256 
  }
  char_u *name_start = arg;
  
+ // "export class" gets used when creating the class, don't use "is_export"
+ // for the items inside the class.
+ int class_export = is_export;
+ is_export = FALSE;
+ 
  // TODO:
  //generics: 
  
  // Name for "extends BaseClass"
  char_u *extends = NULL;
***
*** 558,564 
  {
typval_T tv;
tv.v_type = VAR_UNKNOWN;
!   if (eval_variable(extends, 0, 0, , NULL, EVAL_VAR_IMPORT) == FAIL)
{
semsg(_(e_class_name_not_found_str), extends);
success = FALSE;
--- 562,568 
  {
typval_T tv;
tv.v_type = VAR_UNKNOWN;
!   if (eval_variable_import(extends, ) == FAIL)
{
semsg(_(e_class_name_not_found_str), extends);
success = FALSE;
***
*** 594,600 
char_u *impl = ((char_u **)ga_impl.ga_data)[i];
typval_T tv;
tv.v_type = VAR_UNKNOWN;
!   if (eval_variable(impl, 0, 0, , NULL, EVAL_VAR_IMPORT) == FAIL)
{

Patch 9.0.1184

2023-01-12 Fir de Conversatie Bram Moolenaar


Patch 9.0.1184
Problem:Interface of an object is not recognized when checking type.
Solution:   Use the interface implemented by an object.
Files:  src/vim9type.c, src/structs.h, src/vim9class.c,
src/testdir/test_vim9_class.vim


*** ../vim-9.0.1183/src/vim9type.c  2023-01-11 21:14:11.832106048 +
--- src/vim9type.c  2023-01-12 13:54:29.918762015 +
***
*** 876,886 
--- 876,896 
}
else if (expected->tt_type == VAR_OBJECT)
{
+   // check the class, base class or an implemented interface matches
class_T *cl;
for (cl = (class_T *)actual->tt_member; cl != NULL;
cl = cl->class_extends)
+   {
if ((class_T *)expected->tt_member == cl)
break;
+   int i;
+   for (i = cl->class_interface_count - 1; i >= 0; --i)
+   if ((class_T *)expected->tt_member
+== cl->class_interfaces_cl[i])
+   break;
+   if (i >= 0)
+   break;
+   }
if (cl == NULL)
ret = FAIL;
}
*** ../vim-9.0.1183/src/structs.h   2023-01-11 15:59:01.175405240 +
--- src/structs.h   2023-01-12 13:47:23.316980720 +
***
*** 1500,1505 
--- 1500,1506 
  // interfaces declared for the class
  int   class_interface_count;
  char_u**class_interfaces; // allocated array of names
+ class_T   **class_interfaces_cl;  // interfaces (counts as reference)
  
  // class members: "static varname"
  int   class_class_member_count;
*** ../vim-9.0.1183/src/vim9class.c 2023-01-11 15:59:01.175405240 +
--- src/vim9class.c 2023-01-12 14:22:27.662808427 +
***
*** 582,590 
--- 582,594 
  }
  VIM_CLEAR(extends);
  
+ class_T **intf_classes = NULL;
+ 
  // Check all "implements" entries are valid.
  if (success && ga_impl.ga_len > 0)
  {
+   intf_classes = ALLOC_CLEAR_MULT(class_T *, ga_impl.ga_len);
+ 
for (int i = 0; i < ga_impl.ga_len && success; ++i)
{
char_u *impl = ((char_u **)ga_impl.ga_data)[i];
***
*** 605,612 
success = FALSE;
}
  
-   // check the members of the interface match the members of the class
class_T *ifcl = tv.vval.v_class;
for (int loop = 1; loop <= 2 && success; ++loop)
{
// loop == 1: check class members
--- 609,619 
success = FALSE;
}
  
class_T *ifcl = tv.vval.v_class;
+   intf_classes[i] = ifcl;
+   ++ifcl->class_refcount;
+ 
+   // check the members of the interface match the members of the class
for (int loop = 1; loop <= 2 && success; ++loop)
{
// loop == 1: check class members
***
*** 717,722 
--- 724,732 
cl->class_interfaces[i] = ((char_u **)ga_impl.ga_data)[i];
VIM_CLEAR(ga_impl.ga_data);
ga_impl.ga_len = 0;
+ 
+   cl->class_interfaces_cl = intf_classes;
+   intf_classes = NULL;
}
  
// Add class and object members to "cl".
***
*** 930,935 
--- 940,957 
  {
vim_free(cl->class_name);
vim_free(cl->class_class_functions);
+   if (cl->class_interfaces != NULL)
+   {
+   for (int i = 0; i < cl->class_interface_count; ++i)
+   vim_free(cl->class_interfaces[i]);
+   vim_free(cl->class_interfaces);
+   }
+   if (cl->class_interfaces_cl != NULL)
+   {
+   for (int i = 0; i < cl->class_interface_count; ++i)
+   class_unref(cl->class_interfaces_cl[i]);
+   vim_free(cl->class_interfaces_cl);
+   }
vim_free(cl->class_obj_members);
vim_free(cl->class_obj_methods);
vim_free(cl);
***
*** 937,942 
--- 959,971 
  
  vim_free(extends);
  class_unref(extends_cl);
+ 
+ if (intf_classes != NULL)
+ {
+   for (int i = 0; i < ga_impl.ga_len; ++i)
+   class_unref(intf_classes[i]);
+   vim_free(intf_classes);
+ }
  ga_clear_strings(_impl);
  
  for (int round = 1; round <= 2; ++round)
***
*** 1321,1328 
--- 1350,1362 
class_unref(cl->class_extends);
  
for (int i = 0; i < cl->class_interface_count; ++i)
+   {
vim_free(((char_u **)cl->class_interfaces)[i]);
+   if (cl->class_interfaces_cl[i] != NULL)
+   class_unref(cl->class_interfaces_cl[i]);
+   }
vim_free(cl->class_interfaces);
+   vim_free(cl->class_interfaces_cl);
  
for (int i = 0; i < cl->class_class_member_count; ++i)
{
*** 

nvim + vim9script: how Rust made it happen

2023-01-12 Fir de Conversatie Doug Kearns
Here's an update on the vim9script -> lua transpiler that TJ Devries
has been working on for some time.

https://www.youtube.com/watch?v=zPQSST-M3fM

Nice work TJ.

Regards,
Doug

-- 
-- 
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

--- 
You received this message because you are subscribed to the Google Groups 
"vim_dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to vim_dev+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/vim_dev/CAJ1uvoA1qfOfSmkr0sGg8sCQjwV_H5b799LhZTK_N9epTGnfeQ%40mail.gmail.com.


Patch 9.0.1183

2023-01-12 Fir de Conversatie Bram Moolenaar


Patch 9.0.1183
Problem:Code is indented more than necessary.
Solution:   Use an early return where it makes sense. (Yegappan Lakshmanan,
closes #11805)
Files:  src/if_cscope.c, src/if_lua.c, src/if_mzsch.c, src/if_python.c,
src/if_python3.c, src/if_ruby.c, src/if_xcmdsrv.c, src/indent.c


*** ../vim-9.0.1182/src/if_cscope.c 2022-10-13 16:34:27.130724804 +0100
--- src/if_cscope.c 2023-01-12 12:30:17.296724449 +
***
*** 221,245 
  expand_what = (cmdidx == CMD_scscope)
? EXP_SCSCOPE_SUBCMD : EXP_CSCOPE_SUBCMD;
  
  // (part of) subcommand already typed
! if (*arg != NUL)
! {
!   p = skiptowhite(arg);
!   if (*p != NUL)  // past first word
!   {
!   xp->xp_pattern = skipwhite(p);
!   if (*skiptowhite(xp->xp_pattern) != NUL)
!   xp->xp_context = EXPAND_NOTHING;
!   else if (STRNICMP(arg, "add", p - arg) == 0)
!   xp->xp_context = EXPAND_FILES;
!   else if (STRNICMP(arg, "kill", p - arg) == 0)
!   expand_what = EXP_CSCOPE_KILL;
!   else if (STRNICMP(arg, "find", p - arg) == 0)
!   expand_what = EXP_CSCOPE_FIND;
!   else
!   xp->xp_context = EXPAND_NOTHING;
!   }
! }
  }
  
  /*
--- 221,246 
  expand_what = (cmdidx == CMD_scscope)
? EXP_SCSCOPE_SUBCMD : EXP_CSCOPE_SUBCMD;
  
+ if (*arg == NUL)
+   return;
+ 
  // (part of) subcommand already typed
! p = skiptowhite(arg);
! if (*p == NUL)
!   return;
! 
! // past first word
! xp->xp_pattern = skipwhite(p);
! if (*skiptowhite(xp->xp_pattern) != NUL)
!   xp->xp_context = EXPAND_NOTHING;
! else if (STRNICMP(arg, "add", p - arg) == 0)
!   xp->xp_context = EXPAND_FILES;
! else if (STRNICMP(arg, "kill", p - arg) == 0)
!   expand_what = EXP_CSCOPE_KILL;
! else if (STRNICMP(arg, "find", p - arg) == 0)
!   expand_what = EXP_CSCOPE_FIND;
! else
!   xp->xp_context = EXPAND_NOTHING;
  }
  
  /*
*** ../vim-9.0.1182/src/if_lua.c2022-11-25 16:31:46.968606662 +
--- src/if_lua.c2023-01-12 12:30:17.296724449 +
***
*** 505,522 
  {
  void *p = lua_touserdata(L, ud);
  
! if (p != NULL) // value is userdata?
  {
!   if (lua_getmetatable(L, ud)) // does it have a metatable?
{
!   luaV_getfield(L, tname); // get metatable
!   if (lua_rawequal(L, -1, -2)) // MTs match?
!   {
!   lua_pop(L, 2); // MTs
!   return p;
!   }
}
  }
  return NULL;
  }
  
--- 505,524 
  {
  void *p = lua_touserdata(L, ud);
  
! if (p == NULL)
!   return NULL;
! 
! // value is userdata
! if (lua_getmetatable(L, ud)) // does it have a metatable?
  {
!   luaV_getfield(L, tname); // get metatable
!   if (lua_rawequal(L, -1, -2)) // MTs match?
{
!   lua_pop(L, 2); // MTs
!   return p;
}
  }
+ 
  return NULL;
  }
  
***
*** 1090,1106 
  dictitem_T *di = dict_find(d, key, -1);
  
  if (di == NULL)
lua_pushnil(L);
! else
  {
!   luaV_pushtypval(L, >di_tv);
!   if (di->di_tv.v_type == VAR_FUNC) // funcref?
!   {
!   luaV_Funcref *f = (luaV_Funcref *) lua_touserdata(L, -1);
!   f->self = d; // keep "self" reference
!   d->dv_refcount++;
!   }
  }
  return 1;
  }
  
--- 1092,1110 
  dictitem_T *di = dict_find(d, key, -1);
  
  if (di == NULL)
+ {
lua_pushnil(L);
!   return 1;
! }
! 
! luaV_pushtypval(L, >di_tv);
! if (di->di_tv.v_type == VAR_FUNC) // funcref?
  {
!   luaV_Funcref *f = (luaV_Funcref *) lua_touserdata(L, -1);
!   f->self = d; // keep "self" reference
!   d->dv_refcount++;
  }
+ 
  return 1;
  }
  
***
*** 1235,1254 
  blob_T *b = luaV_unbox(L, luaV_Blob, 1);
  if (b->bv_lock)
luaL_error(L, "blob is locked");
! if (lua_isnumber(L, 2))
! {
!   long len = blob_len(b);
!   int idx = luaL_checkinteger(L, 2);
!   int val = luaL_checkinteger(L, 3);
!   if (idx < len || (idx == len && ga_grow(>bv_ga, 1) == OK))
!   {
!   blob_set(b, idx, (char_u) val);
!   if (idx == len)
!   ++b->bv_ga.ga_len;
!   }
!   else
!   luaL_error(L, "index out of range");
  }
  return 0;
  }
  
--- 1239,1260 
  blob_T *b = luaV_unbox(L, luaV_Blob, 1);
  if (b->bv_lock)
luaL_error(L, "blob is locked");
! 
! if (!lua_isnumber(L, 2))
!   return 0;
! 
! long len = blob_len(b);
! int idx = luaL_checkinteger(L, 2);
! int val = luaL_checkinteger(L, 3);
! if (idx < len || (idx == len && ga_grow(>bv_ga, 1) == OK))
! {
!   blob_set(b, idx, (char_u) val);
!   if (idx == len)
!