From 39d00084831e3f06e3a40f4e4db55baa8e066c71 Mon Sep 17 00:00:00 2001 From: "Eric S. Raymond" Date: Thu, 26 Aug 2010 14:01:53 -0400 Subject: [PATCH] Association of magic line ranges to system libraries is noe declarative. Rather than being hard-coded in logic, there's now a table in perpet.c that maps numeric-label ranges to system library file basenames. The sytem library takes 1000-1999; the first new library to get this treatment is floatlib, range 5000-5999. The test for this is the ability to compile the pit's fft.i program, which requires both syslib and floatlib. Note that whenever you add a new library to this table, the build system will need to be tweaked to add the library to the list of those copied to the build directory. --- NEWS | 6 +++ buildaux/Makefile.am | 4 +- buildaux/Makefile.in | 4 +- pit/Makefile | 3 ++ src/perpet.c | 100 ++++++++++++++++++++++++++----------------- 5 files changed, 75 insertions(+), 42 deletions(-) diff --git a/NEWS b/NEWS index e509a69..3f8eb7a 100644 --- a/NEWS +++ b/NEWS @@ -11,6 +11,12 @@ Changes by Eric S. Raymond 3. A new program for the pit: Brendan Gregg's guess game. +4. The floating-point library is now automatically included if + a program NEXTs to labels in the range 5000-5999. Internally, + line-range to system library mappings are no longer hardcoded but + rather declared as an array of associations that can be easily + modified. + Bugs reported and changes patched by Arvid Norlander 1. Fixed a typo in the perpet.c version of the help information. diff --git a/buildaux/Makefile.am b/buildaux/Makefile.am index 2a5ca7e..81492a2 100644 --- a/buildaux/Makefile.am +++ b/buildaux/Makefile.am @@ -32,6 +32,8 @@ syslib6.6i : pit/lib/syslib6.6i $(LN_S) `test -f 'pit/lib/syslib.6i' || echo '$(srcdir)/'`pit/lib/syslib6.6i syslib6.6i syslib7.7i : pit/lib/syslib7.7i $(LN_S) `test -f 'pit/lib/syslib.7i' || echo '$(srcdir)/'`pit/lib/syslib7.7i syslib7.7i +floatlib.i : pit/lib/floatlib.i + $(LN_S) `test -f 'pit/lib/floatlib.i' || echo '$(srcdir)/'`pit/lib/floatlib.i floatlib.i ick_ec.h : src/ick_ec.h $(LN_S) `test -f 'src/ick_ec.h' || echo '$(srcdir)/'`src/ick_ec.h ick_ec.h ick_lose.h : src/ick_lose.h @@ -48,7 +50,7 @@ AM_YFLAGS = -d # create symlinks used by ick to find files if it's run without first being # installed. BUILT_SOURCES = parser.h ick-wrap.c pickwrap.c syslib.i syslib3.3i syslib4.4i \ - syslib5.5i syslib6.6i syslib7.7i ick_ec.h fiddle.h abcess.h \ + syslib5.5i syslib6.6i syslib7.7i floatlib.i ick_ec.h fiddle.h abcess.h \ ick_lose.h yuk.h noinst_LIBRARIES = libidiot.a libidiot_a_SOURCES = src/idiotism.oil diff --git a/buildaux/Makefile.in b/buildaux/Makefile.in index f12ef9d..386472f 100644 --- a/buildaux/Makefile.in +++ b/buildaux/Makefile.in @@ -296,7 +296,7 @@ AM_YFLAGS = -d # create symlinks used by ick to find files if it's run without first being # installed. BUILT_SOURCES = parser.h ick-wrap.c pickwrap.c syslib.i syslib3.3i syslib4.4i \ - syslib5.5i syslib6.6i syslib7.7i ick_ec.h fiddle.h abcess.h \ + syslib5.5i syslib6.6i syslib7.7i floatlib.i ick_ec.h fiddle.h abcess.h \ ick_lose.h yuk.h noinst_LIBRARIES = libidiot.a @@ -1526,6 +1526,8 @@ syslib6.6i : pit/lib/syslib6.6i $(LN_S) `test -f 'pit/lib/syslib.6i' || echo '$(srcdir)/'`pit/lib/syslib6.6i syslib6.6i syslib7.7i : pit/lib/syslib7.7i $(LN_S) `test -f 'pit/lib/syslib.7i' || echo '$(srcdir)/'`pit/lib/syslib7.7i syslib7.7i +floatlib.i : pit/lib/floatlib.i + $(LN_S) `test -f 'pit/lib/floatlib.i' || echo '$(srcdir)/'`pit/lib/floatlib.i floatlib.i ick_ec.h : src/ick_ec.h $(LN_S) `test -f 'src/ick_ec.h' || echo '$(srcdir)/'`src/ick_ec.h ick_ec.h ick_lose.h : src/ick_lose.h diff --git a/pit/Makefile b/pit/Makefile index 3189a78..95b6595 100644 --- a/pit/Makefile +++ b/pit/Makefile @@ -9,6 +9,7 @@ BASE2SOURCES = \ ./beer.i \ ./bubble.i \ ./change.i \ + ./fft.i \ ./guess.i \ ./icat.i \ ./iching1.i \ @@ -104,6 +105,8 @@ test: $(TARGETS) # Needs special handling because the -m option is required tests/permute: tests/permute.i $(ICK) -m tests/permute.i +fft: fft.i + $(ICK) -m fft.i lines: wc -l $(SOURCES) diff --git a/src/perpet.c b/src/perpet.c index 9d2d2e1..65914b9 100644 --- a/src/perpet.c +++ b/src/perpet.c @@ -155,6 +155,20 @@ int tuplecount = 0; tuple *optuple = NULL; /* AIS: Tuple being optimized */ +/* + * mappings from magic line ranges to system library components are + * declared here. + */ +struct linerange_t { + int start, end; + char *libname; +}; +struct linerange_t lineranges[] = { + {1000, 1999, "syslib"}, /* the system library */ + {5000, 5699, "floatlib"}, /* the floating-point support */ + {0, 0, NULL}, +}; + extern const assoc varstores[]; /* AIS: Need to know this for PIC compilation */ #ifndef HAVE_UNISTD_H @@ -622,52 +636,58 @@ static void check_syslib(/*@partial@*/ char *buffer, /*@observer@*/ const char *argv0, /*@observer@*/ const char *ick_datadir) { - tuple *tp; - /* - * check if we need to magically include the system library - */ - *needsyslib = ick_FALSE; - if(!pickcompile) /* AIS: We never need syslib when compiling - for PIC, because it's preoptimized. */ - { - for (tp = tuples; tp->type; tp++) - { - /* - * If some label in the (1000)-(2000) range is defined, - * then clearly the syslib is already there, so we - * can stop searching and won't need the syslib. - */ - if (tp->label >= 1000 && tp->label <= 1999) { + tuple *tp; + struct linerange_t *lp; + + if (nosyslib || pickcompile) { *needsyslib = ick_FALSE; - break; - } - /* - * If some label in the (1000)-(2000) range is being - * called, we might need the system library. - */ - if (tp->type == NEXT && tp->u.target >= 1000 && - tp->u.target <= 1999) - *needsyslib = ick_TRUE; + return; } - } - if(nosyslib) *needsyslib = ick_FALSE; /* AIS */ - if (*needsyslib) - { /* AIS: modified to use ick_findandfreopen */ - if (ick_Base == 2) /* see code for opening the skeleton */ - (void) ick_snprintf_or_die(buffer, size, "%s.i", SYSLIB); - else - (void) ick_snprintf_or_die(buffer, size, "%s%d.%di", SYSLIB, ick_Base, ick_Base); - if (ick_findandfreopen(buffer, ick_datadir, "r", argv0, stdin) == NULL) - ick_lose(IE127, 1, (const char*) NULL); + + /* + * magical inclusion of system libraries is done here + */ + for (lp = lineranges; lp->start; lp++) + { + *needsyslib = ick_FALSE; + for (tp = tuples; tp->type; tp++) { + /* + * If some label in the specified range is defined, + * then assume the library we seek is already there, so we + * can stop searching. + */ + if (tp->label >= lp->start && tp->label <= lp->end) { + *needsyslib = ick_FALSE; + goto breakout; + } + /* + * If some label in the specified range is being + * called, we might need the library. + */ + if (tp->type == NEXT && + tp->u.target >= lp->start && tp->u.target <= lp->end) + *needsyslib = ick_TRUE; + } + if (*needsyslib) { + if (ick_Base == 2) + (void) ick_snprintf_or_die(buffer, size, + "%s.i", lp->libname); + else + (void) ick_snprintf_or_die(buffer, size, + "%s%d.%di", lp->libname, ick_Base, ick_Base); + if (ick_findandfreopen(buffer, ick_datadir, "r", argv0, stdin) == NULL) + ick_lose(IE127, 1, (const char*) NULL); #ifdef USE_YYRESTART - yyrestart(stdin); + yyrestart(stdin); #endif /* USE_YYRESTART */ - (void) yyparse(); - textlinecount=iyylineno; - } + (void) yyparse(); + textlinecount=iyylineno; + } + breakout: + ; + } } - /** * This code propagates type information up the expression tree. * It also does some unrelated stuff such as checking for WRITE IN and disabling -- 2.43.0