Branch: Tag:

2010-10-16

2010-10-16 23:47:57 by Martin Stjernholm <mast@lysator.liu.se>

Introduced a special value for unorderedness from cmpfuns.

The stable sort function masks it out, so that stable sorting work together
with the previous commit.

910:    return current_order;   }    - /* Returns 2 if no relation is established through lfun calls, or 3 if -  * no order defining lfuns (i.e. `< or `>) were found. */ + /* Returns CMPFUN_UNORDERED if no relation is established through lfun +  * calls, or -CMPFUN_UNORDERED if no order defining lfuns (i.e. `< or +  * `>) were found. */   static int lfun_cmp (const struct svalue *a, const struct svalue *b)   {    struct program *p; -  int default_res = 3, fun; +  int default_res = -CMPFUN_UNORDERED, fun;       if (a->type == T_OBJECT && (p = a->u.object->prog)) {    if ((fun = FIND_LFUN(p->inherits[a->subtype].prog, LFUN_LT)) != -1) {
928:    return -1;    }    pop_stack(); -  default_res = 2; +  default_res = CMPFUN_UNORDERED;    }       if ((fun = FIND_LFUN(p->inherits[a->subtype].prog, LFUN_GT)) != -1) {
941:    return 1;    }    pop_stack(); -  default_res = 2; +  default_res = CMPFUN_UNORDERED;    }       if ((fun = FIND_LFUN(p->inherits[a->subtype].prog, LFUN_EQ)) != -1) {
967:    return 1;    }    pop_stack(); -  default_res = 2; +  default_res = CMPFUN_UNORDERED;    }       if ((fun = FIND_LFUN(p->inherits[b->subtype].prog, LFUN_GT)) != -1) {
980:    return -1;    }    pop_stack(); -  default_res = 2; +  default_res = CMPFUN_UNORDERED;    }       if ((fun = FIND_LFUN(p->inherits[b->subtype].prog, LFUN_EQ)) != -1) {
1046:       res = lfun_cmp (a, b);    -  if (res == 3) { +  if (res == -CMPFUN_UNORDERED) {    /* If the objects had no inequality comparison lfuns to call, use    * their pointers to get a well defined internal sort order. Let's    * also group objects cloned from the same program. */
1056:    return a->u.object->prog < b->u.object->prog ? -1 : 1;    }    -  return res == 2 ? -1 : res; +  return res;   }      int set_svalue_cmpfun(const struct svalue *a, const struct svalue *b)
1065:    if (typediff) {    if (a->type == T_OBJECT || b->type == T_OBJECT) {    int res = lfun_cmp (a, b); -  if (res < 2) return res; +  if (res != -CMPFUN_UNORDERED) return res;    }    return typediff;    }
1133:    if (typediff) {    if (a->type == T_OBJECT || b->type == T_OBJECT) {    int res = lfun_cmp (a, b); -  if (res < 2) return res; +  if (res != -CMPFUN_UNORDERED) return res;    }    return typediff;    }
1242:      #define SORT_BY_INDEX   #define EXTRA_LOCALS int cmpfun_res; - #define CMP(X,Y) ((cmpfun_res = alpha_svalue_cmpfun(svals + X, svals + Y)) ? \ + #define CMP(X,Y) ((cmpfun_res = \ +  (alpha_svalue_cmpfun(svals + X, svals + Y) & \ +  ~CMPFUN_UNORDERED)) ? \    cmpfun_res : pos[X] - pos[Y])   #define SWAP(X,Y) { \    {struct svalue tmp = svals[X]; svals[X] = svals[Y]; svals[Y] = tmp;} \