summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKaz Kylheku <kaz@kylheku.com>2017-05-15 20:39:51 -0700
committerKaz Kylheku <kaz@kylheku.com>2017-05-15 20:39:51 -0700
commit225103289d779216781b2c256c602deca1f05b2a (patch)
treef0151c1ab610002a7aab79fb572032625da99bc2
parentf43feacabc378cbbf31beea28f41f1cb9483f4b6 (diff)
downloadtxr-225103289d779216781b2c256c602deca1f05b2a.tar.gz
txr-225103289d779216781b2c256c602deca1f05b2a.tar.bz2
txr-225103289d779216781b2c256c602deca1f05b2a.zip
less table robust against type renumbering.
* lib.c (less_tab_init): The type_prec table initialization will become incorrect if new type enums are added other than at the end. Let's switch to assignments. Anything not mentioned is zero. * lib.h: Add more advice to comment about extending type_t: consider all places where MAX_TYPE is used.
-rw-r--r--lib.c33
-rw-r--r--lib.h2
2 files changed, 15 insertions, 20 deletions
diff --git a/lib.c b/lib.c
index 6939f817..7e79297a 100644
--- a/lib.c
+++ b/lib.c
@@ -4406,25 +4406,20 @@ static enum less_handling less_tab[MAXTYPE+1][MAXTYPE+1];
static void less_tab_init(void)
{
int l, r;
- static int type_prec[MAXTYPE+1] = {
- 4, /* NIL */
- 1, /* NUM */
- 1, /* CHR */
- 3, /* LIT */
- 5, /* CONS */
- 3, /* STR */
- 4, /* SYM */
- 0, /* PKG */
- 0, /* FUN */
- 6, /* VEC */
- 5, /* LCONS */
- 3, /* LSTR */
- 0, /* COBJ */
- 0, /* ENV */
- 1, /* BGNUM */
- 1, /* FLNUM */
- 2, /* RNG */
- };
+ static int type_prec[MAXTYPE+1];
+
+ type_prec[NIL] = 4;
+ type_prec[NUM] = 1;
+ type_prec[CHR] = 1;
+ type_prec[LIT] = 3;
+ type_prec[CONS] = 5;
+ type_prec[STR] = 3;
+ type_prec[SYM] = 4;
+ type_prec[LCONS] = 5;
+ type_prec[LSTR] = 3;
+ type_prec[BGNUM] = 1;
+ type_prec[FLNUM] = 1;
+ type_prec[RNG] = 2;
for (l = 0; l <= MAXTYPE; l++)
for (r = 0; r <= MAXTYPE; r++) {
diff --git a/lib.h b/lib.h
index 301e46c4..04440b39 100644
--- a/lib.h
+++ b/lib.h
@@ -61,7 +61,7 @@ typedef enum type {
NIL = TAG_PTR, NUM = TAG_NUM, CHR = TAG_CHR, LIT = TAG_LIT, CONS,
STR, SYM, PKG, FUN, VEC, LCONS, LSTR, COBJ, ENV,
BGNUM, FLNUM, RNG, BUF, MAXTYPE = BUF
- /* If extending, check TYPE_SHIFT */
+ /* If extending, check TYPE_SHIFT and all ocurrences of MAX_TYPE */
} type_t;
#define TYPE_SHIFT 5