To: vim_dev@googlegroups.com Subject: Patch 8.2.2291 Fcc: outbox From: Bram Moolenaar Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ------------ Patch 8.2.2291 Problem: Vim9: cannot use "null" for v:null. Solution: Support "null" like "true" and "false". (closes #7495) Files: runtime/doc/vim9.txt, src/vim9compile.c, src/evalvars.c, src/testdir/test_vim9_expr.vim *** ../vim-8.2.2290/runtime/doc/vim9.txt 2020-12-28 20:53:17.495051906 +0100 --- runtime/doc/vim9.txt 2021-01-03 21:42:56.145318965 +0100 *************** *** 14,20 **** THIS IS STILL UNDER DEVELOPMENT - ANYTHING CAN BREAK - ANYTHING CAN CHANGE ! 1. What is Vim9 script? |vim9-script| 2. Differences |vim9-differences| 3. New style functions |fast-functions| 4. Types |vim9-types| --- 14,20 ---- THIS IS STILL UNDER DEVELOPMENT - ANYTHING CAN BREAK - ANYTHING CAN CHANGE ! 1. What is Vim9 script? |Vim9-script| 2. Differences |vim9-differences| 3. New style functions |fast-functions| 4. Types |vim9-types| *************** *** 565,570 **** --- 565,577 ---- White space is required around most operators. + White space is required in a sublist (list slice) around the ":", except at + the start and end: > + otherlist = mylist[v : count] # v:count has a different meaning + otherlist = mylist[:] # make a copy of the List + otherlist = mylist[v :] + otherlist = mylist[: v] + White space is not allowed: - Between a function name and the "(": > call Func (arg) # Error! *************** *** 595,601 **** empty list and dict is falsy: type truthy when ~ ! bool v:true or 1 number non-zero float non-zero string non-empty --- 602,608 ---- empty list and dict is falsy: type truthy when ~ ! bool true, v:true or 1 number non-zero float non-zero string non-empty *************** *** 603,613 **** list non-empty (different from JavaScript) dictionary non-empty (different from JavaScript) func when there is a function name ! special v:true job when not NULL channel when not NULL class when not NULL ! object when not NULL (TODO: when isTrue() returns v:true) The boolean operators "||" and "&&" expect the values to be boolean, zero or one: > --- 610,620 ---- list non-empty (different from JavaScript) dictionary non-empty (different from JavaScript) func when there is a function name ! special true or v:true job when not NULL channel when not NULL class when not NULL ! object when not NULL (TODO: when isTrue() returns true) The boolean operators "||" and "&&" expect the values to be boolean, zero or one: > *************** *** 629,640 **** When using "`.."` for string concatenation arguments of simple types are always converted to string: > 'hello ' .. 123 == 'hello 123' ! 'hello ' .. v:true == 'hello v:true' Simple types are string, float, special and bool. For other types |string()| can be used. ! *false* *true* ! In Vim9 script one can use "true" for v:true and "false" for v:false. Indexing a string with [idx] or [idx, idx] uses character indexes instead of byte indexes. Example: > --- 636,650 ---- When using "`.."` for string concatenation arguments of simple types are always converted to string: > 'hello ' .. 123 == 'hello 123' ! 'hello ' .. v:true == 'hello true' Simple types are string, float, special and bool. For other types |string()| can be used. ! *false* *true* *null* ! In Vim9 script one can use "true" for v:true, "false" for v:false and "null" ! for v:null. When converting a boolean to a string "false" and "true" are ! used, not "v:false" and "v:true" like in legacy script. "v:none" is not ! changed, it is only used in JSON and has no equivalent in other languages. Indexing a string with [idx] or [idx, idx] uses character indexes instead of byte indexes. Example: > *** ../vim-8.2.2290/src/vim9compile.c 2021-01-03 20:55:22.807151946 +0100 --- src/vim9compile.c 2021-01-03 21:45:31.784781485 +0100 *************** *** 3968,3973 **** --- 3968,3987 ---- break; /* + * "null" constant + */ + case 'n': if (STRNCMP(*arg, "null", 4) == 0 + && !eval_isnamec((*arg)[5])) + { + *arg += 4; + rettv->v_type = VAR_SPECIAL; + rettv->vval.v_number = VVAL_NULL; + } + else + ret = NOTDONE; + break; + + /* * List: [expr, expr] */ case '[': ret = compile_list(arg, cctx, ppconst); *************** *** 5006,5011 **** --- 5020,5026 ---- static char *reserved[] = { "true", "false", + "null", NULL }; *** ../vim-8.2.2290/src/evalvars.c 2021-01-03 15:55:05.764625605 +0100 --- src/evalvars.c 2021-01-03 21:47:14.448429542 +0100 *************** *** 2072,2079 **** { case VVAL_FALSE: return in_vim9script() ? "false" : "v:false"; case VVAL_TRUE: return in_vim9script() ? "true" : "v:true"; case VVAL_NONE: return "v:none"; - case VVAL_NULL: return "v:null"; } internal_error("get_var_special_name()"); return "42"; --- 2072,2079 ---- { case VVAL_FALSE: return in_vim9script() ? "false" : "v:false"; case VVAL_TRUE: return in_vim9script() ? "true" : "v:true"; + case VVAL_NULL: return in_vim9script() ? "null" : "v:null"; case VVAL_NONE: return "v:none"; } internal_error("get_var_special_name()"); return "42"; *** ../vim-8.2.2290/src/testdir/test_vim9_expr.vim 2021-01-03 18:33:09.992382498 +0100 --- src/testdir/test_vim9_expr.vim 2021-01-03 21:52:06.583436184 +0100 *************** *** 511,516 **** --- 511,518 ---- assert_equal(true, v:none == v:none) assert_equal(false, v:none == v:null) assert_equal(true, g:anone == v:none) + assert_equal(true, null == v:null) + assert_equal(true, null == g:anull) assert_equal(false, v:none == g:anull) var nr0 = 0 *************** *** 1063,1069 **** assert_equal('atrue', 'a' .. true) assert_equal('afalse', 'a' .. false) ! assert_equal('av:null', 'a' .. v:null) assert_equal('av:none', 'a' .. v:none) if has('float') assert_equal('a0.123', 'a' .. 0.123) --- 1065,1071 ---- assert_equal('atrue', 'a' .. true) assert_equal('afalse', 'a' .. false) ! assert_equal('anull', 'a' .. v:null) assert_equal('av:none', 'a' .. v:none) if has('float') assert_equal('a0.123', 'a' .. 0.123) *************** *** 1657,1662 **** --- 1659,1665 ---- assert_equal(false, f) assert_equal(g:special_null, v:null) + assert_equal(g:special_null, null) assert_equal(g:special_none, v:none) END CheckDefAndScriptSuccess(lines) *** ../vim-8.2.2290/src/version.c 2021-01-03 20:55:22.807151946 +0100 --- src/version.c 2021-01-03 21:44:51.528919996 +0100 *************** *** 752,753 **** --- 752,755 ---- { /* Add new patch number below this line */ + /**/ + 2291, /**/ -- From "know your smileys": 8-O "Omigod!!" (done "rm -rf *" ?) /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net \\\ /// sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\ \\\ an exciting new programming language -- http://www.Zimbu.org /// \\\ help me help AIDS victims -- http://ICCF-Holland.org ///