Last active
January 3, 2018 15:40
-
-
Save SimonDanisch/5bb003514d145288c921ef851d608a5d to your computer and use it in GitHub Desktop.
This file contains hidden or 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
# Modular pass manager: | |
context = ExecutionContext() | |
# adds a predefined function from Sugar as a pass. | |
# this one takes care of e.g.: | |
# * turning Expr(:invoke, args...) into Expr(:call, args...) | |
# * removes apply_type | |
# * turn all functions into GlobalRef | |
# * etc | |
add_pass!(context, ast_normalization) | |
# turn gotos into if/else/while/for | |
add_pass!(context, remove_goto) | |
# Custom pass with Matcha like matching. | |
add_pass!(context, x-> match_head(x, :static_parameter)) do context, expr | |
param = context.sparams[expr.args[1]] | |
specialized_typeof(param) | |
end | |
using Cassette | |
function fortest(a) | |
l = 0 | |
for i=1:a | |
l += 1 | |
end | |
l | |
end | |
Cassette.@context LolCTX | |
function Cassette.getpass(::Type{<: LolCTX}, M) | |
function (sig, body) | |
push!(body.code, :(println($(QuoteNode(body.code))))) | |
body | |
end | |
end | |
Cassette.overdub(LolCTX, fortest)(1) | |
# MacroTools like matching | |
add_pass!(context, :(a_ + b_) => :(a - b)) | |
ast = getast(context, func, args; optimize = true) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment