summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKaz Kylheku <kaz@kylheku.com>2017-08-16 06:54:33 -0700
committerKaz Kylheku <kaz@kylheku.com>2017-08-16 06:54:33 -0700
commitad7a6f7bc7b58097fb6c456709c9a9b1aee0487b (patch)
tree3ae642dc2162703404efceb85d4ac3e7c1fd88bd
parentdcbe8df9d096be6b8352c0a09225814be34865c7 (diff)
downloadtxr-ad7a6f7bc7b58097fb6c456709c9a9b1aee0487b.tar.gz
txr-ad7a6f7bc7b58097fb6c456709c9a9b1aee0487b.tar.bz2
txr-ad7a6f7bc7b58097fb6c456709c9a9b1aee0487b.zip
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.
-rw-r--r--arith.c28
-rw-r--r--txr.116
2 files changed, 43 insertions, 1 deletions
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 .