From 8fe89d9e62435498e47a254930f816143dc6ece7 Mon Sep 17 00:00:00 2001 From: Yichao Yu Date: Fri, 11 Aug 2017 22:49:16 -0400 Subject: [PATCH] Fix most of 0.7 depwarns and test errors --- REQUIRE | 1 + src/MacroTools.jl | 1 + src/macro.jl | 13 +++++++------ src/utils.jl | 4 ++-- 4 files changed, 11 insertions(+), 8 deletions(-) diff --git a/REQUIRE b/REQUIRE index 137767a..5c0d3d8 100644 --- a/REQUIRE +++ b/REQUIRE @@ -1 +1,2 @@ julia 0.6 +Compat 0.30.0 diff --git a/src/MacroTools.jl b/src/MacroTools.jl index 430ae3c..80a96af 100644 --- a/src/MacroTools.jl +++ b/src/MacroTools.jl @@ -1,6 +1,7 @@ __precompile__(true) module MacroTools +using Compat export @match, @capture include("match.jl") diff --git a/src/macro.jl b/src/macro.jl index 9545107..45bbcff 100644 --- a/src/macro.jl +++ b/src/macro.jl @@ -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 diff --git a/src/utils.jl b/src/utils.jl index 3cf8437..f6e1fd3 100644 --- a/src/utils.jl +++ b/src/utils.jl @@ -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 @@ -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.