Module Name: othersrc
Committed By: agc
Date: Thu Sep 1 05:07:13 UTC 2011
Modified Files:
othersrc/external/historical/eawk/dist: awkgram.y lex.c proctab.c
proto.h run.c
othersrc/external/historical/eawk/eawk: Makefile expected
Log Message:
add bit arithmetic operations to eawk (implementation based on the gawk
man page). this provides:
and(x, y) (in C, x & y)
or(x, y) (in C, x | y)
xor(x, y) (in C, x ^ y)
lshift(x, n) (in C, x << n)
rshift(x, n) (in C, x >> n)
compl(x) (in C, ~x)
operations, with exactly the same calling conventions as gawk.
To generate a diff of this commit:
cvs rdiff -u -r1.1.1.1 -r1.2 othersrc/external/historical/eawk/dist/awkgram.y \
othersrc/external/historical/eawk/dist/lex.c \
othersrc/external/historical/eawk/dist/proctab.c \
othersrc/external/historical/eawk/dist/proto.h
cvs rdiff -u -r1.2 -r1.3 othersrc/external/historical/eawk/dist/run.c
cvs rdiff -u -r1.1.1.1 -r1.2 othersrc/external/historical/eawk/eawk/Makefile \
othersrc/external/historical/eawk/eawk/expected
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
Modified files:
Index: othersrc/external/historical/eawk/dist/awkgram.y
diff -u othersrc/external/historical/eawk/dist/awkgram.y:1.1.1.1 othersrc/external/historical/eawk/dist/awkgram.y:1.2
--- othersrc/external/historical/eawk/dist/awkgram.y:1.1.1.1 Wed Aug 31 04:19:39 2011
+++ othersrc/external/historical/eawk/dist/awkgram.y Thu Sep 1 05:07:12 2011
@@ -96,6 +96,8 @@
%right POWER
%right DECR INCR
%left INDIRECT
+%token <i> BITCOMPL BITLSHIFT BITRSHIFT BITAND BITOR BITXOR
+%type <i> bitop
%token LASTTOKEN /* must be last */
%%
@@ -354,6 +356,9 @@
SUB | GSUB
;
+bitop:
+ BITLSHIFT | BITRSHIFT | BITAND | BITOR | BITXOR
+ ;
term:
term '/' ASGNOP term { $$ = eawk_op2(eawk, DIVEQ, $1, $4); }
| term '+' term { $$ = eawk_op2(eawk, ADD, $1, $3); }
@@ -446,6 +451,10 @@
{ $$ = eawk_op3(eawk, SUBSTR, $3, $5, $7); }
| SUBSTR '(' pattern comma pattern ')'
{ $$ = eawk_op3(eawk, SUBSTR, $3, $5, NIL); }
+ | BITCOMPL '(' pattern ')'
+ { $$ = eawk_op1(eawk, BITCOMPL, $3); }
+ | bitop '(' pattern comma pattern ')'
+ { $$ = eawk_op2(eawk, $1, $3, (awknode_t*)$5); }
| var
;
Index: othersrc/external/historical/eawk/dist/lex.c
diff -u othersrc/external/historical/eawk/dist/lex.c:1.1.1.1 othersrc/external/historical/eawk/dist/lex.c:1.2
--- othersrc/external/historical/eawk/dist/lex.c:1.1.1.1 Wed Aug 31 04:19:40 2011
+++ othersrc/external/historical/eawk/dist/lex.c Thu Sep 1 05:07:12 2011
@@ -45,9 +45,11 @@
{ "BEGIN", XBEGIN, XBEGIN },
{ "END", XEND, XEND },
{ "NF", VARNF, VARNF },
+ { "and", BITAND, BITAND },
{ "atan2", FATAN, BLTIN },
{ "break", BREAK, BREAK },
{ "close", CLOSE, CLOSE },
+ { "compl", BITCOMPL, BITCOMPL },
{ "continue", CONTINUE, CONTINUE },
{ "cos", FCOS, BLTIN },
{ "delete", DELETE, DELETE },
@@ -75,13 +77,16 @@
{ "int", FINT, BLTIN },
{ "length", FLENGTH, BLTIN },
{ "log", FLOG, BLTIN },
+ { "lshift", BITLSHIFT, BITLSHIFT },
{ "match", MATCHFCN, MATCHFCN },
{ "next", NEXT, NEXT },
{ "nextfile", NEXTFILE, NEXTFILE },
+ { "or", BITOR, BITOR },
{ "print", PRINT, PRINT },
{ "printf", PRINTF, PRINTF },
{ "rand", FRAND, BLTIN },
{ "return", RETURN, RETURN },
+ { "rshift", BITRSHIFT, BITRSHIFT },
{ "sin", FSIN, BLTIN },
{ "split", SPLIT, SPLIT },
{ "sprintf", SPRINTF, SPRINTF },
@@ -95,6 +100,7 @@
{ "tolower", FTOLOWER, BLTIN },
{ "toupper", FTOUPPER, BLTIN },
{ "while", WHILE, WHILE },
+ { "xor", BITXOR, BITXOR }
};
#define RET(eawk, x) \
Index: othersrc/external/historical/eawk/dist/proctab.c
diff -u othersrc/external/historical/eawk/dist/proctab.c:1.1.1.1 othersrc/external/historical/eawk/dist/proctab.c:1.2
--- othersrc/external/historical/eawk/dist/proctab.c:1.1.1.1 Wed Aug 31 04:19:40 2011
+++ othersrc/external/historical/eawk/dist/proctab.c Thu Sep 1 05:07:12 2011
@@ -4,7 +4,7 @@
#include "awkgram.h"
#include "proto.h"
-static const char * const printname[101] = {
+static const char * const printname[107] = {
"FIRSTTOKEN", /* 258 */
"PROGRAM", /* 259 */
"PASTAT", /* 260 */
@@ -105,11 +105,17 @@
"DECR", /* 355 */
"INCR", /* 356 */
"INDIRECT", /* 357 */
- "LASTTOKEN", /* 358 */
+ "BITCOMPL", /* 358 */
+ "BITLSHIFT", /* 359 */
+ "BITRSHIFT", /* 360 */
+ "BITAND", /* 361 */
+ "BITOR", /* 362 */
+ "BITXOR", /* 363 */
+ "LASTTOKEN", /* 364 */
};
-awkcell_t *(*eawk_proctab[101])(eawk_t *, awknode_t **, int) = {
+awkcell_t *(*eawk_proctab[107])(eawk_t *, awknode_t **, int) = {
eawk_nullproc, /* FIRSTTOKEN */
eawk_program, /* PROGRAM */
eawk_pastat, /* PASTAT */
@@ -210,6 +216,12 @@
eawk_nullproc, /* DECR */
eawk_nullproc, /* INCR */
eawk_indirect, /* INDIRECT */
+ eawk_bitarith, /* BITCOMPL */
+ eawk_bitarith, /* BITLSHIFT */
+ eawk_bitarith, /* BITRSHIFT */
+ eawk_bitarith, /* BITAND */
+ eawk_bitarith, /* BITOR */
+ eawk_bitarith, /* BITXOR */
eawk_nullproc, /* LASTTOKEN */
};
Index: othersrc/external/historical/eawk/dist/proto.h
diff -u othersrc/external/historical/eawk/dist/proto.h:1.1.1.1 othersrc/external/historical/eawk/dist/proto.h:1.2
--- othersrc/external/historical/eawk/dist/proto.h:1.1.1.1 Wed Aug 31 04:19:40 2011
+++ othersrc/external/historical/eawk/dist/proto.h Thu Sep 1 05:07:12 2011
@@ -92,7 +92,7 @@
#define REC 0200 /* this is $0 */
-/* function types */
+/* BLTIN function types */
#define FLENGTH 1
#define FSQRT 2
#define FEXP 3
@@ -210,6 +210,7 @@
awkcell_t *eawk_sprintf(eawk_t *, awknode_t **, int);
awkcell_t *eawk_printf(eawk_t *, awknode_t **, int);
awkcell_t *eawk_arith(eawk_t *, awknode_t **, int);
+awkcell_t *eawk_bitarith(eawk_t *, awknode_t **, int);
awknum_t eawk_ipow(awknum_t, int);
awkcell_t *eawk_incrdecr(eawk_t *, awknode_t **, int);
awkcell_t *eawk_assign(eawk_t *, awknode_t **, int);
Index: othersrc/external/historical/eawk/dist/run.c
diff -u othersrc/external/historical/eawk/dist/run.c:1.2 othersrc/external/historical/eawk/dist/run.c:1.3
--- othersrc/external/historical/eawk/dist/run.c:1.2 Thu Sep 1 05:03:18 2011
+++ othersrc/external/historical/eawk/dist/run.c Thu Sep 1 05:07:12 2011
@@ -1084,7 +1084,7 @@
eawk_warning(eawk, "format item %.30s... ran format() out of memory", os);
return 0;
}
- if (*s == 'l' || *s == 'h' || *s == 'L')
+ if (*s == 'l' || *s == 'h' || *s == 'L' || *s == 'q')
goto weird;
if (isalpha((uint8_t)*s))
break; /* the ansi panoply */
@@ -1350,6 +1350,50 @@
return x * v * v;
}
+/* bitwise operations */
+awkcell_t *
+eawk_bitarith(eawk_t *eawk, awknode_t **a, int op)
+{
+ awkcell_t *x, *y, *res;
+ uint32_t i;
+ uint32_t j = 0;
+
+ x = eawk_execute(eawk, a[0]);
+ i = (uint32_t)eawk_getfval(eawk, x);
+ TEMPFREE(eawk, x);
+ if (op != BITCOMPL) {
+ y = eawk_execute(eawk, a[1]);
+ j = (uint32_t)eawk_getfval(eawk, y);
+ TEMPFREE(eawk, y);
+ }
+ res = eawk_gettemp(eawk);
+ switch (op) {
+ case BITAND:
+ i &= j;
+ break;
+ case BITOR:
+ i |= j;
+ break;
+ case BITXOR:
+ i ^= j;
+ break;
+ case BITCOMPL:
+ i = ~i;
+ break;
+ case BITLSHIFT:
+ i <<= j;
+ break;
+ case BITRSHIFT:
+ i >>= j;
+ break;
+ default:
+ (void) fprintf(stderr, "bitarith: not reached\n");
+ break;
+ }
+ eawk_setfval(eawk, res, (awknum_t)i);
+ return res;
+}
+
/* a[0]++, etc. */
awkcell_t *
eawk_incrdecr(eawk_t *eawk, awknode_t **a, int n)
Index: othersrc/external/historical/eawk/eawk/Makefile
diff -u othersrc/external/historical/eawk/eawk/Makefile:1.1.1.1 othersrc/external/historical/eawk/eawk/Makefile:1.2
--- othersrc/external/historical/eawk/eawk/Makefile:1.1.1.1 Wed Aug 31 04:19:41 2011
+++ othersrc/external/historical/eawk/eawk/Makefile Thu Sep 1 05:07:12 2011
@@ -1,4 +1,4 @@
-# $NetBSD: Makefile,v 1.1.1.1 2011/08/31 04:19:41 agc Exp $
+# $NetBSD: Makefile,v 1.2 2011/09/01 05:07:12 agc Exp $
.include <bsd.own.mk>
@@ -56,4 +56,6 @@
@echo "16. eawk and SHA256"
@(env LD_LIBRARY_PATH=${LIBEAWKDIR} ./${PROG} 'BEGIN { f = "../Makefile"; dlopen(libc, "libc"); buf = dlalloc(65); dlcall(libc, "cptr SHA256_File(awkptr, cptr)", f, buf); dlcall(libc, "int printf(awkptr, awkptr, cptr)", "SHA256 (%s) = %s\n", f, buf) }')
@digest sha256 ../Makefile
+ @echo "17. eawk using bit arithmetic"
+ @(cd ${.CURDIR}/../dist && env LD_LIBRARY_PATH=${LIBEAWKDIR} ./bit1.sh ${LIBEAWKDIR}/../eawk/${PROG})
@echo "All tests complete"
Index: othersrc/external/historical/eawk/eawk/expected
diff -u othersrc/external/historical/eawk/eawk/expected:1.1.1.1 othersrc/external/historical/eawk/eawk/expected:1.2
--- othersrc/external/historical/eawk/eawk/expected:1.1.1.1 Wed Aug 31 04:19:41 2011
+++ othersrc/external/historical/eawk/eawk/expected Thu Sep 1 05:07:12 2011
@@ -1022,4 +1022,13 @@
16. eawk and SHA256
SHA256 (../Makefile) = a6ccb2e57801867720b434d8dfc248d62389c518457ea1a022861819151f2b1f
SHA256 (../Makefile) = a6ccb2e57801867720b434d8dfc248d62389c518457ea1a022861819151f2b1f
+17. eawk using bit arithmetic
+x 0xff, compl ffffff00
+x 0xff, y 0x3fc
+x 0xff, y 0x3fc, z 0xff
+a 0x62, b 0x9d
+c & b = 10001 & 9d = 1
+c | b = 10001 | 9d = 1009d
+c & b = dfb & 9d = 99
+c | b = dfb | 9d = dff
All tests complete