diff --git a/Project.toml b/Project.toml index b455ac9..51a70fb 100644 --- a/Project.toml +++ b/Project.toml @@ -3,8 +3,12 @@ uuid = "8ea1fca8-c5ef-4a55-8b96-4e9afe9c9a3c" authors = ["Shashi Gowda ", "Alessandro Cheli "] version = "2.0" +[deps] +PrecompileTools = "aea7be01-6a6a-4083-8856-8a6e6704d82a" + [compat] julia = "1" +PrecompileTools = "1" Test = "1" [extras] diff --git a/src/TermInterface.jl b/src/TermInterface.jl index 78b22c0..f83b473 100644 --- a/src/TermInterface.jl +++ b/src/TermInterface.jl @@ -1,5 +1,7 @@ module TermInterface +using PrecompileTools: @compile_workload + """ isexpr(x) Returns `true` if `x` is an expression tree. If true, `head(x)` and `children(x)` methods must be defined for `x`. @@ -171,5 +173,21 @@ include("utils.jl") include("expr.jl") -end # module +@compile_workload begin + ex = :(f(g(x), y)) + isexpr(ex) + iscall(ex) + head(ex) + children(ex) + sorted_children(ex) + operation(ex) + arguments(ex) + sorted_arguments(ex) + arity(ex) + metadata(ex) + maketerm(Expr, head(ex), children(ex), nothing) + is_operation(:f)(ex) + node_count(ex) +end +end # module diff --git a/test/runtests.jl b/test/runtests.jl index ef48422..d74c3d6 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -9,6 +9,11 @@ using Test @test arguments(ex) == [:a, :b] @test isexpr(ex) @test iscall(ex) + @test arity(ex) == 2 + @test metadata(ex) === nothing + @test is_operation(:f)(ex) + @test !is_operation(:g)(ex) + @test node_count(ex) == 4 @test ex == maketerm(Expr, :call, [:f, :a, :b], nothing) @@ -23,8 +28,8 @@ end @testset "Unsorted arguments" begin struct Sum - d::Dict{Int,Any} - Sum(xs...) = new(Dict{Int,Any}(xs...)) + d::Dict{Int, Any} + Sum(xs...) = new(Dict{Int, Any}(xs...)) end TermInterface.isexpr(s::Sum) = true @@ -44,4 +49,4 @@ end @test sorted_arguments(s) == [:(1A), :(2B), :(3C)] @test sorted_children(s) == sorted_arguments(s) -end \ No newline at end of file +end