package machineimport ()// Mutation represents an atomic change (or an attempt) of machine's active// states. Mutation causes a Transition.typeMutationstruct {// add, set, remove Type MutationType// States explicitly passed to the mutation method, as their indexes. Use // Transition.CalledStates or IndexToStates to get the actual state names. Called []int// argument map passed to the mutation method (if any). Args A// this mutation has been triggered by an auto state // TODO rename to IsAuto IsAuto bool// Source is the source event for this mutation. Source *MutSource// IsCheck indicates that this mutation is a check, see [Machine.CanAdd]. IsCheck bool// optional queue info// QueueTickNow is the queue tick during which this mutation was scheduled. QueueTickNow uint64// QueueLen is the length of the queue at the time when the mutation was // queued. QueueLen int32// QueueTokensLen is the amount of unexecuted queue tokens (priority queue). // TODO impl QueueTokensLen int32// QueueTick is the assigned queue tick at the time when the mutation was // queued. 0 for prepended mutations. QueueTick uint64// QueueToken is a unique ID, which is given to prepended mutations. // Tokens are assigned in a series but executed in random order. QueueToken uint64// internals// specific context for this mutation (optional) ctx context.Context// optional eval func, only for mutationEval eval func() evalSource string cacheCalled atomic.Pointer[S]}func ( *Mutation) () string {returnfmt.Sprintf("[%s] %v", .Type, .Called)}func ( *Mutation) ( int) bool {returnslices.Contains(.Called, )}func ( *Mutation) ( S) *TimeIndex {returnNewTimeIndex(, .Called)}func ( *Mutation) ( S) string { := NewTimeIndex(, .Called)return"[" + .Type.String() + "] " + j(.ActiveStates(nil))}// MapArgs returns arguments of this Mutation which match the passed [mapper].// The returned map is never nil.func ( *Mutation) ( LogArgsMapperFn) map[string]string {if == nil {returnmap[string]string{} }if := (.Args); == nil {returnmap[string]string{} } else {return }}// LogArgs returns a text snippet with arguments which should be logged for this// Mutation.func ( *Mutation) ( LogArgsMapperFn) string {returnMutationFormatArgs(.MapArgs())}// StepType enumtypeStepTypeint8const (StepRelationStepType = 1 << iotaStepHandler// TODO rename to StepActivateStepSet// StepRemove indicates a step where a state goes active->inactive // TODO rename to StepDeactivateStepRemove// StepRemoveNotActive indicates a step where a state goes inactive->inactive // TODO rename to StepDeactivatePassiveStepRemoveNotActiveStepRequestedStepCancel)func ( StepType) () string {switch {caseStepRelation:return"rel"caseStepHandler:return"handler"caseStepSet:return"activate"caseStepRemove:return"deactivate"caseStepRemoveNotActive:return"deactivate-passive"caseStepRequested:return"requested"caseStepCancel:return"cancel" }return""}// Step struct represents a single step within a Transition, either a relation// resolving step or a handler call.typeStepstruct { Type StepType// Only for Type == StepRelation. RelType Relation// marks a final handler (FooState, FooEnd) IsFinal bool// marks a self handler (FooFoo) IsSelf bool// marks an enter handler (FooState, but not FooEnd). Requires IsFinal. IsEnter bool// Deprecated, use GetFromState(). TODO remove FromState string// TODO implement FromStateIdx int// Deprecated, use GetToState(). TODO remove ToState string// TODO implement ToStateIdx int// Deprecated, use RelType. TODO remove Data any// TODO emitter name and num}// GetFromState returns the source state of a step. Optional, unless no// GetToState().func ( *Step) ( S) string {// TODO rename to FromStateif .FromState != "" {return .FromState }if .FromStateIdx == -1 {return"" }if .FromStateIdx < len() {return [.FromStateIdx] }return""}// GetToState returns the target state of a step. Optional, unless no// GetFromState().func ( *Step) ( S) string {// TODO rename to ToStateif .ToState != "" {return .ToState }if .ToStateIdx == -1 {return"" }if .ToStateIdx < len() {return [.ToStateIdx] }return""}func ( *Step) ( S) string {varstring// collect := .GetFromState() := .GetToState()if == "" && == "" { = StateAny }// format TODO markdown?if != "" { = "**" + + "**" }if != "" { = "**" + + "**" }// outputif != "" && != "" { += + " " + .RelType.String() + " " + } else { = }if == "" { = }if .Type == StepRelation {return } := ""if .Type == StepHandler {if .IsSelf { = } elseif .IsFinal && .IsEnter { = SuffixState } elseif .IsFinal && !.IsEnter { = SuffixEnd } elseif !.IsFinal && .IsEnter { = SuffixEnter } elseif !.IsFinal && !.IsEnter { = SuffixExit } }// infer the namereturn .Type.String() + " " + + }func newStep( string, string, StepType,Relation,) *Step { := &Step{// TODO refac with the new dbg protocol, use indexes onlyFromState: ,ToState: ,Type: ,RelType: , }// default values TODO use real valuesif == "" { .FromStateIdx = -1 }if == "" { .ToStateIdx = -1 }return}func newSteps( string, S, StepType,Relation,) []*Step {// TODO optimize, only use during debugvar []*Stepfor , := range { = append(, newStep(, , , )) }return}
The pages are generated with Goldsv0.8.2. (GOOS=linux GOARCH=amd64)
Golds is a Go 101 project developed by Tapir Liu.
PR and bug reports are welcome and can be submitted to the issue list.
Please follow @zigo_101 (reachable from the left QR code) to get the latest news of Golds.