Created
May 31, 2018 21:01
-
-
Save TsurHerman/2ec94d5bc6a361bef79f74aa71aa2740 to your computer and use it in GitHub Desktop.
Help with a macro
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
abstract type ContextCall{FN,MOD,C} end | |
abstract type Context{C} end | |
Context{C}(x) where C = x | |
# desired output for macro | |
# @mfunction AAA(a::Int64,b::Int64) = a+b | |
# | |
@generated ContextCall{:AAA,:Main,C}(a::Int64,b::Int64) where C = begin | |
code = quote | |
a+b | |
end | |
Context{C}(code) | |
end | |
ContextCall{:AAA,:Main,Any}(1,2) #3 | |
################################################ | |
#my groping in the dark | |
using MacroTools | |
using MacroTools: combinedef | |
D = splitdef(:(AAB(a::Int64,b::Int64) = a+b)) | |
mod = current_module() | |
MOD = module_name(mod) | |
FN = D[:name] | |
D[:name] = Symbol("ContextCall{:$FN,:$MOD,C}") | |
D[:whereparams] = (:C,) | |
body = deepcopy(D[:body]) | |
body = "code = quote $body end;Context{C}(code)" | |
D[:body] = parse(body) | |
A = sprint(print,:(@generated $(combinedef(D)))) | |
parse(A) | |
eval(parse(A)) | |
ContextCall{:AAB,:Main,Any}(1,2) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment