Skip to content

Commit

Permalink
Merge pull request #1067 from JuliaSymbolics/myb/tracing
Browse files Browse the repository at this point in the history
Connection and StateMachineOperator should behave like scalars
  • Loading branch information
YingboMa authored Feb 21, 2024
2 parents 696268d + 450414a commit ee96f0b
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
15 changes: 10 additions & 5 deletions src/equations.jl
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ hide_lhs(_) = false
struct Connection
systems
end
Base.broadcastable(x::Connection) = Ref(x)
Connection() = Connection(nothing)
Base.hash(c::Connection, seed::UInt) = hash(c.systems, (0xc80093537bdc1311 % UInt) seed)
hide_lhs(_::Connection) = true

function connect(sys1, sys2, syss...)
Expand All @@ -19,11 +21,13 @@ end

function Base.show(io::IO, c::Connection)
print(io, "connect(")
n = length(c.systems)
for (i, s) in enumerate(c.systems)
str = join(split(string(nameof(s)), NAMESPACE_SEPARATOR), '.')
print(io, str)
i != n && print(io, ", ")
if c.systems isa AbstractArray
n = length(c.systems)
for (i, s) in enumerate(c.systems)
str = join(split(string(nameof(s)), NAMESPACE_SEPARATOR), '.')
print(io, str)
i != n && print(io, ", ")
end
end
print(io, ")")
end
Expand All @@ -34,6 +38,7 @@ end
_nameof(s) = nameof(s)
_nameof(s::Union{Int, Symbol}) = s
abstract type StateMachineOperator end
Base.broadcastable(x::StateMachineOperator) = Ref(x)
hide_lhs(_::StateMachineOperator) = true
struct InitialState <: StateMachineOperator
s
Expand Down
5 changes: 5 additions & 0 deletions src/struct.jl
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,11 @@ struct Struct <: Real
v::Vector{StructElement}
end

function Base.hash(x::Struct, seed::UInt)
h1 = hash(juliatype(x), seed)
h2 = foldr(hash, getelements(x), init = h1)
h2 (0x0e39036b7de2101a % UInt)
end

"""
symstruct(T)
Expand Down

0 comments on commit ee96f0b

Please sign in to comment.