Created
May 25, 2022 01:42
-
-
Save thautwarm/3db0de83efd8dfd0ab439cba80158b11 to your computer and use it in GitHub Desktop.
forward_def!
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using MLStyle: @switch | |
macro forward_def!(self_ann, expr, methods...) | |
@switch self_ann begin | |
@case :($self :: $t_base{$(t_args...)}) | |
@case :($self :: $t_base) && let t_args = [] end | |
end | |
t = if !isempty(t_args) | |
:($t_base{$(t_args...)}) | |
else | |
t_base | |
end | |
block = [] | |
for meth in methods | |
push!(block, :($Base.@inline $meth($self::$t, args...;kwargs...) where {$(t_args...)} = $meth($expr, args...; kwargs...))) | |
end | |
esc(Expr(:block, block...)) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment