Created
February 6, 2012 10:00
-
-
Save mattn/1751166 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| diff -r 9140571d01ab runtime/doc/eval.txt | |
| --- a/runtime/doc/eval.txt Mon Feb 06 00:13:22 2012 +0100 | |
| +++ b/runtime/doc/eval.txt Mon Feb 06 19:00:34 2012 +0900 | |
| @@ -1688,7 +1688,7 @@ | |
| abs( {expr}) Float or Number absolute value of {expr} | |
| acos( {expr}) Float arc cosine of {expr} | |
| add( {list}, {item}) List append {item} to |List| {list} | |
| -and( {expr}, {expr}) Number bitwise AND | |
| +and( {expr}[, {expr}]) Number bitwise AND | |
| append( {lnum}, {string}) Number append {string} below line {lnum} | |
| append( {lnum}, {list}) Number append lines {list} below line {lnum} | |
| argc() Number number of files in the argument list | |
| @@ -1868,7 +1868,7 @@ | |
| mzeval( {expr}) any evaluate |MzScheme| expression | |
| nextnonblank( {lnum}) Number line nr of non-blank line >= {lnum} | |
| nr2char( {expr}) String single char with ASCII value {expr} | |
| -or( {expr}, {expr}) Number bitwise OR | |
| +or( {expr}[, {expr}]) Number bitwise OR | |
| pathshorten( {expr}) String shorten directory names in a path | |
| pow( {x}, {y}) Float {x} to the power of {y} | |
| prevnonblank( {lnum}) Number line nr of non-blank line <= {lnum} | |
| @@ -1992,7 +1992,7 @@ | |
| winwidth( {nr}) Number width of window {nr} | |
| writefile( {list}, {fname} [, {binary}]) | |
| Number write list of lines to file {fname} | |
| -xor( {expr}, {expr}) Number bitwise XOR | |
| +xor( {expr}[, {expr}]) Number bitwise XOR | |
| abs({expr}) *abs()* | |
| Return the absolute value of {expr}. When {expr} evaluates to | |
| @@ -2035,8 +2035,10 @@ | |
| and({expr}, {expr}) *and()* | |
| Bitwise AND on the two arguments. The arguments are converted | |
| to a number. A List, Dict or Float argument causes an error. | |
| + It is allowed to pass List to first {expr}. | |
| Example: > | |
| :let flag = and(bits, 0x80) | |
| + :let flag = and([bits, 0x80, 0x40]) | |
| append({lnum}, {expr}) *append()* | |
| @@ -4372,8 +4374,10 @@ | |
| or({expr}, {expr}) *or()* | |
| Bitwise OR on the two arguments. The arguments are converted | |
| to a number. A List, Dict or Float argument causes an error. | |
| + It is allowed to pass List to first {expr}. | |
| Example: > | |
| :let bits = or(bits, 0x80) | |
| + :let bits = or([bits, 0x80, 0x81]) | |
| pathshorten({expr}) *pathshorten()* | |
| @@ -6154,11 +6158,13 @@ | |
| :call writefile(fl, "foocopy", "b") | |
| -xor({expr}, {expr}) *xor()* | |
| +xor({expr}[, {expr}]) *xor()* | |
| Bitwise XOR on the two arguments. The arguments are converted | |
| to a number. A List, Dict or Float argument causes an error. | |
| + It is allowed to pass List to first {expr}. | |
| Example: > | |
| :let bits = xor(bits, 0x80) | |
| + :let bits = xor([bits, 0x80, 0x20]) | |
| < | |
| diff -r 9140571d01ab src/eval.c | |
| --- a/src/eval.c Mon Feb 06 00:13:22 2012 +0100 | |
| +++ b/src/eval.c Mon Feb 06 19:00:34 2012 +0900 | |
| @@ -7792,7 +7792,7 @@ | |
| {"acos", 1, 1, f_acos}, /* WJMc */ | |
| #endif | |
| {"add", 2, 2, f_add}, | |
| - {"and", 2, 2, f_and}, | |
| + {"and", 1, 2, f_and}, | |
| {"append", 2, 2, f_append}, | |
| {"argc", 0, 0, f_argc}, | |
| {"argidx", 0, 0, f_argidx}, | |
| @@ -7967,7 +7967,7 @@ | |
| #endif | |
| {"nextnonblank", 1, 1, f_nextnonblank}, | |
| {"nr2char", 1, 1, f_nr2char}, | |
| - {"or", 2, 2, f_or}, | |
| + {"or", 1, 2, f_or}, | |
| {"pathshorten", 1, 1, f_pathshorten}, | |
| #ifdef FEAT_FLOAT | |
| {"pow", 2, 2, f_pow}, | |
| @@ -8079,7 +8079,7 @@ | |
| {"winsaveview", 0, 0, f_winsaveview}, | |
| {"winwidth", 1, 1, f_winwidth}, | |
| {"writefile", 2, 3, f_writefile}, | |
| - {"xor", 2, 2, f_xor}, | |
| + {"xor", 1, 2, f_xor}, | |
| }; | |
| #if defined(FEAT_CMDL_COMPL) || defined(PROTO) | |
| @@ -8654,14 +8654,36 @@ | |
| /* | |
| * "and(expr, expr)" function | |
| + * "and([expr, expr])" function | |
| */ | |
| static void | |
| f_and(argvars, rettv) | |
| typval_T *argvars; | |
| typval_T *rettv; | |
| { | |
| - rettv->vval.v_number = get_tv_number_chk(&argvars[0], NULL) | |
| - & get_tv_number_chk(&argvars[1], NULL); | |
| + if (argvars[0].v_type == VAR_LIST && argvars[1].v_type == VAR_UNKNOWN) | |
| + { | |
| + listitem_T *li = argvars[0].vval.v_list->lv_first; | |
| + if (li) | |
| + { | |
| + rettv->vval.v_number = get_tv_number_chk(&li->li_tv, NULL); | |
| + li = li->li_next; | |
| + while (li) | |
| + { | |
| + rettv->vval.v_number &= get_tv_number_chk(&li->li_tv, NULL); | |
| + li = li->li_next; | |
| + } | |
| + } | |
| + else | |
| + rettv->vval.v_number = 0; | |
| + } | |
| + else if (argvars[1].v_type != VAR_UNKNOWN) | |
| + { | |
| + rettv->vval.v_number = get_tv_number_chk(&argvars[0], NULL) | |
| + & get_tv_number_chk(&argvars[1], NULL); | |
| + } | |
| + else | |
| + EMSG(_(e_invarg)); | |
| } | |
| /* | |
| @@ -14200,7 +14222,6 @@ | |
| typval_T *rettv; | |
| { | |
| char_u buf[NUMBUFLEN]; | |
| - | |
| #ifdef FEAT_MBYTE | |
| if (has_mbyte) | |
| buf[(*mb_char2bytes)((int)get_tv_number(&argvars[0]), buf)] = NUL; | |
| @@ -14222,8 +14243,29 @@ | |
| typval_T *argvars; | |
| typval_T *rettv; | |
| { | |
| - rettv->vval.v_number = get_tv_number_chk(&argvars[0], NULL) | |
| - | get_tv_number_chk(&argvars[1], NULL); | |
| + if (argvars[0].v_type == VAR_LIST && argvars[1].v_type == VAR_UNKNOWN) | |
| + { | |
| + listitem_T *li = argvars[0].vval.v_list->lv_first; | |
| + if (li) | |
| + { | |
| + rettv->vval.v_number = get_tv_number_chk(&li->li_tv, NULL); | |
| + li = li->li_next; | |
| + while (li) | |
| + { | |
| + rettv->vval.v_number |= get_tv_number_chk(&li->li_tv, NULL); | |
| + li = li->li_next; | |
| + } | |
| + } | |
| + else | |
| + rettv->vval.v_number = 0; | |
| + } | |
| + else if (argvars[1].v_type != VAR_UNKNOWN) | |
| + { | |
| + rettv->vval.v_number = get_tv_number_chk(&argvars[0], NULL) | |
| + | get_tv_number_chk(&argvars[1], NULL); | |
| + } | |
| + else | |
| + EMSG(_(e_invarg)); | |
| } | |
| /* | |
| @@ -18558,14 +18600,36 @@ | |
| /* | |
| * "xor(expr, expr)" function | |
| + * "xor([expr, expr])" function | |
| */ | |
| static void | |
| f_xor(argvars, rettv) | |
| typval_T *argvars; | |
| typval_T *rettv; | |
| { | |
| - rettv->vval.v_number = get_tv_number_chk(&argvars[0], NULL) | |
| - ^ get_tv_number_chk(&argvars[1], NULL); | |
| + if (argvars[0].v_type == VAR_LIST && argvars[1].v_type == VAR_UNKNOWN) | |
| + { | |
| + listitem_T *li = argvars[0].vval.v_list->lv_first; | |
| + if (li) | |
| + { | |
| + rettv->vval.v_number = get_tv_number_chk(&li->li_tv, NULL); | |
| + li = li->li_next; | |
| + while (li) | |
| + { | |
| + rettv->vval.v_number ^= get_tv_number_chk(&li->li_tv, NULL); | |
| + li = li->li_next; | |
| + } | |
| + } | |
| + else | |
| + rettv->vval.v_number = 0; | |
| + } | |
| + else if (argvars[1].v_type != VAR_UNKNOWN) | |
| + { | |
| + rettv->vval.v_number = get_tv_number_chk(&argvars[0], NULL) | |
| + ^ get_tv_number_chk(&argvars[1], NULL); | |
| + } | |
| + else | |
| + EMSG(_(e_invarg)); | |
| } | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment