Skip to content

Commit

Permalink
Merge pull request #57 from yuyichao/0.7
Browse files Browse the repository at this point in the history
Fix most of 0.7 depwarns and test errors
  • Loading branch information
MikeInnes authored Oct 3, 2017
2 parents 76c7ea9 + 8fe89d9 commit 469b56d
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 8 deletions.
1 change: 1 addition & 0 deletions REQUIRE
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
julia 0.6
Compat 0.30.0
1 change: 1 addition & 0 deletions src/MacroTools.jl
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
__precompile__(true)
module MacroTools

using Compat
export @match, @capture

include("match.jl")
Expand Down
13 changes: 7 additions & 6 deletions src/macro.jl
Original file line number Diff line number Diff line change
@@ -1,21 +1,22 @@
allbindings(pat, bs) =
isbinding(pat) || (isslurp(pat) && pat :__) ? push!(bs, bname(pat)) :
function allbindings(pat, bs)
if isa(pat, QuoteNode)
return allbindings(pat.value, bs)
end
return isbinding(pat) || (isslurp(pat) && pat :__) ? push!(bs, bname(pat)) :
isa(pat, TypeBind) ? push!(bs, pat.name) :
isa(pat, OrBind) ? (allbindings(pat.pat1, bs); allbindings(pat.pat2, bs)) :
istb(pat) ? push!(bs, tbname(pat)) :
isexpr(pat, :$) ? bs :
isa(pat, Expr) ? map(pat -> allbindings(pat, bs), [pat.head, pat.args...]) :
bs
end

allbindings(pat) = (bs = Any[]; allbindings(pat, bs); bs)

function bindinglet(bs, body)
ex = :(let $(esc(:env)) = env
ex = :(let $(esc(:env)) = env, $((:($(esc(b)) = get(env, $(Expr(:quote, b)), nothing)) for b in bs)...)
$body
end)
for b in bs
push!(ex.args, :($(esc(b)) = get(env, $(Expr(:quote, b)), nothing)))
end
return ex
end

Expand Down
4 changes: 2 additions & 2 deletions src/utils.jl
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ function inexpr(ex, x)
return result
end

global const animals = split(readstring(joinpath(dirname(@__FILE__), "..", "animals.txt")))
const animals = split(read(joinpath(dirname(@__FILE__), "..", "animals.txt"), String))

isgensym(s::Symbol) = contains(string(s), "#")
isgensym(s) = false
Expand All @@ -140,7 +140,7 @@ function alias_gensyms(ex)
end

# Helper function, from Compat. Use Base.macroexpand in 0.7
macroexpandmodule(mod::Module, x::ANY) = eval(mod, :(macroexpand($(QuoteNode(x)))))
macroexpandmodule(mod::Module, @nospecialize(x)) = eval(mod, :(macroexpand($(QuoteNode(x)))))

"""
More convenient macro expansion, e.g.
Expand Down

0 comments on commit 469b56d

Please sign in to comment.