From: Eric S. Raymond Date: Wed, 5 Jun 1996 21:10:00 +0000 (-0400) Subject: INTERCAL 0.13 release. X-Git-Tag: 0.13 X-Git-Url: http://thyrsus.com/gitweb/?a=commitdiff_plain;h=91a59ace4b4e7df1b6b85def8b871727aaa5bf4e;p=intercal.git INTERCAL 0.13 release. (This is a retrospective comment.) --- diff --git a/BUGS b/BUGS index 2dcbc58..0b30c20 100644 --- a/BUGS +++ b/BUGS @@ -2,7 +2,7 @@ There are still some known bugs in INTERCAL (and no doubt many we don't even suspect as yet). The following list accumulates current bug reports and -TO DO agenda items from the major INTERCAL hackers through version 0.10. +TO DO agenda items from the major INTERCAL hackers through version 0.13. ESR = Eric S. Raymond SS = Steve Swales @@ -43,12 +43,6 @@ LLH = Louis Howell relatively small gain, and anyone trying it should make sure the result isn't buggier than the current version. -5) (ESR) We can't use flex to generate the lexical analyzer. The - frustrating thing is that it *almost* works; only some sources - (including icat.i, pi.i and both life programs) fail. Looking - at the parsing trace suggests that flex is returning something to - yacc/bison that does not cause it to terminate as it should. - TO DO 1. (ESR) Add more optimization templates, esp. the idioms for &, |, ^, ~. diff --git a/Makefile b/Makefile index dc40bcb..6407c18 100644 --- a/Makefile +++ b/Makefile @@ -2,7 +2,7 @@ # Utility productions for the INTERCAL distribution # ick.tar: - (cd ..; tar cvf ick.tar `cat intercal-0.12/MANIFEST`) + (cd ..; tar cvf ick.tar `cat intercal-0.13/MANIFEST`) mv ../ick.tar . ick.tar.Z: ick.tar @@ -13,4 +13,4 @@ ick.tar.gz: ick.tar SHAROPTS = -l63 -n intercal -o intercal -a -s esr@snark.thyrsus.com ick.shar: - (cd ..; shar $(SHAROPTS) `cat intercal-0.12/MANIFEST` >ick.shar) + (cd ..; shar $(SHAROPTS) `cat intercal-0.13/MANIFEST` >ick.shar) diff --git a/NEWS b/NEWS index ef6784a..b2bb211 100644 --- a/NEWS +++ b/NEWS @@ -1,5 +1,11 @@ NEW IN THIS RELEASE + Release 0.13 (by Eric S. Raymond) + +1. I folded in patches by Brian Raiter that port + this code to Linux and enable it to use flex. Note: This version has + been tested on Linux and SunOS but not yet elsewhere. + Release 0.12 (by Eric S. Raymond) 1. The code now compiles and runs under Linux, using bison and lex. It does diff --git a/READ.ME b/READ.ME index 4e5d479..56bb26f 100644 --- a/READ.ME +++ b/READ.ME @@ -1,5 +1,5 @@ Release Notes for C-INTERCAL - version 0.12 + version 0.13 DISCREDITS @@ -11,7 +11,8 @@ This implementation was created by Eric S. Raymond during a fit of lunacy from which he has since mostly recovered. It has been considerably hacked upon and improved by Steve Swales, Michael Ernst, Louis Howell (who wrote the array support stubbed out in Eric's original -version), and others. +version), and others. Brian Raiter ported it to Linux and enabled it to use +flex. You can surf to the latest version of this package, and related resources, from http://www.ccil.org/~esr/home.html. @@ -63,7 +64,7 @@ program `foo.i' to executable code, just do There's a -c option that leaves the generated `foo.c' in place for inspection (suppressing compilation to machine code), a -d option that enables verbose -parse reporting from the YACC parser, a -t option that requires strict +parse reporting from the yacc/bison parser, a -t option that requires strict INTERCAL-72 compliance (rejecting COME FROM and the extensions for bases other than two) and an -O option that enables the (hah!) optimizer. Invoking ick -? prints a usage message. Other than that, yer on yer own. @@ -73,11 +74,10 @@ option forces output in "clockface" mode, for superstitious users who believe writing "IV" upside-down offends IVPITER and would rather see IIII. -Steve Swales added [+/-]help, [+/-]traditional, and [+/-]wimpmode options in -the 0.6 release. The help option (with either + or -) triggers a 'usage' -message. - -The +traditional option is presently a no-op. +Every INTERCAL runtime also accepts certain options at runtime (code by +Steve Swales). These include [+/-]help, [+/-]traditional, and [+/-]wimpmode. +The help option (with either + or -) triggers a 'usage' message. The ++traditional option is presently a no-op. Steve writes: "The wimpmode option is the most interesting. I found myself always running my test programs with filters on both ends to work around the @@ -93,9 +93,32 @@ use it... the default is -wimpmode (i.e. NOT wimp mode)." SPREADING THE BLAME The latest version of INTERCAL is kept available at the Retrocomputing Museun, -ftp:locke.ccil.org:pub/retro. +http://www.ccil.org/retro. There is, in addition, an occasionally active USENET newsgroup devoted to the language: alt.lang.intercal. + NOTES ON THE LINUX BUILD + +At the top of ick.h are two defines that you may need to remove if you +are using lex instead of flex. + +Many lexes export a yylineno variable, an undocumented feature that is +not in flex (by default). If your build fails because of redecleration +of yylineno, comment out the define of YYLINENO_BY_HAND. + +Some lexes also supply a yyrestart function to begin parsing a second +file, while others automatically restart after seeing an EOF. (This is +the case with flex.) If your build fails at link time because +yyrestart is not defined, comment out the define of USE_YYRESTART. + +If you are using gcc in an non-ANSI environment, such as SunOS, it is +strongly recommended that you add "-Wno-unused -Wimplicit" to the gcc +command in the makefile. If you are in an ANSI environment and are +using the current versions of gcc, flex, and bison, C-INTERCAL should +build with no warnings. + + + + diff --git a/pit/Makefile b/pit/Makefile index 8509236..ddbe1a3 100644 --- a/pit/Makefile +++ b/pit/Makefile @@ -51,7 +51,7 @@ TARGETS = \ ./sink test: - testcompile $(SOURCES) + for x in $(SOURCES); do echo "Test-compiling $$x"; ../src/ick $$x; done lines: wc -l $(SOURCES) diff --git a/pit/testcompile b/pit/testcompile deleted file mode 100755 index 5dd5a08..0000000 --- a/pit/testcompile +++ /dev/null @@ -1,8 +0,0 @@ -# -# testcompile -- testcompile all named sources using ick: -# -for x in $* -do - echo "Test-compiling $x"; - ../src/ick $x; -done diff --git a/src/Makefile b/src/Makefile index 50a3e1e..81f6365 100644 --- a/src/Makefile +++ b/src/Makefile @@ -8,7 +8,7 @@ # all over creation behind your back. # (/dev/null may be another good choice :-)) -DVMT=/home/esr/export/intercal-0.12 +DVMT=/home2/esr/WWW/intercal-0.13 BINDIR = $(DVMT)/bin INCDIR = $(DVMT)/lib @@ -16,9 +16,6 @@ LIBDIR = $(DVMT)/lib #INCDIR = $(PWD) #LIBDIR = $(PWD) -# To cope with BSD's losing linker, comment the next line out -NR = @echo "Real UNIXes don't need " - YDEBUG = -vlt DEBUG = -g -DDEBUG # DEBUG = -O @@ -27,16 +24,16 @@ CFLAGS = -I. $(DEBUG) -DICKINCLUDEDIR=\"$(INCDIR)\" \ LDFLAGS = # Warning: using flex does not work yet! -LEX = lex -#LEX = flex -l +#LEX = lex +LEX = flex # However, you can use either yacc or bison -YACC = yacc -#YACC = bison -y +#YACC = yacc +YACC = bison -y CSOURCES = ick.y lexer.l feh.c lose.c fiddle.c perpetrate.c ISOURCES = cesspool.c arrgghh.c ick-wrap.c -HEADERS = ick.h lose.h sizes.h +HEADERS = ick.h lose.h sizes.h abcess.h fiddle.h feh.h SOURCES = $(CSOURCES) $(ISOURCES) $(HEADERS) all: ick libick.a @@ -48,7 +45,7 @@ y.tab.h ick.c: ick.y $(YACC) -d $(YDEBUG) ick.y mv y.tab.c ick.c -lexer.c: lexer.l +lexer.c: lexer.l ick.h $(LEX) $(LFLAGS) lexer.l mv lex.yy.c lexer.c @@ -57,27 +54,26 @@ lexer.c: lexer.l lextest: y.tab.h lexer.c ick.h lose.o $(CC) -DMAIN lexer.c lose.o $(LEXLIBS) -o lextest -ick.o: ick.c ick.h lose.h sizes.h -lexer.o: lexer.c y.tab.h ick.h -feh.o: feh.c y.tab.h ick.h lose.h sizes.h -perpetrate.o: perpetrate.c y.tab.h ick.h lose.h -cesspool.o: cesspool.c numerals.c cesspool.h lose.h sizes.h +ick.o: ick.c ick.h feh.h lose.h sizes.h +lexer.o: lexer.c y.tab.h ick.h lose.h +feh.o: feh.c feh.h y.tab.h ick.h fiddle.h lose.h sizes.h +perpetrate.o: perpetrate.c y.tab.h ick.h lose.h sizes.h +cesspool.o: cesspool.c numerals.c abcess.h lose.h sizes.h lose.o: lose.h -fiddle.o: sizes.h +fiddle.o: fiddle.h sizes.h libick.a: cesspool.o lose.o fiddle.o arrgghh.o ar cr libick.a cesspool.o lose.o fiddle.o arrgghh.o - $(NR) ranlib libick.a + -ranlib libick.a install: all cp ick $(BINDIR) - cp lose.h cesspool.h ick-wrap.c $(INCDIR) + cp lose.h abcess.h fiddle.h ick-wrap.c $(INCDIR) cp libick.a ../pit/lib/syslib.i $(LIBDIR) - $(NR) ranlib $(LIBDIR)/libick.a + -ranlib $(LIBDIR)/libick.a clean: rm -f yacc.* y.tab.* y.output *~ *.[oa] lexer.c ick.c lextest ick TAGS: $(SOURCES) etags $(SOURCES) - diff --git a/src/abcess.h b/src/abcess.h new file mode 100644 index 0000000..8b1984b --- /dev/null +++ b/src/abcess.h @@ -0,0 +1,49 @@ +/* abcess.h -- functions used by compiled INTERCAL programs */ + +typedef int bool; +#define TRUE 1 +#define FALSE 0 + +#define ONESPOT 0 +#define TWOSPOT 1 +#define TAIL 2 +#define HYBRID 3 + +/* the following two types must both promote to unsigned int in expressions */ + +typedef unsigned short type16; +typedef unsigned int type32; + +typedef struct array_t +{ + unsigned int rank; + unsigned int *dims; + union + { + type16 *tail; + type32 *hybrid; + } data; +} array; + +/* defined in cesspool.c */ +extern void pushnext(int n); +extern unsigned int popnext(int n); +extern unsigned int resume(unsigned int n); +extern unsigned int pin(void); +extern void clockface(bool mode); +extern void pout(unsigned int val); +extern void binin(unsigned int type, array *a, bool forget); +extern void binout(unsigned int type, array *a); +extern unsigned int assign(char *dest, unsigned int type, bool forget, + unsigned int value); +extern char *aref(); +extern void resize(); +extern void stashinit(void); +extern void stash(unsigned int type, unsigned int index, void *from); +extern void retrieve(void *to, int type, unsigned int index, bool forget); +extern unsigned int roll(unsigned int n); + +/* defined in arrgghh.c */ +extern void parseargs(int argc, char **argv); + +/* abcess.h ends here */ diff --git a/src/arrgghh.c b/src/arrgghh.c index 4124f59..12ce6e4 100644 --- a/src/arrgghh.c +++ b/src/arrgghh.c @@ -6,15 +6,16 @@ * PURPOSE: Parse arguments for INTERCAL programs. */ #include +#include +#include +#include "abcess.h" #include "lose.h" -int traditional = 1; +int traditional = 0; int wimp_mode = 0; void -parseargs(argc,argv) -int argc; -char **argv; +parseargs(int argc, char **argv) { register int i, j; static int helpflag = -1; @@ -28,7 +29,7 @@ char **argv; &wimp_mode, &traditional }; - static nflags = (sizeof(flags)/sizeof(flags[0])); + static int nflags = (int)(sizeof(flags)/sizeof(flags[0])); for(i = 1;i < argc;i++) { if(argv[i][0] != '+' && argv[i][0] != '-') { diff --git a/src/cesspool.c b/src/cesspool.c index 9ac6f45..2e9e2f1 100644 --- a/src/cesspool.c +++ b/src/cesspool.c @@ -1,9 +1,10 @@ /* cesspool.c -- storage management and runtime support for INTERCAL */ /* LINTLIBRARY */ #include +#include #include #include "sizes.h" -#include "cesspool.h" +#include "abcess.h" #include "lose.h" #include "numerals.c" @@ -19,8 +20,7 @@ int next[MAXNEXT]; int nextindex = 0; -void pushnext(n) -int n; +void pushnext(int n) { if (nextindex < MAXNEXT) next[nextindex++] = n; @@ -28,26 +28,29 @@ int n; lose(E123, lineno, (char *)NULL); } -unsigned int popnext(n) -int n; +unsigned int popnext(int n) { nextindex -= n; if (nextindex < 0) { nextindex = 0; - return(-1); + return (unsigned int)-1; } return(next[nextindex]); } -unsigned int resume(n) -unsigned int n; +unsigned int resume(unsigned int n) { if (n == 0) + { lose(E621, lineno, (char *)NULL); - else if ((n = popnext(n)) == -1) + return 0; + } + else if ((n = popnext(n)) == (unsigned int)-1) + { lose(E632, lineno, (char *)NULL); - else - return(n); + return 0; + } + return(n); } /********************************************************************** @@ -56,7 +59,7 @@ unsigned int n; * *********************************************************************/ -unsigned int pin() +unsigned int pin(void) { char buf[BUFSIZ], *cp, *strtok(); unsigned int result = 0; @@ -88,7 +91,7 @@ unsigned int pin() if (digit == -1) lose(E579, lineno, cp); - if (result < 429496729 || result == 429496729 && digit < 6) + if (result < 429496729 || (result == 429496729 && digit < 6)) result = result * 10 + digit; else lose(E533, lineno, (char *)NULL); @@ -96,7 +99,7 @@ unsigned int pin() } if (!n) lose(E562, lineno, (char *)NULL); - if (result > Max_large) + if (result > (unsigned int)Max_large) lose(E533, lineno, (char *)NULL); return(result); } @@ -142,9 +145,7 @@ static int br_trans[10][5] = * 11/24/91 LHH: Removed unnecessary final newline. */ -static void butcher(val, result) -unsigned long val; -char *result; +static void butcher(unsigned long val, char *result) { int i, j; int digitsig, digitval; @@ -199,12 +200,12 @@ char *result; } j = i; - while (*result++ = ovb[j++]) + while ((*result++ = ovb[j++])) continue; *--result = '\n'; j = i; - while (*++result = res[j++]) + while ((*++result = res[j++])) continue; /* Final newline will be added by puts. *result++ = '\n'; @@ -213,9 +214,8 @@ char *result; } } -void clockface(mode) +void clockface(bool mode) /* enable or disable clockface mode (output IIII instead of IV) */ -bool mode; { if (mode) { @@ -233,15 +233,14 @@ bool mode; } } -void pout(val) +void pout(unsigned int val) /* output in `butchered' Roman numerals; see manual, part 4.4.13 */ -unsigned int val; { char result[2*MAXROMANS+1]; extern int wimp_mode; if(wimp_mode) { - printf("%d\n",val); + printf("%u\n",val); } else { butcher(val, result); @@ -258,13 +257,11 @@ unsigned int val; * *********************************************************************/ -void binin(type,a,forget) -unsigned int type; -array *a; -bool forget; +void binin(unsigned int type, array *a, bool forget) { - static unsigned lastin = 0; - int i, c, v; + static unsigned int lastin = 0; + int c, v; + unsigned int i; if (a->rank != 1) lose(E241, lineno, (char *)NULL); @@ -281,13 +278,10 @@ bool forget; } } -void binout(type,a) -unsigned int type; -array *a; +void binout(unsigned int type, array *a) { - static unsigned lastout = 0; - unsigned c; - int i; + static unsigned int lastout = 0; + unsigned int i, c; if (a->rank != 1) lose(E241, lineno, (char *)NULL); @@ -311,14 +305,12 @@ array *a; * *********************************************************************/ -unsigned int assign(dest,type,forget,value) -char *dest; -unsigned int type, value; -bool forget; +unsigned int assign(char *dest, unsigned int type, bool forget, + unsigned int value) { unsigned int retval; if (type == ONESPOT || type == TAIL) { - if (value > Max_small) + if (value > (unsigned int)Max_small) lose(E275, lineno, (char *)NULL); if (forget) retval = value; @@ -351,7 +343,8 @@ char *aref(va_alist) va_dcl array *a; unsigned int v; va_list ap; - int i, address = 0; + int address = 0; + unsigned int i; va_start(ap); type = va_arg(ap, unsigned int); @@ -381,9 +374,9 @@ void resize(va_alist) va_dcl unsigned int type; array *a; bool forget; - unsigned int r, v; + unsigned int i, r, v; va_list ap; - int i, prod = 1; + int prod = 1; va_start(ap); type = va_arg(ap, unsigned int); @@ -438,8 +431,8 @@ void resize(va_alist) va_dcl typedef struct stashbox_t /* this is a save-stack element */ { - int type; /* variable type */ - int index; /* variable's index within the type */ + unsigned int type; /* variable type */ + unsigned int index; /* variable's index within the type */ union /* the data itself */ { type16 onespot; @@ -451,14 +444,13 @@ typedef struct stashbox_t /* this is a save-stack element */ static stashbox *first; -void stashinit() +void stashinit(void) { first = NULL; } -static stashbox *fetch(type, index) +static stashbox *fetch(unsigned int type, unsigned int index) /* find a stashed variable in the save stack and extract it */ -unsigned int type, index; { stashbox **pp = &first, *sp = first; @@ -472,10 +464,8 @@ unsigned int type, index; return (sp); } -void stash(type, index, from) +void stash(unsigned int type, unsigned int index, void *from) /* stash away the variable's value */ -char *from; -unsigned int type, index; { /* create a new stashbox and push it onto the stack */ stashbox *sp = (stashbox*)malloc(sizeof(stashbox)); @@ -490,9 +480,10 @@ unsigned int type, index; memcpy((char *)&sp->save.onespot, from, sizeof(type16)); else if (type == TWOSPOT) memcpy((char *)&sp->save.twospot, from, sizeof(type32)); - else if (type == TAIL | type == HYBRID) { + else if (type == TAIL || type == HYBRID) { array *a = (array*)from; - int i, prod; + int prod; + unsigned int i; sp->save.a = (array*)malloc(sizeof(array)); if (sp->save.a == NULL) lose(E222, lineno, (char *)NULL); sp->save.a->rank = a->rank; @@ -522,11 +513,8 @@ unsigned int type, index; return; } -void retrieve(to, type, index, forget) +void retrieve(void *to, int type, unsigned int index, bool forget) /* restore the value of a variable from the save stack */ -char *to; -unsigned int type, index; -bool forget; { stashbox *sp; @@ -537,7 +525,7 @@ bool forget; memcpy(to, (char *)&sp->save.onespot, sizeof(type16)); else if (type == TWOSPOT) memcpy(to, (char *)&sp->save.twospot, sizeof(type32)); - else if (type == TAIL | type == HYBRID) { + else if (type == TAIL || type == HYBRID) { array *a = (array*)to; if (a->rank) { free(a->dims); @@ -550,7 +538,7 @@ bool forget; free(sp->save.a); } } - else if (type == TAIL | type == HYBRID) { + else if (type == TAIL || type == HYBRID) { free(sp->save.a->dims); if (type == TAIL) free(sp->save.a->data.tail); @@ -567,14 +555,13 @@ bool forget; * *********************************************************************/ -unsigned int roll(n) +unsigned int roll(unsigned int n) /* return TRUE on n% chance, FALSE otherwise */ -unsigned int n; { #ifdef USG - return(lrand48() % 100 < n); + return((unsigned int)(lrand48() % 100) < n); #else - return(rand() % 100 < n); + return((unsigned int)(rand() % 100) < n); #endif /* UNIX */ } diff --git a/src/cesspool.h b/src/cesspool.h deleted file mode 100644 index 652b83a..0000000 --- a/src/cesspool.h +++ /dev/null @@ -1,46 +0,0 @@ -/* cesspool.h -- interface to INTERCAL storage manager and runtime support */ - -#include - -typedef int bool; -#define TRUE 1 -#define FALSE 0 - -extern char *aref(); -extern unsigned int aget(), pin(), roll(), popnext(), resume(), assign(); -extern void pushnext(), resize(), stashinit(), stash(), retrieve(), aput(); -extern void clockface(), pout(); - -extern int lineno; - -#define ONESPOT 0 -#define TWOSPOT 1 -#define TAIL 2 -#define HYBRID 3 - -/* the following two types must both promote to unsigned int in expressions */ - -typedef unsigned short type16; -typedef unsigned int type32; - -typedef struct array_t -{ - int rank; - unsigned int *dims; - union - { - type16 *tail; - type32 *hybrid; - } data; -} array; - -typedef struct -{ - char *name; - int value; -} -numeral; - -extern numeral numerals[]; - -/* cesspool.h ends here */ diff --git a/src/feh.c b/src/feh.c index 806f53b..9b298a7 100644 --- a/src/feh.c +++ b/src/feh.c @@ -10,15 +10,14 @@ and optimizations of dubious value for the INTERCAL compiler. ****************************************************************************/ /*LINTLIBRARY */ #include +#include +#include #include "sizes.h" #include "ick.h" #include "y.tab.h" +#include "fiddle.h" #include "lose.h" - -int yyerror() -{ - /* lose(E017, yylineno, (char *)NULL); */ -} +#include "feh.h" /************************************************************************* * @@ -29,15 +28,13 @@ int yyerror() * **************************************************************************/ -node *newnode() +node *newnode(void) /* allocate and zero out a new expression node */ { return((node *)calloc(sizeof(node), 1)); } -node *cons(type, car, cdr) -int type; -node *car, *cdr; +node *cons(int type, node *car, node *cdr) { node *np = newnode(); @@ -56,7 +53,7 @@ node *car, *cdr; * **************************************************************************/ -unsigned int intern(type, index) +unsigned int intern(int type, int index) { atom *x; @@ -89,7 +86,7 @@ unsigned int intern(type, index) * **************************************************************************/ -void treset() +void treset(void) { memset(tuples, '\0', sizeof(tuple) * MAXLINES); nonespots = ntwospots = ntails = nhybrids = 0; @@ -97,11 +94,14 @@ void treset() lineno = 0; } -tuple *newtuple() +tuple *newtuple(void) /* allocate and zero out a new expression tuple */ { if (lineno >= MAXLINES) + { lose(E666, yylineno, (char *)NULL); + return NULL; + } else return(tuples + lineno++); } @@ -115,8 +115,7 @@ tuple *newtuple() * **************************************************************************/ -void typecast(np) -node *np; +void typecast(node *np) { /* recurse so we typecast each node after all its subnodes */ if (np == (node *)NULL) @@ -155,7 +154,7 @@ node *np; * **************************************************************************/ -void codecheck() +void codecheck(void) { tuple *tp, *up; @@ -228,9 +227,8 @@ void codecheck() #define ISCONSTANT(np, v) ((np->opcode == MESH || np->opcode == MESH32) && np->constant == v) -void rfree(np) +static void rfree(node *np) /* recursively free the given node and all nodes underneath */ -node *np; { if (np->lval != (node *)NULL) rfree(np->lval); @@ -239,9 +237,8 @@ node *np; free(np); } -int requal(mp, np) +static int requal(node *mp, node *np) /* do two node trees represent the same expression? */ -node *mp, *np; { if (mp == (node *)NULL && np == (node *)NULL) return(TRUE); @@ -255,8 +252,7 @@ node *mp, *np; return(TRUE); } -void optimize(np) -node *np; +void optimize(node *np) { /* recurse so we simplify each node after all its subnodes */ if (np == (node *)NULL) @@ -310,7 +306,7 @@ node *np; if (np->opcode == AND && np->rval->opcode == MESH) { np->opcode = MESH; - np->constant = and16(np->lval->constant, np->rval->constant); + np->constant = and16(np->lval->constant); free(np->rval); } @@ -318,7 +314,7 @@ node *np; if (np->opcode == OR && np->rval->opcode == MESH) { np->opcode = MESH; - np->constant = or16(np->lval->constant, np->rval->constant); + np->constant = or16(np->lval->constant); free(np->rval); } @@ -326,7 +322,7 @@ node *np; if (np->opcode == XOR && np->rval->opcode == MESH) { np->opcode = MESH; - np->constant = xor16(np->lval->constant, np->rval->constant); + np->constant = xor16(np->lval->constant); free(np->rval); } } @@ -372,44 +368,42 @@ char *enablers[MAXTYPES] = assoc vartypes[] = { - ONESPOT, "ONESPOT", - TWOSPOT, "TWOSPOT", - TAIL, "TAIL", - HYBRID, "HYBRID", - 0, (char *)NULL + { ONESPOT, "ONESPOT" }, + { TWOSPOT, "TWOSPOT" }, + { TAIL, "TAIL" }, + { HYBRID, "HYBRID" }, + { 0, (char *)NULL } }; -assoc forgetbits[] = +static assoc forgetbits[] = { - ONESPOT, "oneforget", - TWOSPOT, "twoforget", - TAIL, "tailforget", - HYBRID, "hyforget", - 0, (char *)NULL + { ONESPOT, "oneforget" }, + { TWOSPOT, "twoforget" }, + { TAIL, "tailforget" }, + { HYBRID, "hyforget" }, + { 0, (char *)NULL } }; -assoc varstores[] = +static assoc varstores[] = { - ONESPOT, "onespots", - TWOSPOT, "twospots", - TAIL, "tails", - HYBRID, "hybrids", - 0, (char *)NULL + { ONESPOT, "onespots" }, + { TWOSPOT, "twospots" }, + { TAIL, "tails" }, + { HYBRID, "hybrids" }, + { 0, (char *)NULL } }; -assoc typedefs[] = +static assoc typedefs[] = { - ONESPOT, "type16", - TWOSPOT, "type32", - TAIL, "type16", - HYBRID, "type32", - 0, (char *)NULL + { ONESPOT, "type16" }, + { TWOSPOT, "type32" }, + { TAIL, "type16" }, + { HYBRID, "type32" }, + { 0, (char *)NULL } }; -char *nameof(value, table) +char *nameof(int value, assoc table[]) /* return string corresponding to value in table */ -int value; -assoc table[]; { assoc *ap; @@ -419,10 +413,10 @@ assoc table[]; return((char *)NULL); } -void prvar(np, fp) +static void prexpr(node *np, FILE *fp); + +static void prvar(node *np, FILE *fp) /* print out args to pass to storage manager for reference */ -node *np; -FILE *fp; { node *sp; int dim; @@ -430,26 +424,23 @@ FILE *fp; switch (np->opcode) { case ONESPOT: - (void) fprintf(fp, "onespots[%d]", np->constant); + (void) fprintf(fp, "onespots[%lu]", np->constant); break; case TWOSPOT: - (void) fprintf(fp, "twospots[%d]", np->constant); + (void) fprintf(fp, "twospots[%lu]", np->constant); break; case TAIL: - (void) fprintf(fp, "TAIL, &tails[%d]", np->constant); + (void) fprintf(fp, "TAIL, &tails[%lu]", np->constant); break; case HYBRID: - (void) fprintf(fp, "HYBRID, &hybrids[%d]", np->constant); + (void) fprintf(fp, "HYBRID, &hybrids[%lu]", np->constant); break; case SUB: { - void prexpr(); - node *sp; - (void) fprintf(fp, "aref("); prvar(np->lval, fp); @@ -468,10 +459,8 @@ FILE *fp; } } -void prexpr(np, fp) +static void prexpr(node *np, FILE *fp) /* print out C-function equivalent of an expression */ -FILE *fp; -node *np; { switch (np->opcode) { @@ -538,7 +527,7 @@ node *np; break; case MESH: - (void) fprintf(fp, "0x%x", np->constant); + (void) fprintf(fp, "0x%lx", np->constant); break; case MESH32: @@ -566,8 +555,7 @@ node *np; (void) free(np); } -char *nice_text(text) -char *text; +static char *nice_text(char *text) { #define MAXNICEBUF 512 static char buf[MAXNICEBUF]; @@ -583,14 +571,11 @@ char *text; return buf; } -void emit(tn, fp) +void emit(tuple *tn, FILE *fp) /* emit code for the given tuple */ -tuple *tn; -FILE *fp; { node *np, *sp; int dim; - char *name; static int make_cf_target = 0; if (yydebug || compile_only) @@ -633,7 +618,7 @@ FILE *fp; } prvar(np->lval, fp); (void) fprintf(fp,", %s", nameof(sp->opcode, vartypes)); - (void) fprintf(fp,", %s[%d], ", nameof(sp->opcode, forgetbits), + (void) fprintf(fp,", %s[%lu], ", nameof(sp->opcode, forgetbits), sp->constant); prexpr(np->rval, fp); (void) fprintf(fp,");\n"); @@ -646,7 +631,7 @@ FILE *fp; dim++; (void) fprintf(fp, "\tresize("); prvar(np->lval, fp); - (void) fprintf(fp, ", %s[%d]", nameof(np->lval->opcode, forgetbits), + (void) fprintf(fp, ", %s[%lu]", nameof(np->lval->opcode, forgetbits), np->lval->constant); (void) fprintf(fp, ", %d", dim); for (sp = np->rval; sp; sp = sp->rval) { @@ -676,7 +661,7 @@ FILE *fp; case STASH: for (np = tn->u.node; np; np = np->rval) - (void) fprintf(fp, "\tstash(%s, %d, %s+%d);\n", + (void) fprintf(fp, "\tstash(%s, %lu, %s+%lu);\n", nameof(np->opcode, vartypes), np->constant, nameof(np->opcode, varstores), np->constant); @@ -684,7 +669,7 @@ FILE *fp; case RETRIEVE: for (np = tn->u.node; np; np = np->rval) - (void) fprintf(fp, "\tretrieve(%s+%d, %s, %d, %s[%d]);\n", + (void) fprintf(fp, "\tretrieve(%s+%lu, %s, %lu, %s[%lu]);\n", nameof(np->opcode, varstores), np->constant, nameof(np->opcode, vartypes), np->constant, @@ -694,14 +679,14 @@ FILE *fp; case IGNORE: for (np = tn->u.node; np; np = np->rval) - (void) fprintf(fp,"\t%s[%d] = TRUE;\n", + (void) fprintf(fp,"\t%s[%lu] = TRUE;\n", nameof(np->opcode, forgetbits), np->constant); break; case REMEMBER: for (np = tn->u.node; np; np = np->rval) - (void) fprintf(fp,"\t%s[%d] = FALSE;\n", + (void) fprintf(fp,"\t%s[%lu] = FALSE;\n", nameof(np->opcode, forgetbits), np->constant); break; @@ -718,7 +703,7 @@ FILE *fp; for (np = tn->u.node; np; np = np->rval) { (void) fprintf(fp, - "\tint i;\n\n\tfor (i = 0; i < sizeof(linetype)/sizeof(int); i++)\n"); + "\tint i;\n\n\tfor (i = 0; i < (int)(sizeof(linetype)/sizeof(int)); i++)\n"); (void) fprintf(fp, "\t if (linetype[i] == %s)\n", enablers[np->constant-GETS]); (void) fprintf(fp, @@ -730,7 +715,7 @@ FILE *fp; for (np = tn->u.node; np; np = np->rval) { (void) fprintf(fp, - "\tint i;\n\n\tfor (i = 0; i < sizeof(linetype)/sizeof(int); i++)\n"); + "\tint i;\n\n\tfor (i = 0; i < (int)(sizeof(linetype)/sizeof(int)); i++)\n"); (void) fprintf(fp, "\t if (linetype[i] == %s)\n", enablers[np->constant-GETS]); (void) fprintf(fp, @@ -747,7 +732,7 @@ FILE *fp; if (np->lval->opcode == TAIL || np->lval->opcode == HYBRID) { (void) fprintf(fp,"\tbinin("); prvar(np->lval, fp); - (void) fprintf(fp, ", %s[%d]", + (void) fprintf(fp, ", %s[%lu]", nameof(np->lval->opcode, forgetbits), np->lval->constant); (void) fprintf(fp,");\n"); @@ -763,7 +748,7 @@ FILE *fp; } prvar(np->lval, fp); (void) fprintf(fp,", %s", nameof(sp->opcode, vartypes)); - (void) fprintf(fp,", %s[%d]", nameof(sp->opcode, forgetbits), + (void) fprintf(fp,", %s[%lu]", nameof(sp->opcode, forgetbits), sp->constant); (void) fprintf(fp,", pin());\n"); } @@ -795,7 +780,7 @@ FILE *fp; fprintf(stderr,"compiling a splat... line = %d (%s)\n", tn->lineno,textlines[tn->lineno]); */ - (void) fprintf(fp,"\t(void) puts(\"%s\");\n", + (void) fprintf(fp,"\t(void) puts(\"*%s\");\n", nice_text(textlines[tn->lineno])); (void) fprintf(fp, "\texit(%d);\n", tn->lineno); diff --git a/src/feh.h b/src/feh.h new file mode 100644 index 0000000..586a01f --- /dev/null +++ b/src/feh.h @@ -0,0 +1,17 @@ +/* feh.h -- compilation functions used by perpetrate.c and ick.y */ + +extern node *newnode(void); +extern node *cons(int type, node *car, node *cdr); +extern unsigned int intern(int type, int index); +extern void treset(void); +extern tuple *newtuple(void); +extern void typecast(node *np); +extern void codecheck(void); +extern void optimize(node *np); +extern char *nameof(int value, assoc table[]); +extern void emit(tuple *tn, FILE *fp); + +extern char *enablers[MAXTYPES]; +extern assoc vartypes[]; + +/* feh.h ends here */ diff --git a/src/fiddle.c b/src/fiddle.c index 5f83d7f..faf111f 100644 --- a/src/fiddle.c +++ b/src/fiddle.c @@ -4,10 +4,10 @@ * We link these to the compiler, too, in order to do constant folding */ +#include "fiddle.h" #include "sizes.h" -unsigned int mingle(r, s) -register unsigned int r, s; +unsigned int mingle(register unsigned int r, register unsigned int s) { if (Base == 2) { r = ((r & 0x0000ff00) << 8) | (r & 0x000000ff); @@ -21,7 +21,8 @@ register unsigned int r, s; return (r << 1) | s; } else { - unsigned int i, result = 0, fac = 1; + unsigned int result = 0, fac = 1; + int i; for (i = 0 ; i < Small_digits ; i++) { result += fac * (s % Base); s /= Base; @@ -34,8 +35,7 @@ register unsigned int r, s; } } -unsigned int iselect(r, s) -register unsigned int r, s; +unsigned int iselect(register unsigned int r, register unsigned int s) { if (Base == 2) { register unsigned int i = 1, t = 0; @@ -53,8 +53,9 @@ register unsigned int r, s; return(t); } else { - unsigned int i, j, result = 0, fac, digit, ofac = 1; + unsigned int j, result = 0, fac, digit, ofac = 1; for (j = Base - 1 ; j > 0 ; j--) { + int i; fac = 1; for (i = 0; i < Large_digits ; i++) { if ((s / fac) % Base == j) { @@ -70,8 +71,7 @@ register unsigned int r, s; } } -unsigned int whirl(len,p,n) -unsigned int len,p,n; +static unsigned int whirl(unsigned int len, unsigned int p, unsigned int n) { unsigned int i, fac = 1, result = 0, d1, d2, dsave; d1 = n % Base; @@ -88,8 +88,7 @@ unsigned int len,p,n; return result; } -unsigned int and16(n) -unsigned int n; +unsigned int and16(unsigned int n) { if (Base == 2) { unsigned int m = (n >> 1); @@ -102,8 +101,7 @@ unsigned int n; } } -unsigned int or16(n) -unsigned int n; +unsigned int or16(unsigned int n) { if (Base == 2) { unsigned int m = (n >> 1); @@ -116,14 +114,12 @@ unsigned int n; } } -unsigned int whirl16(p,n) -unsigned int p,n; +unsigned int whirl16(unsigned int p, unsigned int n) { return whirl(Small_digits,p,n); } -unsigned int and32(n) -unsigned int n; +unsigned int and32(unsigned int n) { if (Base == 2) { unsigned int m = (n >> 1); @@ -136,8 +132,7 @@ unsigned int n; } } -unsigned int or32(n) -unsigned int n; +unsigned int or32(unsigned int n) { if (Base == 2) { unsigned int m = (n >> 1); @@ -150,14 +145,12 @@ unsigned int n; } } -unsigned int whirl32(p,n) -unsigned int p,n; +unsigned int whirl32(unsigned int p, unsigned int n) { return whirl(Large_digits,p,n); } -unsigned int xor(len,n) -unsigned int len,n; +unsigned int xor(unsigned int len, unsigned int n) { unsigned int i, fac = 1, result = 0, d1, d2, dsave; d1 = n % Base; @@ -171,8 +164,7 @@ unsigned int len,n; return result; } -unsigned int xor16(n) -unsigned int n; +unsigned int xor16(unsigned int n) { if (Base == 2) { unsigned int m = (n >> 1); @@ -185,8 +177,7 @@ unsigned int n; } } -unsigned int xor32(n) -unsigned int n; +unsigned int xor32(unsigned int n) { if (Base == 2) { unsigned int m = (n >> 1); @@ -199,8 +190,7 @@ unsigned int n; } } -unsigned int fin(len,n) -unsigned int len,n; +static unsigned int fin(unsigned int len, unsigned int n) { unsigned int i, fac = 1, result = 0, d1, d2, dsave; d1 = n % Base; @@ -214,8 +204,7 @@ unsigned int len,n; return result; } -unsigned int fin16(n) -unsigned int n; +unsigned int fin16(unsigned int n) { if (Base == 2) { unsigned int m = (n >> 1); @@ -228,8 +217,7 @@ unsigned int n; } } -unsigned int fin32(n) -unsigned int n; +unsigned int fin32(unsigned int n) { if (Base == 2) { unsigned int m = (n >> 1); diff --git a/src/fiddle.h b/src/fiddle.h new file mode 100644 index 0000000..b01346f --- /dev/null +++ b/src/fiddle.h @@ -0,0 +1,12 @@ +/* fiddle.h -- functions implementing intercal's operators */ + +extern unsigned int mingle(register unsigned int r, register unsigned int s); +extern unsigned int iselect(register unsigned int r, register unsigned int s); +extern unsigned int and16(unsigned int n), or16(unsigned int n), + xor16(unsigned int n), fin16(unsigned int n); +extern unsigned int whirl16(unsigned int p, unsigned int n); +extern unsigned int and32(unsigned int n), or32(unsigned int n), + xor32(unsigned int n), fin32(unsigned int n); +extern unsigned int whirl32(unsigned int p, unsigned int n); + +/* fiddle.h ends here */ diff --git a/src/ick-wrap.c b/src/ick-wrap.c index 771cbe0..f5697e5 100644 --- a/src/ick-wrap.c +++ b/src/ick-wrap.c @@ -1,11 +1,12 @@ /* $A.c -- generated C-code file for INTERCAL program $A.i */ -#include -#include +#include +#include +#include -extern unsigned int mingle(), iselect(); -extern unsigned int and16(), or16(), xor16(), and32(), or32(), xor32(); -extern unsigned int whirl16(), whirl32(), fin16(), fin32(); +#include +#include +#include int lineno; @@ -13,9 +14,7 @@ static int abstained[$B]$C; $D $E -main(argc,argv) -int argc; -char **argv; +int main(int argc, char *argv[]) { int skipto = 0; @@ -43,6 +42,8 @@ $G { $H } + + return 0; } /* Generated code for $A.i ends here */ diff --git a/src/ick.h b/src/ick.h index 30cfc58..3a0584c 100644 --- a/src/ick.h +++ b/src/ick.h @@ -1,5 +1,11 @@ /* ick.h -- compilation types for intercal parser */ +/* Comment this out if your version of lex automatically supplies yylineno. */ +#define YYLINENO_BY_HAND + +/* Comment this out if your version of lex doesn't use yyrestart(). */ +#define USE_YYRESTART + typedef int bool; #define TRUE 1 #define FALSE 0 @@ -71,17 +77,11 @@ extern assoc vartypes[]; extern char *textlines[MAXLINES]; extern int yylineno; -extern unsigned int mingle(), iselect(); -extern unsigned int and16(), or16(), xor16(), and32(), or32(), xor32(); -extern unsigned int whirl16(), whirl32(), fin16(), fin32(); - -extern int yydebug; -extern int yylineno; -extern int politesse; - /* compilation options */ extern bool compile_only; /* just compile into C, don't run the linker */ +extern int yydebug; /* print debugging information while parsing */ +extern int traditional; /* compile as INTERCAL-72 */ -extern int lineno; /* current source line number; lose() uses it */ +extern int politesse; /* ick.h ends here */ diff --git a/src/ick.y b/src/ick.y index 14c7a75..895322c 100644 --- a/src/ick.y +++ b/src/ick.y @@ -15,22 +15,25 @@ WHIRL operator. #include #include "sizes.h" #include "ick.h" +#include "feh.h" #include "lose.h" -#define yylex() lexer() +extern int yyerror(char*); -extern node *newnode(), *cons(); -extern tuple *newtuple(); -extern unsigned int intern(); -extern int yylineno, traditional; +/* Intervene our first-stage lexer. */ +extern int lexer(void); +#define yylex() lexer() static node *rlist; /* pointer to current right-hand node list */ -static node *llist; /* pointer to current left-hand node list */ +/* static node *llist; */ /* pointer to current left-hand node list */ static node *np; /* variable for building node lists */ #define ACTION(x, nt, nn) {x = newtuple(); x->type = nt; x->u.node=nn;} #define TARGET(x, nt, nn) {x = newtuple(); x->type = nt; x->u.target=nn;} #define NEWFANGLED if (traditional) lose(E111,yylineno,(char*)NULL); else + +static tuple *splat(void); + %} %start program @@ -194,7 +197,7 @@ oparray : TAIL UNARY NUMBER constant: MESH NUMBER { /* enforce the 16-bit constant constraint */ - if ($2 > Max_small) + if ((unsigned int)$2 > Max_small) lose(E017, yylineno, (char *)NULL); $$ = newnode(); $$->opcode = MESH; @@ -277,7 +280,7 @@ unambig : variable {$$ = $1;} $$->rval->opcode = $1; if($1 == MESH) { /* enforce the 16-bit constant constraint */ - if ($3 > Max_small) + if ((unsigned int)$3 > Max_small) lose(E017, yylineno, (char *)NULL); $$->rval->constant = $3; } @@ -306,11 +309,10 @@ unambig : variable {$$ = $1;} %% -tuple *splat() +static tuple *splat(void) /* try to recover from an invalid statement. */ { - extern FILE *yyin; - tuple *sp; + tuple *sp; int tok, i, lineno; extern bool re_send_token; diff --git a/src/lexer.l b/src/lexer.l index 5a97890..40bfe50 100644 --- a/src/lexer.l +++ b/src/lexer.l @@ -1,5 +1,6 @@ %{ #include +#include #include #include #include @@ -7,9 +8,18 @@ #include "y.tab.h" #include "lose.h" -#ifdef YYLINENO_BY_HAND -int yylineno = 1; -#endif /* YYLINENO_BY_HAND */ +#define YY_NO_UNPUT + +#ifndef yywrap +static int yywrap(void) +{ + return 1; +} +#endif /* yywrap */ + +#ifdef YYLINENO_BY_HAND +int yylineno = 1; +#endif /* YYLINENO_BY_HAND */ #ifdef MAIN YYSTYPE yylval; @@ -18,48 +28,18 @@ YYSTYPE yylval; char *textlines[MAXLINES]; int politesse = 0; +#ifdef FLEX_SCANNER +static char linebuf[YY_BUF_SIZE]; +#else /* FLEX_SCANNER */ static char linebuf[YYLMAX]; +#endif /* FLEX_SCANNER */ + static char *lineptr = linebuf; bool re_send_token = FALSE; -int lexer() -{ - static int tok = BADCHAR; - - if (re_send_token) - re_send_token = FALSE; - else - { - tok = yylex(); -#ifdef YYDEBUG - if (yydebug) - (void) (void) fprintf(stdout, "yylex: returning token %d\n", tok); -#endif /* YYDEBUG */ - } - -#ifdef YYDEBUG - if (yydebug) - (void) (void) fprintf(stdout, "lexer: returning token %d\n", tok); -#endif /* YYDEBUG */ - return(tok); -} - -int myatoi(text) -char *text; -{ -#define MAXTEXT 100 - static char buf[MAXTEXT]; - register int i; - - for(buf[i = 0] = '\0';*text && i < MAXTEXT;text++) { - if(isdigit(*text)) { - buf[i++] = *text; - } - } - buf[i] = '\0'; - return atoi(buf); -} +int lexer(void); +static int myatoi(char *text); /* * The spectacular ugliness of INTERCAL syntax requires that the lexical @@ -71,9 +51,10 @@ char *text; */ #undef getc -int getc(fp) -FILE *fp; +int getc(FILE *fp) { + extern FILE* yyin; + static bool bangflag = FALSE; static bool backflag = FALSE; @@ -135,13 +116,30 @@ FILE *fp; } else { +#ifdef ACCEPT_LOWERCASE if (islower(c)) c = toupper(c); +#endif /* ACCEPT_LOWERCASE */ return(*lineptr++ = c); } } } +/* replace YY_INPUT so that it uses our getc function. */ +#undef YY_INPUT +#define YY_INPUT(buf,result,max_size) \ + { \ + int c = getc(yyin); \ + if (c == EOF) { \ + if (ferror(yyin)) \ + YY_FATAL_ERROR("input in flex scanner failed"); \ + result = YY_NULL; \ + } else { \ + buf[0] = c; \ + result = 1; \ + } \ + } + %} W [\ \t\n]* @@ -225,13 +223,55 @@ GIVE{W}UP {return(GIVE_UP);} %% -#ifdef MAIN -int yyerror() +int lexer(void) +{ + static int tok = BADCHAR; + + if (re_send_token) + re_send_token = FALSE; + else + { + tok = yylex(); +#ifdef YYDEBUG + if (yydebug) + (void) fprintf(stdout, "yylex: returning token %d\n", tok); +#endif /* YYDEBUG */ + } + +#ifdef YYDEBUG + if (yydebug) + (void) fprintf(stdout, "lexer: returning token %d\n", tok); +#endif /* YYDEBUG */ + return(tok); +} + +static int myatoi(char *text) { - (void) printf("lextest: lexer error.\n"); +#define MAXTEXT 100 + static char buf[MAXTEXT]; + register int i; + + for(buf[i = 0] = '\0';*text && i < MAXTEXT;text++) { + if(isdigit(*text)) { + buf[i++] = *text; + } + } + buf[i] = '\0'; + return atoi(buf); +} + +void yyerror(char *errtype) +{ +#ifdef MAIN + (void) printf("lextest: lexer error: %s.\n", errtype); +#else /* MAIN */ + /* lose(E017, yylineno, (char *)NULL); */ + (void) errtype; +#endif /* MAIN */ } -main() +#ifdef MAIN +int main(void) { int t; @@ -240,10 +280,6 @@ main() (void) printf("%03d %09d\n", t, yylval.numval); yylval.numval = 0; } + return 0; } #endif /* MAIN */ - -int yywrap() -{ - return(EOF); -} diff --git a/src/lose.c b/src/lose.c index d12389e..ea13ddd 100644 --- a/src/lose.c +++ b/src/lose.c @@ -3,11 +3,10 @@ */ /*LINTLIBRARY*/ #include +#include +#include "lose.h" -void lose(m, n, s) -char *m; -int n; -char *s; +void lose(char *m, int n, char *s) { (void) fprintf(stderr, "ICL%c%c%cI\t", diff --git a/src/lose.h b/src/lose.h index c4e39f8..eeed55e 100644 --- a/src/lose.h +++ b/src/lose.h @@ -1,4 +1,4 @@ -/* lose.h --- error message strings +/* lose.h --- error message strings */ /* * Note: these error message texts, with one exception, are direct from @@ -121,6 +121,8 @@ #define E997 "997 ILLEGAL POSSESSION OF A CONTROLLED UNARY OPERATOR.\n\ ON THE WAY TO %d\n" -extern void lose(); +extern int lineno; + +extern void lose(char *m, int n, char *s); /* lose.h ends here */ diff --git a/src/numerals.c b/src/numerals.c index 0d816fb..e193ab5 100644 --- a/src/numerals.c +++ b/src/numerals.c @@ -14,99 +14,106 @@ * Nahuatl, Tagalog, Sanskrit, Basque, Georgian, Kwakiutl, and * Volap\"uk are now supported in addition to English. */ -numeral numerals[] = +typedef struct +{ + char *name; + int value; +} +numeral; + +static numeral numerals[] = { /* English */ - "OH", 0, - "ZERO", 0, - "ONE", 1, - "TWO", 2, - "THREE", 3, - "FOUR", 4, - "FIVE", 5, - "SIX", 6, - "SEVEN", 7, - "EIGHT", 8, - "NINE", 9, - "NINER", 9, /* For all you junior birdmen */ + { "OH", 0 }, + { "ZERO", 0 }, + { "ONE", 1 }, + { "TWO", 2 }, + { "THREE", 3 }, + { "FOUR", 4 }, + { "FIVE", 5 }, + { "SIX", 6 }, + { "SEVEN", 7 }, + { "EIGHT", 8 }, + { "NINE", 9 }, + { "NINER", 9 }, /* For all you junior birdmen */ /* Sanskrit */ - "SUTYA", 0, /* Retroflex s, pronounced halfway to sh */ - "SHUTYA", 0, - "EKA", 1, - "DVI", 2, - "TRI", 3, - "CHATUR", 4, - "PANCHAN", 5, - "SHASH", 6, - "SAPTAM", 7, - "ASHTAN", 8, - "NAVAN", 9, + { "SUTYA", 0 }, /* Retroflex s, pronounced halfway to sh */ + { "SHUTYA", 0 }, + { "EKA", 1 }, + { "DVI", 2 }, + { "TRI", 3 }, + { "CHATUR", 4 }, + { "PANCHAN", 5 }, + { "SHASH", 6 }, + { "SAPTAM", 7 }, + { "ASHTAN", 8 }, + { "NAVAN", 9 }, /* Basque */ - "ZEROA", 0, - "BAT", 1, - "BI", 2, - "HIRO", 3, - "LAU", 4, - "BORTZ", 5, - "SEI", 6, - "ZAZPI", 7, - "ZORTZI", 8, - "BEDERATZI", 9, + { "ZEROA", 0 }, + { "BAT", 1 }, + { "BI", 2 }, + { "HIRO", 3 }, + { "LAU", 4 }, + { "BORTZ", 5 }, + { "SEI", 6 }, + { "ZAZPI", 7 }, + { "ZORTZI", 8 }, + { "BEDERATZI", 9 }, /* Tagalog */ - "WALA", 0, - "ISA", 1, - "DALAWA", 2, - "TATLO", 3, - "APAT", 4, - "LIMA", 5, - "ANIM", 6, - "PITO", 7, - "WALO", 8, - "SIYAM", 9, + { "WALA", 0 }, + { "ISA", 1 }, + { "DALAWA", 2 }, + { "TATLO", 3 }, + { "APAT", 4 }, + { "LIMA", 5 }, + { "ANIM", 6 }, + { "PITO", 7 }, + { "WALO", 8 }, + { "SIYAM", 9 }, /* Classical Nahuatl */ - "AHTLE", 0, /* Actually `nothing'; no separate zero word is known */ - "CE", 1, - "OME", 2, - "IEI", 3, - "NAUI", 4, - "NACUILI", 5, - "CHIQUACE", 6, - "CHICOME", 7, - "CHICUE", 8, - "CHICUNAUI", 9, + { "AHTLE", 0 }, /* Actually `nothing'; no separate zero word is known */ + { "CE", 1 }, + { "OME", 2 }, + { "IEI", 3 }, + { "NAUI", 4 }, + { "NACUILI", 5 }, + { "CHIQUACE", 6 }, + { "CHICOME", 7 }, + { "CHICUE", 8 }, + { "CHICUNAUI", 9 }, /* Georgian */ - "NULI", 0, - "ERTI", 1, - "ORI", 2, - "SAMI", 3, - "OTXI", 4, - "XUTI", 5, - "EKSVI", 6, - "SHVIDI", 7, - "RVA", 8, - "CXRA", 9, + { "NULI", 0 }, + { "ERTI", 1 }, + { "ORI", 2 }, + { "SAMI", 3 }, + { "OTXI", 4 }, + { "XUTI", 5 }, + { "EKSVI", 6 }, + { "SHVIDI", 7 }, + { "RVA", 8 }, + { "CXRA", 9 }, /* Kwakiutl (technically, Kwak'wala) */ - "KE'YOS", 0, /* Actually `nothing'; no separate zero word is known */ - "'NEM", 1, - "MAL'H", 2, - "YUDEXW", 3, - "MU", 4, - "SEK'A", 5, - "Q'ETL'A", 6, - "ETLEBU", 7, - "MALHGWENALH", 8, - "'NA'NE'MA", 9, + { "KE'YOS", 0 }, /* Actually `nothing'; no separate zero word is known */ + { "'NEM", 1 }, + { "MAL'H", 2 }, + { "YUDEXW", 3 }, + { "MU", 4 }, + { "SEK'A", 5 }, + { "Q'ETL'A", 6 }, + { "ETLEBU", 7 }, + { "MALHGWENALH", 8 }, + { "'NA'NE'MA", 9 }, /* Volap\"uk */ - "NOS", 0, - "BAL", 1, - "TEL", 2, - "KIL", 3, - "FOL", 4, - "LUL", 5, - "M\\\"AL", 6, - "VEL", 7, - "J\\\"OL", 8, - "Z\\\"UL", 9, + { "NOS", 0 }, + { "BAL", 1 }, + { "TEL", 2 }, + { "KIL", 3 }, + { "FOL", 4 }, + { "LUL", 5 }, + { "M\\\"AL", 6 }, + { "VEL", 7 }, + { "J\\\"OL", 8 }, + { "Z\\\"UL", 9 }, }; /* numeral.c ends here */ diff --git a/src/perpetrate.c b/src/perpetrate.c index b930300..a171fa5 100644 --- a/src/perpetrate.c +++ b/src/perpetrate.c @@ -9,9 +9,14 @@ DESCRIPTION ****************************************************************************/ /*LINTLIBRARY */ #include +#include +#include +#include #include #include "ick.h" +#include "feh.h" #include "y.tab.h" +#include "sizes.h" #include "lose.h" #ifndef ICKINCLUDEDIR @@ -21,14 +26,23 @@ DESCRIPTION #define ICKLIBDIR "/usr/local/lib" #endif #ifndef CC -#define CC "cc" +#define CC "gcc" #endif +#ifdef USE_YYRESTART +/* function supplied by lex */ +extern void yyrestart(FILE*); +#endif /* USE_YYRESTART */ + +/* function created by yacc */ +extern int yyparse(void); + /* compilation options */ -bool dooptimize; /* do optimizations? (controlled by -O) */ -bool clockface; /* set up output to do IIII for IV */ bool compile_only; /* just compile into C, don't run the linker */ -bool traditional; /* insist on strict INTERCAL-72 conformance */ +bool traditional; /* insist on strict INTERCAL-72 conformance */ + +static bool dooptimize; /* do optimizations? (controlled by -O) */ +static bool clockface; /* set up output to do IIII for IV */ #define SKELETON "ick-wrap.c" #define SYSLIB "syslib.i" @@ -58,13 +72,23 @@ tuple tuples[MAXLINES]; static void abend(int signim) { lose(E778, yylineno, (char *)NULL); + (void) signim; } -main(argc, argv) -int argc; -char *argv[]; +static void print_usage(char *prog, char *options) +{ + fprintf(stderr,"Usage: %s [-%s] [ ... ]\n",prog,options); + fprintf(stderr,"\t-c\t:compile INTERCAL to C, but don't compile C\n"); + fprintf(stderr,"\t-d\t:print debugging information (implies -c)\n"); + fprintf(stderr,"\t-t\t:traditional mode, accept only INTERCAL-72\n"); + fprintf(stderr,"\t-C\t:clockface output (e.g. use IIII instead of IV)\n"); + fprintf(stderr,"\t-O\t:attempt to optimize generated code\n"); + fprintf(stderr,"\t\tINTERCAL source file(s) (use extension .i)\n"); + fprintf(stderr,"\t\teach file produces a separate output program.\n"); +} + +int main(int argc, char *argv[]) { - extern char *optarg; /* set by getopt */ extern int optind; /* set by getopt */ char buf[BUFSIZ], buf2[BUFSIZ], *chp, *strrchr(); tuple *tp; @@ -74,7 +98,6 @@ char *argv[]; FILE *ifp, *ofp; int maxabstain; bool needsyslib; - void print_usage(); if (!(includedir = getenv("ICKINCLUDEDIR"))) includedir = ICKINCLUDEDIR; @@ -88,11 +111,11 @@ char *argv[]; switch (c) { case 'c': - compile_only = 1; + compile_only = TRUE; break; case 'd': - yydebug = compile_only = 1; + yydebug = compile_only = TRUE; break; case 'C': @@ -100,7 +123,7 @@ char *argv[]; break; case 't': - traditional = 1; + traditional = TRUE; break; case 'O': @@ -117,9 +140,9 @@ char *argv[]; } (void) signal(SIGSEGV, abend); -#ifdef SIGBUS +#ifdef SIGBUS (void) signal(SIGBUS, abend); -#endif /* SIGBUS */ +#endif /* SIGBUS */ (void) sprintf(buf2,"%s/%s",includedir,SKELETON); @@ -202,6 +225,9 @@ char *argv[]; if ( freopen(buf2, "r", stdin) == (FILE*) NULL ) { lose(E127, 0, (char*) NULL); } +#ifdef USE_YYRESTART + yyrestart(stdin); +#endif /* USE_YYRESTART */ yyparse(); } @@ -273,10 +299,11 @@ char *argv[]; maxabstain++; if (maxabstain) { - int i; + int i; (void) fprintf(ofp, "#define UNKNOWN\t\t0\n"); - for (i = 0; i < sizeof(enablers)/sizeof(char *); i++) + i = 0; + for (; i < (int)(sizeof(enablers)/sizeof(char *)); i++) (void) fprintf(ofp, "#define %s\t%d\n", enablers[i], i+1); @@ -339,7 +366,7 @@ char *argv[]; "static bool hyforget[%d];\n", nhybrids); } - if (yydebug | compile_only) + if (yydebug || compile_only) for (op = oblist; op < obdex; op++) (void) fprintf(ofp, " /* %s %d -> %d */\n", nameof(op->type, vartypes), @@ -381,19 +408,7 @@ char *argv[]; } } (void) fclose(ifp); -} - -void print_usage(prog,options) -char *prog, *options; -{ - fprintf(stderr,"Usage: %s [-%s] [ ... ]\n",prog,options); - fprintf(stderr,"\t-c\t:compile INTERCAL to C, but don't compile C\n"); - fprintf(stderr,"\t-d\t:print debugging information (implies -c)\n"); - fprintf(stderr,"\t-t\t:traditional mode, accept only INTERCAL-72\n"); - fprintf(stderr,"\t-C\t:clockface output (e.g. use IIII instead of IV)\n"); - fprintf(stderr,"\t-O\t:attempt to optimize generated code\n"); - fprintf(stderr,"\t\tINTERCAL source file(s) (use extension .i)\n"); - fprintf(stderr,"\t\teach file produces a separate output program.\n"); + return 0; } /* perpetrate.c ends here */ diff --git a/src/sizes.h b/src/sizes.h index 811cc57..f3c49a8 100644 --- a/src/sizes.h +++ b/src/sizes.h @@ -5,3 +5,5 @@ extern int Small_digits; extern int Large_digits; extern unsigned int Max_small; extern unsigned int Max_large; + +/* sizes.h ends here */