eval: Remove v:none

To get v:none back just rever this commit. This will not make json*() functions
compatible with Vim though.
This commit is contained in:
ZyX
2016-02-06 02:46:23 +03:00
parent a3b87fc19b
commit 6167ce6df2
10 changed files with 8 additions and 73 deletions

View File

@@ -1569,13 +1569,6 @@ v:null Special value used to put "null" in JSON and NIL in msgpack.
See |jsonencode()|. This value is converted to "null" when See |jsonencode()|. This value is converted to "null" when
used as a String (e.g. in |expr5| with string concatenation used as a String (e.g. in |expr5| with string concatenation
operator) and to zero when used as a Number (e.g. in |expr5| operator) and to zero when used as a Number (e.g. in |expr5|
or |expr7| when used with numeric operators).
*v:none* *none-variable*
v:none Special value used to put an empty item in JSON. See
|jsonencode()|. This value is converted to "none" when used
as a String (e.g. in |expr5| with string concatenation
operator) and to zero when used as a Number (e.g. in |expr5|
or |expr7| when used with numeric operators). or |expr7| when used with numeric operators).
*v:oldfiles* *oldfiles-variable* *v:oldfiles* *oldfiles-variable*
@@ -4876,7 +4869,7 @@ msgpackdump({list}) {Nvim} *msgpackdump()*
messagepack). messagepack).
Limitations: *E951* *E952* *E953* Limitations: *E951* *E952* *E953*
1. |Funcref|s and |v:none| cannot be dumped. 1. |Funcref|s cannot be dumped.
2. Containers that reference themselves cannot be dumped. 2. Containers that reference themselves cannot be dumped.
3. Dictionary keys are always dumped as STR strings. 3. Dictionary keys are always dumped as STR strings.
4. Other strings are always dumped as BIN strings. 4. Other strings are always dumped as BIN strings.

View File

@@ -106,6 +106,10 @@ are always available and may be used simultaneously in separate plugins. The
|jsonencode()| behaviour slightly changed: now |msgpack-special-dict| values |jsonencode()| behaviour slightly changed: now |msgpack-special-dict| values
are accepted. are accepted.
*v:none* variable is absent. In Vim it represents “no value” in non-JSON
strings like "{"a": }" parsed as "{'a': v:none}". See |jsondecode()| and
|jsonencode()| incompatibilities above.
Viminfo text files were replaced with binary (messagepack) ShaDa files. Viminfo text files were replaced with binary (messagepack) ShaDa files.
Additional differences: Additional differences:

View File

@@ -659,8 +659,7 @@ static Object vim_to_object_rec(typval_T *obj, PMap(ptr_t) *lookup)
rv.data.boolean = (obj->vval.v_special == kSpecialVarTrue); rv.data.boolean = (obj->vval.v_special == kSpecialVarTrue);
break; break;
} }
case kSpecialVarNull: case kSpecialVarNull: {
case kSpecialVarNone: {
rv.type = kObjectTypeNil; rv.type = kObjectTypeNil;
break; break;
} }

View File

@@ -368,7 +368,6 @@ static struct vimvar {
{ VV_NAME("false", VAR_SPECIAL), VV_RO }, { VV_NAME("false", VAR_SPECIAL), VV_RO },
{ VV_NAME("true", VAR_SPECIAL), VV_RO }, { VV_NAME("true", VAR_SPECIAL), VV_RO },
{ VV_NAME("null", VAR_SPECIAL), VV_RO }, { VV_NAME("null", VAR_SPECIAL), VV_RO },
{ VV_NAME("none", VAR_SPECIAL), VV_RO },
}; };
/* shorthand */ /* shorthand */
@@ -512,7 +511,6 @@ void eval_init(void)
set_vim_var_special(VV_FALSE, kSpecialVarFalse); set_vim_var_special(VV_FALSE, kSpecialVarFalse);
set_vim_var_special(VV_TRUE, kSpecialVarTrue); set_vim_var_special(VV_TRUE, kSpecialVarTrue);
set_vim_var_special(VV_NONE, kSpecialVarNone);
set_vim_var_special(VV_NULL, kSpecialVarNull); set_vim_var_special(VV_NULL, kSpecialVarNull);
set_reg_var(0); // default for v:register is not 0 but '"' set_reg_var(0); // default for v:register is not 0 but '"'
@@ -16204,7 +16202,6 @@ static void f_type(typval_T *argvars, typval_T *rettv)
n = 6; n = 6;
break; break;
} }
case kSpecialVarNone:
case kSpecialVarNull: { case kSpecialVarNull: {
n = 7; n = 7;
break; break;
@@ -17520,7 +17517,6 @@ long get_tv_number_chk(typval_T *varp, int *denote)
return 1; return 1;
} }
case kSpecialVarFalse: case kSpecialVarFalse:
case kSpecialVarNone:
case kSpecialVarNull: { case kSpecialVarNull: {
return 0; return 0;
} }

View File

@@ -124,7 +124,6 @@ typedef enum {
VV_FALSE, VV_FALSE,
VV_TRUE, VV_TRUE,
VV_NULL, VV_NULL,
VV_NONE,
} VimVarIndex; } VimVarIndex;
/// All recognized msgpack types /// All recognized msgpack types

View File

@@ -55,7 +55,6 @@ typedef kvec_t(MPConvStackVal) MPConvStack;
const char *const encode_special_var_names[] = { const char *const encode_special_var_names[] = {
[kSpecialVarNull] = "null", [kSpecialVarNull] = "null",
[kSpecialVarNone] = "none",
[kSpecialVarTrue] = "true", [kSpecialVarTrue] = "true",
[kSpecialVarFalse] = "false", [kSpecialVarFalse] = "false",
}; };
@@ -358,10 +357,6 @@ static int name##_convert_one_value(firstargtype firstargname, \
CONV_BOOL(tv->vval.v_special == kSpecialVarTrue); \ CONV_BOOL(tv->vval.v_special == kSpecialVarTrue); \
break; \ break; \
} \ } \
case kSpecialVarNone: { \
CONV_NONE_VAL(); \
break; \
} \
} \ } \
break; \ break; \
} \ } \
@@ -726,9 +721,6 @@ encode_vim_to_##name##_error_ret: \
#define CONV_BOOL(num) \ #define CONV_BOOL(num) \
ga_concat(gap, ((num)? "v:true": "v:false")) ga_concat(gap, ((num)? "v:true": "v:false"))
#define CONV_NONE_VAL() \
ga_concat(gap, "v:none")
#define CONV_UNSIGNED_NUMBER(num) #define CONV_UNSIGNED_NUMBER(num)
#define CONV_DICT_START(len) \ #define CONV_DICT_START(len) \
@@ -1074,9 +1066,6 @@ static inline bool check_json_key(const typval_T *const tv)
} \ } \
} while (0) } while (0)
#undef CONV_NONE_VAL
#define CONV_NONE_VAL()
DEFINE_VIML_CONV_FUNCTIONS(static, json, garray_T *const, gap) DEFINE_VIML_CONV_FUNCTIONS(static, json, garray_T *const, gap)
#undef CONV_STRING #undef CONV_STRING
@@ -1090,7 +1079,6 @@ DEFINE_VIML_CONV_FUNCTIONS(static, json, garray_T *const, gap)
#undef CONV_EMPTY_DICT #undef CONV_EMPTY_DICT
#undef CONV_NIL #undef CONV_NIL
#undef CONV_BOOL #undef CONV_BOOL
#undef CONV_NONE_VAL
#undef CONV_UNSIGNED_NUMBER #undef CONV_UNSIGNED_NUMBER
#undef CONV_DICT_START #undef CONV_DICT_START
#undef CONV_DICT_END #undef CONV_DICT_END
@@ -1226,10 +1214,6 @@ char *encode_tv2json(typval_T *tv, size_t *len)
#define CONV_NIL() \ #define CONV_NIL() \
msgpack_pack_nil(packer) msgpack_pack_nil(packer)
#define CONV_NONE_VAL() \
return conv_error(_("E953: Attempt to convert v:none in %s, %s"), \
mpstack, objname)
#define CONV_BOOL(num) \ #define CONV_BOOL(num) \
do { \ do { \
if ((num)) { \ if ((num)) { \
@@ -1277,7 +1261,6 @@ DEFINE_VIML_CONV_FUNCTIONS(, msgpack, msgpack_packer *const, packer)
#undef CONV_EMPTY_DICT #undef CONV_EMPTY_DICT
#undef CONV_NIL #undef CONV_NIL
#undef CONV_BOOL #undef CONV_BOOL
#undef CONV_NONE_VAL
#undef CONV_UNSIGNED_NUMBER #undef CONV_UNSIGNED_NUMBER
#undef CONV_DICT_START #undef CONV_DICT_START
#undef CONV_DICT_END #undef CONV_DICT_END

View File

@@ -20,7 +20,6 @@ typedef struct dictvar_S dict_T;
typedef enum { typedef enum {
kSpecialVarFalse, ///< v:false kSpecialVarFalse, ///< v:false
kSpecialVarTrue, ///< v:true kSpecialVarTrue, ///< v:true
kSpecialVarNone, ///< v:none
kSpecialVarNull, ///< v:null kSpecialVarNull, ///< v:null
} SpecialVarValue; } SpecialVarValue;
@@ -40,7 +39,7 @@ typedef enum {
VAR_LIST, ///< List, .v_list is used. VAR_LIST, ///< List, .v_list is used.
VAR_DICT, ///< Dictionary, .v_dict is used. VAR_DICT, ///< Dictionary, .v_dict is used.
VAR_FLOAT, ///< Floating-point value, .v_float is used. VAR_FLOAT, ///< Floating-point value, .v_float is used.
VAR_SPECIAL, ///< Special value (true, false, null, none), .v_special VAR_SPECIAL, ///< Special value (true, false, null), .v_special
///< is used. ///< is used.
} VarType; } VarType;

View File

@@ -645,11 +645,6 @@ describe('msgpackdump() function', function()
exc_exec('call msgpackdump([todump])')) exc_exec('call msgpackdump([todump])'))
end) end)
it('fails to dump v:none', function()
eq('Vim(call):E953: Attempt to convert v:none in msgpackdump() argument, index 0, itself',
exc_exec('call msgpackdump([v:none])'))
end)
it('fails when called with no arguments', function() it('fails when called with no arguments', function()
eq('Vim(call):E119: Not enough arguments for function: msgpackdump', eq('Vim(call):E119: Not enough arguments for function: msgpackdump',
exc_exec('call msgpackdump()')) exc_exec('call msgpackdump()'))
@@ -686,7 +681,7 @@ describe('msgpackdump() function', function()
end) end)
it('fails to dump special value', function() it('fails to dump special value', function()
for _, val in ipairs({'v:true', 'v:false', 'v:null', 'v:none'}) do for _, val in ipairs({'v:true', 'v:false', 'v:null'}) do
eq('Vim(call):E686: Argument of msgpackdump() must be a List', eq('Vim(call):E686: Argument of msgpackdump() must be a List',
exc_exec('call msgpackdump(' .. val .. ')')) exc_exec('call msgpackdump(' .. val .. ')'))
end end

View File

@@ -28,21 +28,15 @@ describe('Special values', function()
eq(0, funcs.empty(true)) eq(0, funcs.empty(true))
eq(1, funcs.empty(false)) eq(1, funcs.empty(false))
eq(1, eval('empty(v:null)')) eq(1, eval('empty(v:null)'))
eq(1, eval('empty(v:none)'))
end) end)
it('can be stringified and evaled back', function() it('can be stringified and evaled back', function()
eq(true, funcs.eval(funcs.string(true))) eq(true, funcs.eval(funcs.string(true)))
eq(false, funcs.eval(funcs.string(false))) eq(false, funcs.eval(funcs.string(false)))
eq(nil, eval('eval(string(v:null))')) eq(nil, eval('eval(string(v:null))'))
eq(1, eval('eval(string(v:none)) is# v:none'))
end) end)
it('work with is/isnot properly', function() it('work with is/isnot properly', function()
eq(1, eval('v:none is v:none'))
eq(0, eval('v:none is v:null'))
eq(0, eval('v:none is v:true'))
eq(0, eval('v:none is v:false'))
eq(1, eval('v:null is v:null')) eq(1, eval('v:null is v:null'))
eq(0, eval('v:null is v:true')) eq(0, eval('v:null is v:true'))
eq(0, eval('v:null is v:false')) eq(0, eval('v:null is v:false'))
@@ -50,35 +44,26 @@ describe('Special values', function()
eq(0, eval('v:true is v:false')) eq(0, eval('v:true is v:false'))
eq(1, eval('v:false is v:false')) eq(1, eval('v:false is v:false'))
eq(0, eval('v:none is 0'))
eq(0, eval('v:null is 0')) eq(0, eval('v:null is 0'))
eq(0, eval('v:true is 0')) eq(0, eval('v:true is 0'))
eq(0, eval('v:false is 0')) eq(0, eval('v:false is 0'))
eq(0, eval('v:none is 1'))
eq(0, eval('v:null is 1')) eq(0, eval('v:null is 1'))
eq(0, eval('v:true is 1')) eq(0, eval('v:true is 1'))
eq(0, eval('v:false is 1')) eq(0, eval('v:false is 1'))
eq(0, eval('v:none is ""'))
eq(0, eval('v:null is ""')) eq(0, eval('v:null is ""'))
eq(0, eval('v:true is ""')) eq(0, eval('v:true is ""'))
eq(0, eval('v:false is ""')) eq(0, eval('v:false is ""'))
eq(0, eval('v:none is "none"'))
eq(0, eval('v:null is "null"')) eq(0, eval('v:null is "null"'))
eq(0, eval('v:true is "true"')) eq(0, eval('v:true is "true"'))
eq(0, eval('v:false is "false"')) eq(0, eval('v:false is "false"'))
eq(0, eval('v:none is []'))
eq(0, eval('v:null is []')) eq(0, eval('v:null is []'))
eq(0, eval('v:true is []')) eq(0, eval('v:true is []'))
eq(0, eval('v:false is []')) eq(0, eval('v:false is []'))
eq(0, eval('v:none isnot v:none'))
eq(1, eval('v:none isnot v:null'))
eq(1, eval('v:none isnot v:true'))
eq(1, eval('v:none isnot v:false'))
eq(0, eval('v:null isnot v:null')) eq(0, eval('v:null isnot v:null'))
eq(1, eval('v:null isnot v:true')) eq(1, eval('v:null isnot v:true'))
eq(1, eval('v:null isnot v:false')) eq(1, eval('v:null isnot v:false'))
@@ -86,27 +71,22 @@ describe('Special values', function()
eq(1, eval('v:true isnot v:false')) eq(1, eval('v:true isnot v:false'))
eq(0, eval('v:false isnot v:false')) eq(0, eval('v:false isnot v:false'))
eq(1, eval('v:none isnot 0'))
eq(1, eval('v:null isnot 0')) eq(1, eval('v:null isnot 0'))
eq(1, eval('v:true isnot 0')) eq(1, eval('v:true isnot 0'))
eq(1, eval('v:false isnot 0')) eq(1, eval('v:false isnot 0'))
eq(1, eval('v:none isnot 1'))
eq(1, eval('v:null isnot 1')) eq(1, eval('v:null isnot 1'))
eq(1, eval('v:true isnot 1')) eq(1, eval('v:true isnot 1'))
eq(1, eval('v:false isnot 1')) eq(1, eval('v:false isnot 1'))
eq(1, eval('v:none isnot ""'))
eq(1, eval('v:null isnot ""')) eq(1, eval('v:null isnot ""'))
eq(1, eval('v:true isnot ""')) eq(1, eval('v:true isnot ""'))
eq(1, eval('v:false isnot ""')) eq(1, eval('v:false isnot ""'))
eq(1, eval('v:none isnot "none"'))
eq(1, eval('v:null isnot "null"')) eq(1, eval('v:null isnot "null"'))
eq(1, eval('v:true isnot "true"')) eq(1, eval('v:true isnot "true"'))
eq(1, eval('v:false isnot "false"')) eq(1, eval('v:false isnot "false"'))
eq(1, eval('v:none isnot []'))
eq(1, eval('v:null isnot []')) eq(1, eval('v:null isnot []'))
eq(1, eval('v:true isnot []')) eq(1, eval('v:true isnot []'))
eq(1, eval('v:false isnot []')) eq(1, eval('v:false isnot []'))
@@ -114,17 +94,14 @@ describe('Special values', function()
it('work with +/-/* properly', function() it('work with +/-/* properly', function()
eq(1, eval('0 + v:true')) eq(1, eval('0 + v:true'))
eq(0, eval('0 + v:none'))
eq(0, eval('0 + v:null')) eq(0, eval('0 + v:null'))
eq(0, eval('0 + v:false')) eq(0, eval('0 + v:false'))
eq(-1, eval('0 - v:true')) eq(-1, eval('0 - v:true'))
eq( 0, eval('0 - v:none'))
eq( 0, eval('0 - v:null')) eq( 0, eval('0 - v:null'))
eq( 0, eval('0 - v:false')) eq( 0, eval('0 - v:false'))
eq(1, eval('1 * v:true')) eq(1, eval('1 * v:true'))
eq(0, eval('1 * v:none'))
eq(0, eval('1 * v:null')) eq(0, eval('1 * v:null'))
eq(0, eval('1 * v:false')) eq(0, eval('1 * v:false'))
end) end)
@@ -132,28 +109,23 @@ describe('Special values', function()
it('does not work with +=/-=/.=', function() it('does not work with +=/-=/.=', function()
meths.set_var('true', true) meths.set_var('true', true)
meths.set_var('false', false) meths.set_var('false', false)
execute('let none = v:none')
execute('let null = v:null') execute('let null = v:null')
eq('Vim(let):E734: Wrong variable type for +=', exc_exec('let true += 1')) eq('Vim(let):E734: Wrong variable type for +=', exc_exec('let true += 1'))
eq('Vim(let):E734: Wrong variable type for +=', exc_exec('let false += 1')) eq('Vim(let):E734: Wrong variable type for +=', exc_exec('let false += 1'))
eq('Vim(let):E734: Wrong variable type for +=', exc_exec('let none += 1'))
eq('Vim(let):E734: Wrong variable type for +=', exc_exec('let null += 1')) eq('Vim(let):E734: Wrong variable type for +=', exc_exec('let null += 1'))
eq('Vim(let):E734: Wrong variable type for -=', exc_exec('let true -= 1')) eq('Vim(let):E734: Wrong variable type for -=', exc_exec('let true -= 1'))
eq('Vim(let):E734: Wrong variable type for -=', exc_exec('let false -= 1')) eq('Vim(let):E734: Wrong variable type for -=', exc_exec('let false -= 1'))
eq('Vim(let):E734: Wrong variable type for -=', exc_exec('let none -= 1'))
eq('Vim(let):E734: Wrong variable type for -=', exc_exec('let null -= 1')) eq('Vim(let):E734: Wrong variable type for -=', exc_exec('let null -= 1'))
eq('Vim(let):E734: Wrong variable type for .=', exc_exec('let true .= 1')) eq('Vim(let):E734: Wrong variable type for .=', exc_exec('let true .= 1'))
eq('Vim(let):E734: Wrong variable type for .=', exc_exec('let false .= 1')) eq('Vim(let):E734: Wrong variable type for .=', exc_exec('let false .= 1'))
eq('Vim(let):E734: Wrong variable type for .=', exc_exec('let none .= 1'))
eq('Vim(let):E734: Wrong variable type for .=', exc_exec('let null .= 1')) eq('Vim(let):E734: Wrong variable type for .=', exc_exec('let null .= 1'))
end) end)
it('work with . (concat) properly', function() it('work with . (concat) properly', function()
eq("true", eval('"" . v:true')) eq("true", eval('"" . v:true'))
eq("none", eval('"" . v:none'))
eq("null", eval('"" . v:null')) eq("null", eval('"" . v:null'))
eq("false", eval('"" . v:false')) eq("false", eval('"" . v:false'))
end) end)
@@ -162,25 +134,21 @@ describe('Special values', function()
eq(6, funcs.type(true)) eq(6, funcs.type(true))
eq(6, funcs.type(false)) eq(6, funcs.type(false))
eq(7, eval('type(v:null)')) eq(7, eval('type(v:null)'))
eq(7, eval('type(v:none)'))
end) end)
it('work with copy() and deepcopy()', function() it('work with copy() and deepcopy()', function()
eq(true, funcs.deepcopy(true)) eq(true, funcs.deepcopy(true))
eq(false, funcs.deepcopy(false)) eq(false, funcs.deepcopy(false))
eq(nil, eval('deepcopy(v:null)')) eq(nil, eval('deepcopy(v:null)'))
eq(nil, eval('deepcopy(v:none)'))
eq(true, funcs.copy(true)) eq(true, funcs.copy(true))
eq(false, funcs.copy(false)) eq(false, funcs.copy(false))
eq(nil, eval('copy(v:null)')) eq(nil, eval('copy(v:null)'))
eq(nil, eval('copy(v:none)'))
end) end)
it('fails in index', function() it('fails in index', function()
eq('Vim(echo):E15: Cannot index a special value', exc_exec('echo v:true[0]')) eq('Vim(echo):E15: Cannot index a special value', exc_exec('echo v:true[0]'))
eq('Vim(echo):E15: Cannot index a special value', exc_exec('echo v:false[0]')) eq('Vim(echo):E15: Cannot index a special value', exc_exec('echo v:false[0]'))
eq('Vim(echo):E15: Cannot index a special value', exc_exec('echo v:none[0]'))
eq('Vim(echo):E15: Cannot index a special value', exc_exec('echo v:null[0]')) eq('Vim(echo):E15: Cannot index a special value', exc_exec('echo v:null[0]'))
end) end)
end) end)

View File

@@ -31,7 +31,6 @@ describe('string() function', function()
it('dumps special v: values', function() it('dumps special v: values', function()
eq('v:true', eval('string(v:true)')) eq('v:true', eval('string(v:true)'))
eq('v:false', eval('string(v:false)')) eq('v:false', eval('string(v:false)'))
eq('v:none', eval('string(v:none)'))
eq('v:null', eval('string(v:null)')) eq('v:null', eval('string(v:null)'))
end) end)