Give - unary expressions special treatment.

The progs engine has no neg instruction, so need to implement -val as
nil - val
This commit is contained in:
Bill Currie 2011-03-03 18:13:30 +09:00
parent f9e177efd6
commit 4324486ae6

View file

@ -589,6 +589,22 @@ expr_cast (sblock_t *sblock, expr_t *e, operand_t **op)
return sblock;
}
static sblock_t *
expr_negate (sblock_t *sblock, expr_t *e, operand_t **op)
{
expr_t *neg;
expr_t *zero;
zero = new_nil_expr ();
zero->file = e->file;
zero->line = e->line;
convert_nil (zero, e->e.expr.type);
neg = binary_expr ('-', zero, e->e.expr.e1);
neg->file = e->file;
neg->line = e->line;
return statement_subexpr (sblock, neg, op);
}
static sblock_t *
expr_uexpr (sblock_t *sblock, expr_t *e, operand_t **op)
{
@ -608,6 +624,10 @@ expr_uexpr (sblock_t *sblock, expr_t *e, operand_t **op)
case 'C':
sblock = expr_cast (sblock, e, op);
break;
case '-':
// progs has no neg instruction!?!
sblock = expr_negate (sblock, e, op);
break;
default:
opcode = convert_op (e->e.expr.op);
if (!opcode)