Branch: Tag:

2021-04-09

2021-04-09 17:31:41 by Henrik Grubbström (Grubba) <grubba@grubba.org>

Compiler [Typechecker]: Improved binop(PT_BINOP_{OR|MINUS}, ...)

Add special case to simplify the result for A - (B|C) and A | (B|C).

Previously
int - (int(1)|int(5))
resulted in
(int(..0)|int(2..)) & (int(..4)|int(6..))
now it instead results in
int(..0)|int(2..4)|int(6..)
which is what most users expect.

4677:    remap, aflags, bflags, remap_flags);    }    switch(b->type) { -  case T_AND: +     case T_OR: -  +  if ((op == PT_BINOP_MINUS) || (op == PT_BINOP_OR)) { +  /* Special case to avoid excessively complicated expressions +  * in the result. +  * +  * A - (B | C) == (A - B) - C +  * rather than +  * A - (B | C) == (A - B) & (A - C) +  * +  * A | (B | C) == (A | B) | C +  * rather than +  * A | (B | C) == (A | B) | (A | C) +  */ +  tmp = low_type_binop(op, a, b->car, remap, aflags, bflags, remap_flags); +  tmp2 = remap_markers(b->cdr, NULL, remap, +  remap_flags | PT_FLAG_REMAP_SWAP_MARKERS); +  ret = low_type_binop(op, tmp, tmp2, NULL, aflags, bflags, 0); +  free_type(tmp); +  free_type(tmp2); +  return ret; +  } +  /* FALLTHRU */ +  case T_AND:    /* op secondary(T_AND) secondary(T_OR)    * 0 0000 0 0000 0 0000    * 1 0001 1 0001 7 0111