Skip to content

Commit

Permalink
Fix delegate.jl for julia master
Browse files Browse the repository at this point in the history
  • Loading branch information
garrison committed Oct 14, 2017
1 parent 7d4da0d commit f4b28bf
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions src/delegate.jl
Original file line number Diff line number Diff line change
@@ -1,15 +1,27 @@
# by JMW; taken from DataStructures.jl

# See https://github.com/JuliaCollections/DataStructures.jl/commit/bb7b51f95a9ddc7582acb171486f150353c6e361
function unquote(e::Expr)
# For julia < 0.7
@assert e.head == :quote
return e.args[1]
end

function unquote(e::QuoteNode)
return e.value
end

macro delegate(source, targets)
typename = esc(source.args[1])
fieldname = esc(Expr(:quote, source.args[2].args[1]))
fieldname = unquote(source.args[2])
funcnames = targets.args
n = length(funcnames)
fdefs = Array{Any}(n)
fdefs = Vector{Any}(n)
for i in 1:n
funcname = esc(funcnames[i])
fdefs[i] = quote
($funcname)(a::($typename), args...) =
($funcname)(getfield(a, $fieldname), args...)
($funcname)(a.$fieldname, args...)
end
end
return Expr(:block, fdefs...)
Expand Down

0 comments on commit f4b28bf

Please sign in to comment.