From 852ff838af56ef3668ff94c27b0140869dcb7359 Mon Sep 17 00:00:00 2001 From: Kimplul Date: Wed, 14 Aug 2024 18:51:28 +0300 Subject: allow adding traits to pointers + Should be enough to fairly easily use pointers in standard containers. Note that this just uses the pointer value itself, and doesn't care about the underlying type at all. So for example a sorted vector of pointers is sorted by the address, not by some comparison function that the underlying type may have defined. For that you will need a wrapper struct or something. --- src/debug.c | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) (limited to 'src/debug.c') diff --git a/src/debug.c b/src/debug.c index 47e53f2..92d85d2 100644 --- a/src/debug.c +++ b/src/debug.c @@ -218,6 +218,22 @@ void internal_warn(const char *fmt, ...) va_end(args); } +static void _type_str(FILE *fp, struct type *type); + +static void _type_list_str(FILE *fp, struct type *types) +{ + if (!types) + return; + + _type_str(fp, types); + + types = types->n; + foreach_type(t, types) { + fprintf(fp, ", "); + _type_str(fp, t); + } +} + /** * Workhorse for type_str(). * @@ -263,6 +279,15 @@ static void _type_str(FILE *fp, struct type *type) break; } + case TYPE_CALLABLE: { + fputc('(', fp); + _type_list_str(fp, callable_ptypes(type)); + fprintf(fp, " => "); + _type_str(fp, callable_rtype(type)); + fputc(')', fp); + break; + } + default: if (is_primitive(type)) fprintf(fp, "%s", primitive_str(type)); -- cgit v1.3