harec

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README | LICENSE

commit 1d408d8a995ff548b81885f1f8c968897da15107
parent 1a7e587288efdf94541756f27a0d15195717aa32
Author: Eyal Sawady <ecs@d2evs.net>
Date:   Wed, 14 Jul 2021 17:01:41 +0000

eval: flesh out unariy !, ~, and -

Signed-off-by: Eyal Sawady <ecs@d2evs.net>

Diffstat:
Msrc/eval.c | 13+++++++++++--
1 file changed, 11 insertions(+), 2 deletions(-)

diff --git a/src/eval.c b/src/eval.c @@ -645,12 +645,13 @@ static enum eval_result eval_unarithm(struct context *ctx, struct expression *in, struct expression *out) { struct expression lvalue = {0}; - enum eval_result r = eval_expr(ctx, in->binarithm.lvalue, &lvalue); + enum eval_result r = eval_expr(ctx, in->unarithm.operand, &lvalue); if (r != EVAL_OK) { return r; } out->type = EXPR_CONSTANT; + out->result = lvalue.result; switch (in->unarithm.op) { case UN_ADDRESS: assert(lvalue.type == EXPR_CONSTANT); @@ -660,11 +661,19 @@ eval_unarithm(struct context *ctx, struct expression *in, struct expression *out out->constant = lvalue.constant; break; case UN_BNOT: + out->constant.uval = ~lvalue.constant.uval; + break; case UN_DEREF: + assert(0); // TODO case UN_LNOT: + out->constant.bval = !lvalue.constant.bval; + break; case UN_MINUS: + out->constant.ival = -lvalue.constant.ival; + break; case UN_PLUS: - assert(0); // TODO + out->constant = lvalue.constant; + break; } return EVAL_OK;