]> thyrsus.com Git - intercal.git/commitdiff
Association of magic line ranges to system libraries is noe declarative.
authorEric S. Raymond <esr@thyrsus.com>
Thu, 26 Aug 2010 18:01:53 +0000 (14:01 -0400)
committerEric S. Raymond <esr@thyrsus.com>
Thu, 26 Aug 2010 18:01:53 +0000 (14:01 -0400)
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
buildaux/Makefile.am
buildaux/Makefile.in
pit/Makefile
src/perpet.c

diff --git a/NEWS b/NEWS
index e509a69222a27d0e8a17eda4d6e3d77213cebdd1..3f8eb7acd4b0a2faa0cb7fc2ff3ec814d4eae15d 100644 (file)
--- 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.
index 2a5ca7ea12a388b042d217d22b25ffc116fca526..81492a237ecb6a1539055690cebef038a69c1c12 100644 (file)
@@ -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
index f12ef9dc08e1813492ad9f7a63a4436c771ce647..386472f796a6f7d4073a0a59d5fab6f1105374fe 100644 (file)
@@ -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
index 3189a7887d6d6ea91bf1f562d4e14c6f03638061..95b659591d1ba294086069dc389165f759dc2964 100644 (file)
@@ -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)
index 9d2d2e165552efbefc665fe06af837159dc1b3aa..65914b981bf5e3c715cd00dc81c5b87da50388b7 100644 (file)
@@ -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