~lbnz/xr0

c44a52dafdc9b34b21375a32c67960b17acd1754 — Amisi Kiarie 6 months ago 9ce0803
checkpoint
M include/value.h => include/value.h +4 -1
@@ 67,8 67,11 @@ value_str(struct value *);
enum value_type
value_type(struct value *);

bool
value_islocation(struct value *);

struct location *
value_as_ptr(struct value *);
value_as_location(struct value *);

bool
value_referencesheap(struct value *, struct state *);

M src/0v/object/object.c => src/0v/object/object.c +3 -3
@@ 181,7 181,7 @@ object_isdeallocand(struct object *obj, struct state *s)
{
	switch (obj->type) {
	case OBJECT_VALUE:
		return obj->value && state_isdeallocand(s, value_as_ptr(obj->value));
		return obj->value && state_isdeallocand(s, value_as_location(obj->value));
	case OBJECT_DEALLOCAND_RANGE:
		return range_isdeallocand(obj->range, s);
	default:


@@ 361,7 361,7 @@ object_upto(struct object *obj, struct ast_expr *excl_up, struct state *s)
		ast_expr_copy(obj->offset),
		range_create(
			ast_expr_difference_create(excl_up, lw),
			value_as_ptr(state_alloc(s))
			value_as_location(state_alloc(s))
		)
	);
}


@@ 405,7 405,7 @@ object_from(struct object *obj, struct ast_expr *incl_lw, struct state *s)
				up,
				ast_expr_copy(incl_lw)
			),
			value_as_ptr(state_alloc(s))
			value_as_location(state_alloc(s))
		)
	);
}

M src/0v/state/state.c => src/0v/state/state.c +9 -6
@@ 210,7 210,7 @@ state_getobject(struct state *state, char *id)
struct object *
state_deref(struct state *state, struct value *ptr_val, struct ast_expr *index)
{
	struct location *deref_base = value_as_ptr(ptr_val);
	struct location *deref_base = value_as_location(ptr_val);
	assert(deref_base);

	/* `*(ptr+offset)` */


@@ 231,7 231,7 @@ state_range_alloc(struct state *state, struct object *obj,
	}

	/* assume pointer */
	struct location *deref = value_as_ptr(arr_val);
	struct location *deref = value_as_location(arr_val);

	struct block *b = location_getblock(
		deref, state->vconst, state->stack, state->heap


@@ 256,7 256,10 @@ state_alloc(struct state *state)
struct error *
state_dealloc(struct state *state, struct value *val)
{
	return location_dealloc(value_as_ptr(val), state->heap);
	if (!value_islocation(val)) {
		return error_create("dealloc on non-location");
	}
	return location_dealloc(value_as_location(val), state->heap);
}




@@ 269,7 272,7 @@ state_range_dealloc(struct state *state, struct object *obj,
	if (!arr_val) {
		return error_create("no value");
	}
	struct location *deref = value_as_ptr(arr_val);
	struct location *deref = value_as_location(arr_val);
	return location_range_dealloc(deref, lw, up, state);
}



@@ 277,7 280,7 @@ bool
state_addresses_deallocand(struct state *state, struct object *obj)
{
	struct value *val = object_as_value(obj);
	struct location *loc = value_as_ptr(val); 
	struct location *loc = value_as_location(val); 
	
	return state_isdeallocand(state, loc);
}


@@ 303,7 306,7 @@ state_range_aredeallocands(struct state *state, struct object *obj,
	if (!arr_val) {
		return false;
	}
	struct location *deref = value_as_ptr(arr_val);
	struct location *deref = value_as_location(arr_val);
	
	struct block *b = location_getblock(
		deref, state->vconst, state->stack, state->heap

M src/0v/value/value.c => src/0v/value/value.c +8 -2
@@ 470,10 470,16 @@ value_str(struct value *v)
	return strbuilder_build(b);
}

bool
value_islocation(struct value *v)
{
	return v->type == VALUE_PTR && !v->ptr.isindefinite;
}

struct location *
value_as_ptr(struct value *v)
value_as_location(struct value *v)
{
	assert(v->type == VALUE_PTR && !v->ptr.isindefinite);
	assert(value_islocation(v));
	return v->ptr.loc;
}


M tests/0-basic/140-FAIL-sync-free.x.EXPECTED => tests/0-basic/140-FAIL-sync-free.x.EXPECTED +1 -0
@@ 0,0 1,1 @@
cannot exec statement: dealloc on non-location

M tests/3-program/100-lex/parse.x => tests/3-program/100-lex/parse.x +1 -1
@@ 7,7 7,7 @@
#define true 1

char *
read_file(char *path);
read_file(char *path) ~ [ .alloc result; ];

struct lexer;