~lbnz/xr0

25810a49f5d587bbf1e9b51b5679056d185637fa — Amisi Kiarie 6 months ago 1e3c83d
chore: add `a_printf`, macro to assert and printf if false
2 files changed, 4 insertions(+), 1 deletions(-)

M include/util.h
M src/object/object.c
M include/util.h => include/util.h +3 -0
@@ 108,6 108,9 @@ d_printf(char *fmt, ...);
int
v_printf(char *fmt, ...);

/* a_printf: assert and print as appropriate if there is an error. */
#define a_printf(expr, ...) if (!expr) { fprintf(stderr, __VA_ARGS__); assert(false); }

struct error;

struct error *

M src/object/object.c => src/object/object.c +1 -1
@@ 468,7 468,7 @@ getorcreatestruct(struct object *obj, struct ast_type *t, struct state *s)
		return v;
	}
	struct ast_type *complete = ast_type_struct_complete(t, state_getext(s));
	assert(complete);
	a_printf(complete, "%s is incomplete\n", ast_type_str(t));
	v = value_struct_create(complete);
	object_assign(obj, v);
	return v;