From ad7a6f7bc7b58097fb6c456709c9a9b1aee0487b Mon Sep 17 00:00:00 2001 From: Kaz Kylheku Date: Wed, 16 Aug 2017 06:54:33 -0700 Subject: Allow character inputs in some bit operations. * arith.c (logand, logior, logxor): Allow one operand to be a character, if the opposite opernad is a fixnum integer. The result is a character. (bit): Allow the value being tested to be a character. * txr.1: Updated. --- arith.c | 28 ++++++++++++++++++++++++++++ txr.1 | 16 +++++++++++++++- 2 files changed, 43 insertions(+), 1 deletion(-) diff --git a/arith.c b/arith.c index 7700ea07..abf9f1be 100644 --- a/arith.c +++ b/arith.c @@ -2241,6 +2241,15 @@ val logand(val a, val b) return zero; switch (TYPE_PAIR(type(a), type(b))) { + case TYPE_PAIR(NUM, CHR): + case TYPE_PAIR(CHR, NUM): + if (a == b) { + return a; + } else { + cnum ac = c_num(a); + cnum bc = c_num(b); + return chr(ac & bc); + } case TYPE_PAIR(NUM, NUM): if (a == b) { return a; @@ -2282,6 +2291,15 @@ val logior(val a, val b) return zero; switch (TYPE_PAIR(type(a), type(b))) { + case TYPE_PAIR(NUM, CHR): + case TYPE_PAIR(CHR, NUM): + if (a == b) { + return a; + } else { + cnum ac = c_num(a); + cnum bc = c_num(b); + return chr(ac | bc); + } case TYPE_PAIR(NUM, NUM): if (a == b) { return a; @@ -2323,6 +2341,15 @@ val logxor(val a, val b) return zero; switch (TYPE_PAIR(type(a), type(b))) { + case TYPE_PAIR(NUM, CHR): + case TYPE_PAIR(CHR, NUM): + if (a == b) { + return a; + } else { + cnum ac = c_num(a); + cnum bc = c_num(b); + return chr(ac ^ bc); + } case TYPE_PAIR(NUM, NUM): if (a == b) { return a; @@ -2593,6 +2620,7 @@ val bit(val a, val bit) switch (type(a)) { case NUM: + case CHR: { cnum an = c_num(a); if (bn < (SIZEOF_PTR * CHAR_BIT)) diff --git a/txr.1 b/txr.1 index 29195b97..a36c0f27 100644 --- a/txr.1 +++ b/txr.1 @@ -34865,6 +34865,20 @@ the value -1 (all bits 1). If is called with no arguments it produces zero. In the one-argument case, the functions just return their argument value. +In the two-argument case, one of the operands may be a character, if the other +operand is a fixnum integer. The character operand is taken to be an integer +corresponding to the character value's Unicode code point value. The resulting +value is regarded as a Unicode code point and converted to a character value +accordingly. + +When three or more arguments are specified, the operation's semantics is +that of a left-associative reduction through two-argument invocations, +so that the three-argument case +.code "(logand a b c)" +is equivalent to the expression +.codn "(logand (logand a b) c)" , +which features two two-argument cases.. + .coNP Function @ logtest .synb .mets (logtest < int1 << int2 ) @@ -35008,7 +35022,7 @@ and .desc The .code bit -function tests whether the integer +function tests whether the integer or character .meta value has a 1 in bit position .metn bit . -- cgit v1.2.3