From e7bcbf37fba5663bfa94d35a751df20d7acb5c27 Mon Sep 17 00:00:00 2001 From: jeaye Date: Sat, 17 Feb 2024 23:22:44 +0000 Subject: [PATCH] Improve function string representation --- .../cpp/jank/runtime/obj/native_function_wrapper.hpp | 2 +- src/cpp/jank/runtime/obj/jit_function.cpp | 9 +++++++-- src/cpp/jank/runtime/obj/native_function_wrapper.cpp | 12 ++++++++---- 3 files changed, 16 insertions(+), 7 deletions(-) diff --git a/include/cpp/jank/runtime/obj/native_function_wrapper.hpp b/include/cpp/jank/runtime/obj/native_function_wrapper.hpp index 51d8def90..d8742dba6 100644 --- a/include/cpp/jank/runtime/obj/native_function_wrapper.hpp +++ b/include/cpp/jank/runtime/obj/native_function_wrapper.hpp @@ -65,7 +65,7 @@ namespace jank::runtime /* behavior::objectable */ native_bool equal(object const &) const; - native_persistent_string const &to_string() const; + native_persistent_string to_string() const; void to_string(fmt::memory_buffer &buff) const; native_hash to_hash() const; diff --git a/src/cpp/jank/runtime/obj/jit_function.cpp b/src/cpp/jank/runtime/obj/jit_function.cpp index 5b11382ae..8767585e2 100644 --- a/src/cpp/jank/runtime/obj/jit_function.cpp +++ b/src/cpp/jank/runtime/obj/jit_function.cpp @@ -9,12 +9,17 @@ namespace jank::runtime native_persistent_string obj::jit_function::to_string() { - return "jit function"; + fmt::memory_buffer buff; + to_string(buff); + return native_persistent_string{ buff.data(), buff.size() }; } void obj::jit_function::to_string(fmt::memory_buffer &buff) { - fmt::format_to(std::back_inserter(buff), "jit_function"); + fmt::format_to(std::back_inserter(buff), + "{}@{}", + magic_enum::enum_name(base.type), + fmt::ptr(&base)); } native_hash obj::jit_function::to_hash() const diff --git a/src/cpp/jank/runtime/obj/native_function_wrapper.cpp b/src/cpp/jank/runtime/obj/native_function_wrapper.cpp index 1128cfc55..a659abf34 100644 --- a/src/cpp/jank/runtime/obj/native_function_wrapper.cpp +++ b/src/cpp/jank/runtime/obj/native_function_wrapper.cpp @@ -21,13 +21,17 @@ namespace jank::runtime void obj::native_function_wrapper::to_string(fmt::memory_buffer &buff) const { - fmt::format_to(std::back_inserter(buff), "function"); + fmt::format_to(std::back_inserter(buff), + "{}@{}", + magic_enum::enum_name(base.type), + fmt::ptr(&base)); } - native_persistent_string const &obj::native_function_wrapper::to_string() const + native_persistent_string obj::native_function_wrapper::to_string() const { - static native_persistent_string const s{ "native_function_wrapper" }; - return s; + fmt::memory_buffer buff; + to_string(buff); + return native_persistent_string{ buff.data(), buff.size() }; } native_hash obj::native_function_wrapper::to_hash() const