Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,12 @@ uuid = "8ea1fca8-c5ef-4a55-8b96-4e9afe9c9a3c"
authors = ["Shashi Gowda <gowda@mit.edu>", "Alessandro Cheli <sudo-woodo3@protonmail.com>"]
version = "2.0"

[deps]
PrecompileTools = "aea7be01-6a6a-4083-8856-8a6e6704d82a"

[compat]
julia = "1"
PrecompileTools = "1"
Test = "1"

[extras]
Expand Down
20 changes: 19 additions & 1 deletion src/TermInterface.jl
Original file line number Diff line number Diff line change
@@ -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`.
Expand Down Expand Up @@ -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
11 changes: 8 additions & 3 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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)


Expand All @@ -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
Expand All @@ -44,4 +49,4 @@ end

@test sorted_arguments(s) == [:(1A), :(2B), :(3C)]
@test sorted_children(s) == sorted_arguments(s)
end
end
Loading