#include "object.h" #include #include #include #include #include #include void b_dsref_init(struct b_dsref *obj, struct b_dsref_type *type) { obj->ob_ref = 1; obj->ob_type = type; } struct b_dsref *b_make_rvalue(struct b_dsref *obj) { obj->ob_ref = 0; return obj; } struct b_dsref *b_retain(struct b_dsref *obj) { obj->ob_ref++; return obj; } void b_release(struct b_dsref *obj) { if (obj->ob_ref > 1) { obj->ob_ref--; return; } obj->ob_ref = 0; if (obj->ob_type && obj->ob_type->t_release) { obj->ob_type->t_release(obj); } free(obj); } void b_to_string(struct b_dsref *obj, struct b_stream *out) { if (obj->ob_type->t_to_string) { obj->ob_type->t_to_string(obj, out); return; } const char *name = "corelib::object"; if (obj->ob_type) { name = obj->ob_type->t_name; } b_stream_write_fmt(out, NULL, "<%s@%p>", name, obj); } b_dsref_type_id b_typeid(const struct b_dsref *obj) { if (obj->ob_type->t_flags & B_DSREF_FUNDAMENTAL) { return obj->ob_type->t_id; } return (b_dsref_type_id)obj->ob_type; }