Skip to content

Commit

Permalink
Merge pull request #587 from nmheim/ale/terminterface-new
Browse files Browse the repository at this point in the history
Get tests to pass in new TermInterface
  • Loading branch information
0x0f0f0f authored Mar 15, 2024
2 parents 4fa745b + dfed907 commit 89cffef
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/SymbolicUtils.jl
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ using SymbolicIndexingInterface
import Base: +, -, *, /, //, \, ^, ImmutableDict
using ConstructionBase
using TermInterface
import TermInterface: iscall, isexpr, issym, symtype, head, children, operation, arguments
import TermInterface: iscall, isexpr, issym, symtype, head, children, operation, arguments, metadata

function similarterm end
include("types.jl")
Expand Down
13 changes: 8 additions & 5 deletions src/types.jl
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ function arguments(x::BasicSymbolic)
end
return args
end
children(x::BasicSymbolic) = arguments(x)
function unsorted_arguments(x::BasicSymbolic)
@compactified x::BasicSymbolic begin
Term => return x.arguments
Expand Down Expand Up @@ -546,10 +547,12 @@ different type than `t`, because `f` also influences the result.
- The `symtype` of the resulting term. Best effort will be made to set the symtype of the
resulting similar term to this type.
"""
similarterm(t::Symbolic, f, args, symtype; metadata=nothing) =
maketerm(typeof(t), f, args, _promote_symtype(f, args), metadata)
similarterm(t::BasicSymbolic, f, args,
symtype; metadata=nothing) = basic_similarterm(t, f, args, symtype; metadata=metadata)
similarterm(t::Symbolic, f, args; metadata=nothing) =
maketerm(typeof(t), f, args, _promote_symtype(f, args); metadata)
similarterm(t::BasicSymbolic, f, args, symtype; metadata=nothing) =
maketerm(typeof(t), f, args, symtype; metadata=metadata)
maketerm(T::Type{<:Symbolic}, f, args, symtype; metadata=nothing) =
basic_similarterm(T, f, args, symtype; metadata=metadata)

function basic_similarterm(t, f, args, stype; metadata=nothing)
if f isa Symbol
Expand Down Expand Up @@ -813,7 +816,7 @@ function show_term(io::IO, t)
show_pow(io, args)
elseif f === (getindex)
show_ref(io, f, args)
elseif f === (identity) && !issym(args[1]) && iscall(args[1])
elseif f === (identity) && !issym(args[1]) && !iscall(args[1])
show(io, args[1])
else
show_call(io, f, args)
Expand Down
4 changes: 3 additions & 1 deletion src/utils.jl
Original file line number Diff line number Diff line change
Expand Up @@ -220,8 +220,10 @@ macro matchable(expr)
quote
$expr
SymbolicUtils.iscall(::$name) = true
SymbolicUtils.head(::$name) = $name
SymbolicUtils.operation(::$name) = $name
SymbolicUtils.arguments(x::$name) = getfield.((x,), ($(QuoteNode.(fields)...),))
SymbolicUtils.children(x::$name) = getfield.((x,), ($(QuoteNode.(fields)...),))
SymbolicUtils.arguments(x::$name) = SymbolicUtils.children(x)
Base.length(x::$name) = $(length(fields) + 1)
SymbolicUtils.similarterm(x::$name, f, args, type; kw...) = f(args...)
end |> esc
Expand Down

0 comments on commit 89cffef

Please sign in to comment.