Branch: Tag:

2021-01-08

2021-01-08 15:00:18 by Henrik Grubbström (Grubba) <grubba@grubba.org>

Compiler [Typechecker]: Unify binops for T_AND and T_OR.

Also fixes typo in lookup table.

4507:    remap, aflags, bflags, remap_flags);    }    switch(b->type) { +  case T_AND:    case T_OR: -  /* op secondary -  * 0 0000 0 0000 -  * 1 0001 7 0111 -  * 2 0010 1 0001 -  * 3 0011 1, 3, 5, 7 0011 -  * 4 0100 7 0111 -  * 5 0101 7 0111 -  * 6 0110 - -  * 7 0111 7 0111 -  * 8 1000 1 0001 -  * 9 1001 - -  * 10 1010 1 0001 -  * 11 1011 1 0001 -  * 12 1100 1, 3, 5, 7 0011 -  * 13 1101 1 0111 -  * 14 1110 1 0001 -  * 15 1111 15 1111 +  /* op secondary(T_AND) secondary(T_OR) +  * 0 0000 0 0000 0 0000 +  * 1 0001 1 0001 7 0111 +  * 2 0010 7 0111 1 0001 +  * 3 0011 1, 3, 5, 7 0011 1, 3, 5, 7 0011 +  * 4 0100 1 0001 7 0111 +  * 5 0101 1 0001 7 0111 +  * 6 0110 - - +  * 7 0111 1 0001 7 0111 +  * 8 1000 7 0111 1 0001 +  * 9 1001 - - +  * 10 1010 7 0111 1 0001 +  * 11 1011 7 0111 1 0001 +  * 12 1100 1, 3, 5, 7 0011 1, 3, 5, 7 0011 +  * 13 1101 1 0001 7 0111 +  * 14 1110 7 0111 1 0001 +  * 15 1111 15 1111 15 1111 +  * +  * Note that secondary ops 1 and 7 are swapped for T_AND and T_OR.    */    tmp = low_type_binop(op, a, b->car, remap, aflags, bflags, remap_flags);    tmp2 = low_type_binop(op, a, b->cdr, remap, aflags, bflags, remap_flags);    -  /* NB: XOR and XNOR not supported cf above. -  * This is not a problem in practice, as they -  * are handled earlier. -  */ -  if ("071377-71-113117"[op] == '1') { +  /* FIXME: XOR and XNOR not supported cf above. */ +  if (("017311-17-77317f"[op] == '1') == (b->type == T_AND)) {    /* Secondary operator is AND. */    if (!tmp2) {    free_type(tmp);
4544:    return NULL;    }    -  type_stack_mark(); -  push_finished_type(tmp); -  push_finished_type(tmp2); -  push_reverse_type(T_AND); -  } else { -  /* Secondary operator is OR. */ -  if (!tmp2) return tmp; -  if (!tmp) return tmp2; -  -  type_stack_mark(); -  push_finished_type(tmp); -  push_finished_type(tmp2); -  push_reverse_type(T_OR); -  } -  free_type(tmp); -  free_type(tmp2); -  return pop_unfinished_type(); -  -  case T_AND: -  tmp = low_type_binop(op, a, b->cdr, remap, aflags, bflags, remap_flags); -  if (!tmp) return NULL; -  tmp2 = low_type_binop(op, a, b->car, remap, aflags, bflags, remap_flags); -  if (!tmp2) { -  free_type(tmp2); -  return NULL; -  } -  -  switch(op) { -  case PT_BINOP_AND: +  if ((b->type == T_AND) && (op == PT_BINOP_AND)) {    /* NB: Attempt to avoid keeping the result from inverted types,    * in order to reduce type expansion.    */
4585:    tmp2 = remap_markers(b->cdr, NULL, remap,    remap_flags ^ PT_FLAG_REMAP_SWAP_MARKERS);    } -  break; -  default: -  /* Make the C-compiler happy. */ -  break; +     }       type_stack_mark();    push_finished_type(tmp);    push_finished_type(tmp2);    push_reverse_type(T_AND); -  +  } else { +  /* Secondary operator is OR. */ +  if (!tmp2) return tmp; +  if (!tmp) return tmp2; +  +  type_stack_mark(); +  push_finished_type(tmp); +  push_finished_type(tmp2); +  push_reverse_type(T_OR); +  }    free_type(tmp);    free_type(tmp2);    return pop_unfinished_type(); -  +     case T_NOT:    /* Swap the bits of the opcode pairwise.    *