diff --git a/Project.toml b/Project.toml index 4414a1c6..bdb880ff 100644 --- a/Project.toml +++ b/Project.toml @@ -4,6 +4,7 @@ version = "0.12.1" [deps] FillArrays = "1a297f60-69ca-5386-bcde-b61e274b549b" +GroundEffects = "d00d4687-65cd-4fba-8fd9-ecb45a036ebe" LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e" MacroTools = "1914dd2f-81c6-5fcd-8719-6d5c9610ff09" StaticArrays = "90137ffa-7385-5640-81b9-e52037218182" diff --git a/src/lazymacro.jl b/src/lazymacro.jl index b4f15bb0..23d7a336 100644 --- a/src/lazymacro.jl +++ b/src/lazymacro.jl @@ -4,6 +4,7 @@ # and @chethega https://github.com/JuliaLang/julia/pull/30939 using MacroTools +using GroundEffects lazy(::Any) = throw(ArgumentError("function `lazy` exists only for its effect on broadcasting, see the macro @~")) struct LazyCast{T} @@ -13,12 +14,11 @@ Broadcast.broadcasted(::typeof(lazy), x) = LazyCast(x) Broadcast.materialize(x::LazyCast) = x.value -is_call(ex::Expr) = - ex.head == :call && !startswith(String(ex.args[1]), ".") +is_call(ex) = isexpr(ex, :call) && !is_dotcall(ex) -is_dotcall(ex::Expr) = - (ex.head == :. && ex.args[2].head === :tuple) || - (ex.head == :call && startswith(String(ex.args[1]), ".")) +is_dotcall(ex) = + (isexpr(ex, :.) && ex.args[2].head === :tuple) || + (isexpr(ex, :call) && ex.args[1] isa Symbol && startswith(String(ex.args[1]), ".")) # e.g., `f.(x, y, z)` or `x .+ y .+ z` lazy_expr(x) = x @@ -105,5 +105,6 @@ julia> @~ A * B + C macro ~(ex) checkex(ex) # Expanding macro here to support, e.g., `@.` - esc(:($instantiate($(lazy_expr(macroexpand(__module__, ex)))))) + lex = lazy_expr(GroundEffects.lower(macroexpand(__module__, ex))) + esc(:($instantiate($lex))) end