Skip to content

Commit

Permalink
Minor improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
YingboMa committed Feb 9, 2024
1 parent eba000f commit ce7c201
Showing 1 changed file with 19 additions and 2 deletions.
21 changes: 19 additions & 2 deletions src/equations.jl
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,14 @@ end
###
### State machine
###
_nameof(s) = nameof(s)
_nameof(s::Union{Int, Symbol}) = s
abstract type StateMachineOperator end
hide_lhs(_::StateMachineOperator) = true
struct InitialState <: StateMachineOperator
s
end
Base.show(io::IO, s::InitialState) = print(io, "initial_state(", nameof(s.s), ")")
Base.show(io::IO, s::InitialState) = print(io, "initial_state(", _nameof(s.s), ")")
initial_state(s) = Equation(InitialState(nothing), InitialState(s))

Base.@kwdef struct Transition{A, B, C} <: StateMachineOperator
Expand All @@ -47,6 +49,21 @@ Base.@kwdef struct Transition{A, B, C} <: StateMachineOperator
reset::Bool = true
synchronize::Bool = false
priority::Int = 1
function Transition(from, to, cond, immediate, reset, synchronize, priority)
cond = unwrap(cond)
new{typeof(from), typeof(to), typeof(cond)}(from, to, cond, immediate,
reset, synchronize,
priority)
end
end
function Base.:(==)(transtion1::Transition, transition2::Transition)

Check warning on line 59 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) &&
transition1.immediate == transition2.immediate &&
transition1.reset == transition2.reset &&
transition1.synchronize == transition2.synchronize &&
transition1.priority == transition2.priority
end
function transition(from, to, cond;
immediate::Bool = true, reset::Bool = true, synchronize::Bool = false,
Expand All @@ -55,7 +72,7 @@ function transition(from, to, cond;
synchronize, priority))
end
function Base.show(io::IO, s::Transition)
print(io, nameof(s.from), "", nameof(s.to), " [")
print(io, _nameof(s.from), "", _nameof(s.to), " [")
print(io, "immediate: ", s.immediate, ", ")
print(io, "reset: ", s.reset, ", ")
print(io, "synchronize: ", s.synchronize, ", ")
Expand Down

0 comments on commit ce7c201

Please sign in to comment.