From 09737aa40b0e00be0068b5d05d00e604e9194a58 Mon Sep 17 00:00:00 2001 From: John Date: Fri, 1 Mar 2024 02:47:07 -0600 Subject: [PATCH] temp_type_impl: pretty-print functions --- cl-interpret/src/lib.rs | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/cl-interpret/src/lib.rs b/cl-interpret/src/lib.rs index 7d2fd6d..b5e9b41 100644 --- a/cl-interpret/src/lib.rs +++ b/cl-interpret/src/lib.rs @@ -282,7 +282,9 @@ pub mod temp_type_impl { ')'.fmt(f) } ConValue::Function(func) => { - write!(f, "fn {}", func.name()) + use cl_ast::format::*; + use std::fmt::Write; + write!(f.pretty(), "{}", func.decl()) } ConValue::BuiltIn(func) => { write!(f, "{}", func.description()) @@ -311,6 +313,9 @@ pub mod function { pub fn new(decl: &FnDecl) -> Self { Self { decl: decl.clone().into() } } + pub fn decl(&self) -> &FnDecl { + &self.decl + } } impl Callable for Function { @@ -592,7 +597,11 @@ pub mod error { write!(f, "{value} is not callable.") } Error::ArgNumber { want, got } => { - write!(f, "Expected {want} arguments, got {got}") + write!( + f, + "Expected {want} argument{}, got {got}", + if *want == 1 { "" } else { "s" } + ) } Error::NullPointer => { write!(f, "Attempted to dereference a null pointer?")