1 To: vim_dev@googlegroups.com
4 From: Bram Moolenaar <Bram@moolenaar.net>
6 Content-Type: text/plain; charset=UTF-8
7 Content-Transfer-Encoding: 8bit
11 Problem: No support for bitwise AND, OR, XOR and invert.
12 Solution: Add and(), or(), invert() and xor() functions.
13 Files: src/eval.c, src/testdir/test49.in, src/testdir/test65.in,
14 src/testdir/test65.ok, runtime/doc/eval.txt
17 *** ../vim-7.3.376/src/eval.c 2011-11-30 15:19:25.000000000 +0100
18 --- src/eval.c 2011-12-11 13:49:31.000000000 +0100
22 static void f_acos __ARGS((typval_T *argvars, typval_T *rettv));
24 static void f_add __ARGS((typval_T *argvars, typval_T *rettv));
25 + static void f_and __ARGS((typval_T *argvars, typval_T *rettv));
26 static void f_append __ARGS((typval_T *argvars, typval_T *rettv));
27 static void f_argc __ARGS((typval_T *argvars, typval_T *rettv));
28 static void f_argidx __ARGS((typval_T *argvars, typval_T *rettv));
32 static void f_inputsave __ARGS((typval_T *argvars, typval_T *rettv));
33 static void f_inputsecret __ARGS((typval_T *argvars, typval_T *rettv));
34 static void f_insert __ARGS((typval_T *argvars, typval_T *rettv));
35 + static void f_invert __ARGS((typval_T *argvars, typval_T *rettv));
36 static void f_isdirectory __ARGS((typval_T *argvars, typval_T *rettv));
37 static void f_islocked __ARGS((typval_T *argvars, typval_T *rettv));
38 static void f_items __ARGS((typval_T *argvars, typval_T *rettv));
43 static void f_nextnonblank __ARGS((typval_T *argvars, typval_T *rettv));
44 static void f_nr2char __ARGS((typval_T *argvars, typval_T *rettv));
45 + static void f_or __ARGS((typval_T *argvars, typval_T *rettv));
46 static void f_pathshorten __ARGS((typval_T *argvars, typval_T *rettv));
48 static void f_pow __ARGS((typval_T *argvars, typval_T *rettv));
52 static void f_winsaveview __ARGS((typval_T *argvars, typval_T *rettv));
53 static void f_winwidth __ARGS((typval_T *argvars, typval_T *rettv));
54 static void f_writefile __ARGS((typval_T *argvars, typval_T *rettv));
55 + static void f_xor __ARGS((typval_T *argvars, typval_T *rettv));
57 static int list2fpos __ARGS((typval_T *arg, pos_T *posp, int *fnump));
58 static pos_T *var2fpos __ARGS((typval_T *varp, int dollar_lnum, int *fnum));
62 {"acos", 1, 1, f_acos}, /* WJMc */
65 + {"and", 2, 2, f_and},
66 {"append", 2, 2, f_append},
67 {"argc", 0, 0, f_argc},
68 {"argidx", 0, 0, f_argidx},
72 {"inputsave", 0, 0, f_inputsave},
73 {"inputsecret", 1, 2, f_inputsecret},
74 {"insert", 2, 3, f_insert},
75 + {"invert", 1, 1, f_invert},
76 {"isdirectory", 1, 1, f_isdirectory},
77 {"islocked", 1, 1, f_islocked},
78 {"items", 1, 1, f_items},
83 {"nextnonblank", 1, 1, f_nextnonblank},
84 {"nr2char", 1, 1, f_nr2char},
86 {"pathshorten", 1, 1, f_pathshorten},
92 {"winsaveview", 0, 0, f_winsaveview},
93 {"winwidth", 1, 1, f_winwidth},
94 {"writefile", 2, 3, f_writefile},
95 + {"xor", 2, 2, f_xor},
98 #if defined(FEAT_CMDL_COMPL) || defined(PROTO)
105 + * "and(expr, expr)" function
108 + f_and(argvars, rettv)
112 + rettv->vval.v_number = get_tv_number_chk(&argvars[0], NULL)
113 + & get_tv_number_chk(&argvars[1], NULL);
117 * "append(lnum, string/list)" function
126 + * "invert(expr)" function
129 + f_invert(argvars, rettv)
133 + rettv->vval.v_number = ~get_tv_number_chk(&argvars[0], NULL);
137 * "isdirectory()" function
146 + * "or(expr, expr)" function
149 + f_or(argvars, rettv)
153 + rettv->vval.v_number = get_tv_number_chk(&argvars[0], NULL)
154 + | get_tv_number_chk(&argvars[1], NULL);
158 * "pathshorten()" function
167 + * "xor(expr, expr)" function
170 + f_xor(argvars, rettv)
174 + rettv->vval.v_number = get_tv_number_chk(&argvars[0], NULL)
175 + ^ get_tv_number_chk(&argvars[1], NULL);
180 * Translate a String variable into a position.
181 * Returns NULL when there is an error.
183 *** ../vim-7.3.376/src/testdir/test65.in 2010-08-15 21:57:29.000000000 +0200
184 --- src/testdir/test65.in 2011-12-11 13:55:06.000000000 +0100
187 ! Test for floating point.
192 ! Test for floating point and logical operators.
200 :$put =float2nr(123.456)
201 :$put =float2nr(-123.456)
203 + :$put =and(127, 127)
204 + :$put =and(127, 16)
205 + :$put =and(127, 128)
211 + :$put =xor(127, 127)
212 + :$put =xor(127, 16)
213 + :$put =xor(127, 128)
215 + :$put =and(invert(127), 65535)
216 + :$put =and(invert(16), 65535)
217 + :$put =and(invert(128), 65535)
219 :/^Results/,$wq! test.out
222 *** ../vim-7.3.376/src/testdir/test65.ok 2010-08-15 21:57:29.000000000 +0200
223 --- src/testdir/test65.ok 2011-12-11 13:55:30.000000000 +0100
247 *** ../vim-7.3.376/runtime/doc/eval.txt 2011-06-19 02:55:32.000000000 +0200
248 --- runtime/doc/eval.txt 2011-12-14 15:28:23.000000000 +0100
251 For |Lists| only "+" is possible and then both expr6 must be a list. The
252 result is a new list with the two lists Concatenated.
254 ! expr7 * expr7 .. number multiplication *expr-star*
255 ! expr7 / expr7 .. number division *expr-/*
256 ! expr7 % expr7 .. number modulo *expr-%*
258 For all, except ".", Strings are converted to Numbers.
260 Note the difference between "+" and ".":
263 For |Lists| only "+" is possible and then both expr6 must be a list. The
264 result is a new list with the two lists Concatenated.
266 ! expr7 * expr7 .. Number multiplication *expr-star*
267 ! expr7 / expr7 .. Number division *expr-/*
268 ! expr7 % expr7 .. Number modulo *expr-%*
270 For all, except ".", Strings are converted to Numbers.
271 + For bitwise operators see |and()|, |or()| and |xor()|.
273 Note the difference between "+" and ".":
278 abs( {expr}) Float or Number absolute value of {expr}
279 acos( {expr}) Float arc cosine of {expr}
280 add( {list}, {item}) List append {item} to |List| {list}
281 + and( {expr}, {expr}) Number bitwise AND
282 append( {lnum}, {string}) Number append {string} below line {lnum}
283 append( {lnum}, {list}) Number append lines {list} below line {lnum}
284 argc() Number number of files in the argument list
288 inputsave() Number save and clear typeahead
289 inputsecret( {prompt} [, {text}]) String like input() but hiding the text
290 insert( {list}, {item} [, {idx}]) List insert {item} in {list} [before {idx}]
291 + invert( {expr}) Number bitwise invert
292 isdirectory( {directory}) Number TRUE if {directory} is a directory
293 islocked( {expr}) Number TRUE if {expr} is locked
294 items( {dict}) List key-value pairs in {dict}
298 mzeval( {expr}) any evaluate |MzScheme| expression
299 nextnonblank( {lnum}) Number line nr of non-blank line >= {lnum}
300 nr2char( {expr}) String single char with ASCII value {expr}
301 + or( {expr}, {expr}) Number bitwise OR
302 pathshorten( {expr}) String shorten directory names in a path
303 pow( {x}, {y}) Float {x} to the power of {y}
304 prevnonblank( {lnum}) Number line nr of non-blank line <= {lnum}
308 winwidth( {nr}) Number width of window {nr}
309 writefile( {list}, {fname} [, {binary}])
310 Number write list of lines to file {fname}
311 + xor( {expr}, {expr}) Number bitwise XOR
314 Return the absolute value of {expr}. When {expr} evaluates to
318 Use |insert()| to add an item at another position.
321 + and({expr}, {expr}) *and()*
322 + Bitwise AND on the two arguments. The arguments are converted
323 + to a number. A List, Dict or Float argument causes an error.
325 + :let flag = and(bits, 0x80)
328 append({lnum}, {expr}) *append()*
329 When {expr} is a |List|: Append each item of the |List| as a
330 text line below line {lnum} in the current buffer.
334 Note that when {item} is a |List| it is inserted as a single
335 item. Use |extend()| to concatenate |Lists|.
337 + invert({expr}) *invert()*
338 + Bitwise invert. The argument is converted to a number. A
339 + List, Dict or Float argument causes an error. Example: >
340 + :let bits = invert(bits)
342 isdirectory({directory}) *isdirectory()*
343 The result is a Number, which is non-zero when a directory
344 with the name {directory} exists. If {directory} doesn't
348 call setpos('.', save_cursor)
349 < Also see |setpos()|.
351 + or({expr}, {expr}) *or()*
352 + Bitwise OR on the two arguments. The arguments are converted
353 + to a number. A List, Dict or Float argument causes an error.
355 + :let bits = or(bits, 0x80)
358 pathshorten({expr}) *pathshorten()*
359 Shorten directory names in the path {expr} and return the
360 result. The tail, the file name, is kept as-is. The other
363 To copy a file byte for byte: >
364 :let fl = readfile("foo", "b")
365 :call writefile(fl, "foocopy", "b")
369 There are three types of features:
371 To copy a file byte for byte: >
372 :let fl = readfile("foo", "b")
373 :call writefile(fl, "foocopy", "b")
376 ! xor({expr}, {expr}) *xor()*
377 ! Bitwise XOR on the two arguments. The arguments are converted
378 ! to a number. A List, Dict or Float argument causes an error.
380 ! :let bits = xor(bits, 0x80)
385 There are three types of features:
386 *** ../vim-7.3.376/src/version.c 2011-12-14 15:23:53.000000000 +0100
387 --- src/version.c 2011-12-14 15:28:39.000000000 +0100
391 { /* Add new patch number below this line */
397 DINGO: Wicked wicked Zoot ... she is a bad person and she must pay the
398 penalty. And here in Castle Anthrax, we have but one punishment
399 ... you must tie her down on a bed ... and spank her. Come!
400 GIRLS: A spanking! A spanking!
401 "Monty Python and the Holy Grail" PYTHON (MONTY) PICTURES LTD
403 /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net \\\
404 /// sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
405 \\\ an exciting new programming language -- http://www.Zimbu.org ///
406 \\\ help me help AIDS victims -- http://ICCF-Holland.org ///