Skip to content

Commit

Permalink
Implement better printing (#7)
Browse files Browse the repository at this point in the history
* Implement better show

* Bump patch version
  • Loading branch information
willtebbutt authored Aug 21, 2024
1 parent 5322b32 commit dba69bc
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 1 deletion.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "MistyClosures"
uuid = "dbe65cb8-6be2-42dd-bbc5-4196aaced4f4"
authors = ["Will Tebbutt", "Frames White", "Hong Ge"]
version = "1.0.1"
version = "1.0.2"

[compat]
julia = "1.10"
Expand Down
12 changes: 12 additions & 0 deletions src/MistyClosures.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ module MistyClosures
using Core: OpaqueClosure
using Core.Compiler: IRCode

import Base: show

struct MistyClosure{Toc<:OpaqueClosure}
oc::Toc
ir::IRCode
Expand All @@ -17,6 +19,16 @@ function Base.deepcopy_internal(x::T, dict::IdDict) where {T<:MistyClosure}
return T(Base.deepcopy_internal(x.oc, dict), x.ir)
end

# Don't print out the IRCode object, because this tends to pollute the REPL. Just make it
# clear that this is a MistyClosure, which contains an OpaqueClosure.
show(io::IO, mime::MIME"text/plain", mc::MistyClosure) = _show_misty_closure(io, mime, mc)
show(io::IO, mc::MistyClosure) = _show_misty_closure(io, MIME"text/plain"(), mc)

function _show_misty_closure(io::IO, mime::MIME"text/plain", mc::MistyClosure)
print(io, "MistyClosure ")
show(io, mime, mc.oc)
end

export MistyClosure

end
5 changes: 5 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,9 @@ using Core: OpaqueClosure

# deepcopy
@test deepcopy(mc) isa typeof(mc)

# printing -- we shouldn't see the IRCode, because it's often quite a lot.
io = IOBuffer()
show(io, mc)
@test String(take!(io)) == "MistyClosure (::Float64)::Float64->◌"
end

2 comments on commit dba69bc

@willtebbutt
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/113604

Tip: Release Notes

Did you know you can add release notes too? Just add markdown formatted text underneath the comment after the text
"Release notes:" and it will be added to the registry PR, and if TagBot is installed it will also be added to the
release that TagBot creates. i.e.

@JuliaRegistrator register

Release notes:

## Breaking changes

- blah

To add them here just re-invoke and the PR will be updated.

Tagging

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v1.0.2 -m "<description of version>" dba69bc29aaefde2501dba1a9e370fb7346e05c6
git push origin v1.0.2

Please sign in to comment.