~lbnz/xr0

93d30606c6c66af7b6bc08c53d49141888f15f39 — Amisi Kiarie a month ago 25810a4
feat: add case for bang to `expr_unary_eval`
3 files changed, 54 insertions(+), 4 deletions(-)

M include/value.h
M src/ast/expr/verify.c
M src/value/value.c
M include/value.h => include/value.h +3 -0
@@ 46,6 46,9 @@ int
value_int_up(struct value *);

struct value *
value_bang(struct value *);

struct value *
value_sync_create(struct ast_expr *);

struct value *

M src/ast/expr/verify.c => src/ast/expr/verify.c +14 -4
@@ 531,6 531,9 @@ static struct result *
address_eval(struct ast_expr *, struct state *);

static struct result *
bang_eval(struct ast_expr *, struct state *);

static struct result *
expr_unary_eval(struct ast_expr *expr, struct state *state)
{
	switch (ast_expr_unary_op(expr)) {


@@ 539,10 542,7 @@ expr_unary_eval(struct ast_expr *expr, struct state *state)
	case UNARY_OP_ADDRESS:
		return address_eval(expr, state);
	case UNARY_OP_BANG:
		/* XXX: hack because we stmt_exec pre as a preproces to verify
		 * constructors, this breaks any preconditions like: pre: !(p ==
		 * 0) */
		return result_value_create(value_literal_create("hack"));
		return bang_eval(expr, state);
	default:
		assert(false);
	}


@@ 624,6 624,16 @@ address_eval(struct ast_expr *expr, struct state *state)
}

static struct result *
bang_eval(struct ast_expr *expr, struct state *state)
{
	struct result *res = ast_expr_eval(ast_expr_unary_operand(expr), state);
	if (result_iserror(res)) {
		return res;
	}
	return result_value_create(value_bang(result_as_value(res)));
}

static struct result *
expr_structmember_eval(struct ast_expr *expr, struct state *s)
{
	struct ast_expr *root = ast_expr_member_root(expr);

M src/value/value.c => src/value/value.c +37 -0
@@ 146,6 146,20 @@ value_int_ne_create(int not_val)
	return v;
}

static struct value *
value_sync_bang(struct value *);

struct value *
value_bang(struct value *v)
{
	switch (v->type) {
	case VALUE_SYNC:
		return value_sync_bang(v);
	default:
		assert(false);
	}
}

struct number *
number_with_range_create(int lw, int excl_up);



@@ 205,6 219,19 @@ value_sync_create(struct ast_expr *e)
	return v;
}

static struct number *
number_computed_bang(struct number *);

static struct value *
value_sync_bang(struct value *orig)
{
	struct value *v = malloc(sizeof(struct value));
	assert(v);
	v->type = VALUE_SYNC;
	v->n = number_computed_bang(orig->n);
	return v;
}

struct value *
value_sync_copy(struct value *old)
{


@@ 826,6 853,16 @@ number_computed_create(struct ast_expr *e)
	return num;
}

static struct number *
number_computed_bang(struct number *orig)
{
	struct number *num = calloc(1, sizeof(struct number));
	num->type = NUMBER_COMPUTED;
	num->computation = ast_expr_inverted_copy(orig->computation, true);
	return num;
}


struct number_value *
number_value_min_create();