Skip to content

Commit

Permalink
Improve function string representation
Browse files Browse the repository at this point in the history
  • Loading branch information
jeaye committed Feb 17, 2024
1 parent f48c8be commit e7bcbf3
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 7 deletions.
2 changes: 1 addition & 1 deletion include/cpp/jank/runtime/obj/native_function_wrapper.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
9 changes: 7 additions & 2 deletions src/cpp/jank/runtime/obj/jit_function.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 8 additions & 4 deletions src/cpp/jank/runtime/obj/native_function_wrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit e7bcbf3

Please sign in to comment.