From 3bada4560e534a9c52e1922a1dbaf241aea798b8 Mon Sep 17 00:00:00 2001 From: Christoffer Lerno Date: Wed, 18 Sep 2024 14:53:55 +0200 Subject: [PATCH] Correctly print interfaces. --- lib/std/core/allocators/libc_allocator.c3 | 7 ++++++- lib/std/io/formatter.c3 | 4 ++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/lib/std/core/allocators/libc_allocator.c3 b/lib/std/core/allocators/libc_allocator.c3 index 8389c6c19..0a18551fa 100644 --- a/lib/std/core/allocators/libc_allocator.c3 +++ b/lib/std/core/allocators/libc_allocator.c3 @@ -3,15 +3,20 @@ // a copy of which can be found in the LICENSE_STDLIB file. module std::core::mem::allocator @if(env::LIBC); +import std::io; import libc; const LibcAllocator LIBC_ALLOCATOR = {}; -distinct LibcAllocator (Allocator) = uptr; +distinct LibcAllocator (Allocator, Printable) = uptr; + +fn String LibcAllocator.to_string(&self, Allocator allocator) @dynamic => "Libc allocator".copy(allocator); +fn usz! LibcAllocator.to_format(&self, Formatter *format) @dynamic => format.print("Libc allocator"); module std::core::mem::allocator @if(env::POSIX); import std::os; import libc; + fn void*! LibcAllocator.acquire(&self, usz bytes, AllocInitType init_type, usz alignment) @dynamic { if (init_type == ZERO) diff --git a/lib/std/io/formatter.c3 b/lib/std/io/formatter.c3 index 69cd8ebcb..b5fcfabfe 100644 --- a/lib/std/io/formatter.c3 +++ b/lib/std/io/formatter.c3 @@ -117,6 +117,7 @@ fn usz! Formatter.out_str(&self, any arg) @private case ANYFAULT: case FAULT: return self.out_substr((*(anyfault*)arg.ptr).nameof); + case INTERFACE: case ANY: return self.out_str(*(any*)arg); case OPTIONAL: @@ -282,6 +283,9 @@ fn usz! Formatter.out_str(&self, any arg) @private } len += self.out(']')!; return len; + case ANY: + case INTERFACE: + unreachable("Already handled"); default: } return self.out_substr("Invalid type");