Skip to content

Instantly share code, notes, and snippets.

@Roger-luo
Created April 9, 2021 04:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Roger-luo/241ee8ab360e91aefc5b8d45947050a5 to your computer and use it in GitHub Desktop.
Save Roger-luo/241ee8ab360e91aefc5b8d45947050a5 to your computer and use it in GitHub Desktop.
using Expronicon
using MLStyle
function expand_mlstyle(m::Module, ex)
@switch ex begin
@case Expr(:macrocall, Symbol("@match"), xs...) || Expr(:macrocall, Symbol("@switch"), xs...) ||
Expr(:macrocall, Symbol("@λ"), xs...)
return expand_mlstyle(m, macroexpand(m, ex))
@case ::Expr
return Expr(ex.head, map(x->expand_mlstyle(m, x), ex.args)...)
@case _
return ex
end
end
function expand_file(m::Module, file::String, build_dir="build")
src = read(file, String)
ex = Meta.parse("begin $src end")
dst = joinpath(build_dir, dirname(file))
ispath(dst) || mkpath(dst)
open(joinpath(build_dir, file), "w+") do io
ex = prettify(expand_mlstyle(m, ex))
if ex isa Expr && ex.head === :block && length(ex.args) == 1
ex = ex.args[1]
end
println(io, "Expronicon.eval(quote")
println(io, ex)
println(io, "end)")
end
end
expand_file(Expronicon, "src/analysis.jl")
expand_file(Expronicon, "src/codegen.jl")
# expand_file(Expronicon, "src/Expronicon.jl")
expand_file(Expronicon, "src/match.jl")
expand_file(Expronicon, "src/patches.jl")
expand_file(Expronicon, "src/printing.jl")
expand_file(Expronicon, "src/transform.jl")
expand_file(Expronicon, "src/types.jl")
cp("test", joinpath("build", "test"); force=true)
cp("Project.toml", joinpath("build", "Project.toml"); force=true)
src = read("src/match.jl", String)
ex = Meta.parse("begin $src end")
ex = prettify(ex)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment