Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Connection and StateMachineOperator should behave like scalars #1067

Merged
merged 4 commits into from
Feb 21, 2024
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
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 @@
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 @@

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 @@
_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 All @@ -56,7 +61,7 @@
priority)
end
end
function Base.:(==)(transtion1::Transition, transition2::Transition)

Check warning on line 64 in src/equations.jl

View workflow job for this annotation

GitHub Actions / Spell Check with Typos

"transtion" should be "transition".
transition1.from == transition2.from &&
transition1.to == transition2.to &&
isequal(transition1.cond, transition2.cond) &&
Expand Down
5 changes: 5 additions & 0 deletions src/struct.jl
Original file line number Diff line number Diff line change
Expand Up @@ -44,19 +44,19 @@
end

function decodetyp(typ::TypeT)
siz = TypeT(8) * (typ >> SIZE_OFFSET)

Check warning on line 47 in src/struct.jl

View workflow job for this annotation

GitHub Actions / Spell Check with Typos

"siz" should be "six" or "size".
if !iszero(typ & (TypeT(1) << ISINTEGER))
if !iszero(typ & TypeT(1) << SIGNED_OFFSET)
siz == 8 ? Int8 :

Check warning on line 50 in src/struct.jl

View workflow job for this annotation

GitHub Actions / Spell Check with Typos

"siz" should be "six" or "size".
siz == 16 ? Int16 :

Check warning on line 51 in src/struct.jl

View workflow job for this annotation

GitHub Actions / Spell Check with Typos

"siz" should be "six" or "size".
siz == 32 ? Int32 :

Check warning on line 52 in src/struct.jl

View workflow job for this annotation

GitHub Actions / Spell Check with Typos

"siz" should be "six" or "size".
siz == 64 ? Int64 :

Check warning on line 53 in src/struct.jl

View workflow job for this annotation

GitHub Actions / Spell Check with Typos

"siz" should be "six" or "size".
error("invalid type $(typ)!")
else # unsigned
siz == 8 ? UInt8 :

Check warning on line 56 in src/struct.jl

View workflow job for this annotation

GitHub Actions / Spell Check with Typos

"siz" should be "six" or "size".
siz == 16 ? UInt16 :

Check warning on line 57 in src/struct.jl

View workflow job for this annotation

GitHub Actions / Spell Check with Typos

"siz" should be "six" or "size".
siz == 32 ? UInt32 :

Check warning on line 58 in src/struct.jl

View workflow job for this annotation

GitHub Actions / Spell Check with Typos

"siz" should be "six" or "size".
siz == 64 ? UInt64 :

Check warning on line 59 in src/struct.jl

View workflow job for this annotation

GitHub Actions / Spell Check with Typos

"siz" should be "six" or "size".
error("invalid type $(typ)!")
end
else # float
Expand All @@ -72,6 +72,11 @@
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
Loading