private object EasyChecks_Pulse(IRuntime runtime, int myId, Message message)
 {
     // item 1980001
     if (N == 0)
     {
         // item 215
         ReportPrimes(
             runtime,
             Primes,
             N,
             Client
             );
         // item 156
         Shutdown();
         return(null);
     }
     else
     {
         // item 1980002
         if (N == 1)
         {
             // item 211
             Primes.Add(1);
             // item 215
             ReportPrimes(
                 runtime,
                 Primes,
                 N,
                 Client
                 );
             // item 156
             Shutdown();
             return(null);
         }
         else
         {
             // item 1980003
             if (N == 2)
             {
                 // item 209
                 Primes.Add(1);
                 Primes.Add(2);
                 // item 215
                 ReportPrimes(
                     runtime,
                     Primes,
                     N,
                     Client
                     );
                 // item 156
                 Shutdown();
                 return(null);
             }
             else
             {
                 // item 1980004
                 if (N < 0)
                 {
                     // item 220
                     runtime.SendMessage(
                         Client,
                         CallResult.Error,
                         new ArgumentException(
                             "N",
                             "Negative argument"),
                         myId
                         );
                     // item 156
                     Shutdown();
                     return(null);
                 }
                 else
                 {
                     // item 269
                     Primes.Add(1);
                     Primes.Add(2);
                     Primes.Add(3);
                     // item 216
                     Current = 5;
                     J       = 3;
                     // item 214
                     State = StateNames.Calculation;
                     return(null);
                 }
             }
         }
     }
 }
Example #2
0
 public void CleanUp(IRuntime runtime, int myId) {
     if (CurrentState == StateNames.Deleted) {
         return;
     }
     CurrentState = StateNames.Deleted;
     
 }
 private object Working_default(IRuntime runtime, int myId, Message message)
 {
     // item 856
     State = StateNames.Working;
     return(null);
 }
Example #4
0
 private void Number_Letter(IRuntime runtime, int myId, Message message) {
     // item 391
     AddChar(Data, message.C);
     // item 394
     CurrentState = StateNames.Number;
 }
Example #5
0
 private void Operator_Whitespace(IRuntime runtime, int myId, Message message) {
     // item 414
     CreateOperator(Data);
     // item 341
     CurrentState = StateNames.Idle;
 }
Example #6
0
 private void Operator_Operator(char c) {
     // item 295
     if (TryMakeLongOperator(Data, c)) {
         // item 298
         CurrentState = StateNames.Idle;
     } else {
         // item 299
         CreateOperator(Data);
         // item 288
         AddChar(Data, c);
         // item 291
         CurrentState = StateNames.Operator;
     }
 }
Example #7
0
 private void Identifier_Letter(IRuntime runtime, int myId, Message message) {
     // item 374
     AddChar(Data, message.C);
     // item 377
     CurrentState = StateNames.Identifier;
 }
Example #8
0
 private object Sleepy_Food(int msg)
 {
     State = StateNames.Sleepy;
     return("na...");
 }
Example #9
0
 private object Sleepy_Sleep(int msg)
 {
     State = StateNames.Hungry;
     return("z-z-z...");
 }
Example #10
0
 private object Hungry_Food(int msg)
 {
     State = StateNames.Sleepy;
     return("yam-yam");
 }
Example #11
0
 private object Hungry_Sleep(int msg)
 {
     State = StateNames.Hungry;
     return("I am hungry");
 }
 private object Calculation_default(IRuntime runtime, int myId, Message message)
 {
     // item 178
     State = StateNames.Calculation;
     return(null);
 }
            private object Calculation_Pulse(IRuntime runtime, int myId, Message message)
            {
                // item 1790001
                int i = 0;

                while (true)
                {
                    // item 1790002
                    if (i < ChunkSize)
                    {
                    }
                    else
                    {
                        // item 159
                        State = StateNames.Calculation;
                        return(null);
                    }
                    // item 193
                    if (Current > N)
                    {
                        // item 230
                        ReportPrimes(
                            runtime,
                            Primes,
                            N,
                            Client
                            );
                        // item 195
                        Shutdown();
                        return(null);
                    }
                    else
                    {
                    }
                    // item 181
                    if (J * J > Current)
                    {
                        // item 192
                        Primes.Add(Current);
                        // item 190
                        J        = 3;
                        Current += 2;
                    }
                    else
                    {
                        // item 185
                        if (Current % J == 0)
                        {
                            // item 190
                            J        = 3;
                            Current += 2;
                        }
                        else
                        {
                            // item 184
                            J += 2;
                        }
                    }
                    // item 1790003
                    i++;
                }
            }
 private object EasyChecks_default(IRuntime runtime, int myId, Message message)
 {
     // item 170
     State = StateNames.EasyChecks;
     return(null);
 }
Example #15
0
 private void Number_dummy(char c) {
     // item 274
     CurrentState = StateNames.Operator;
 }
Example #16
0
 private object Idle_Whitespace(char c)
 {
     State = StateNames.Idle;
     return(null);
 }
Example #17
0
 private void Operator_Letter(char c) {
     // item 293
     CreateOperator(Data);
     // item 286
     AddChar(Data, c);
     // item 289
     CurrentState = StateNames.Identifier;
 }
Example #18
0
 private object Idle_Letter(char c)
 {
     AddChar(this, c);
     State = StateNames.Identifier;
     return(null);
 }
Example #19
0
 private void Idle_Operator(IRuntime runtime, int myId, Message message) {
     // item 361
     AddChar(Data, message.C);
     // item 364
     CurrentState = StateNames.Operator;
 }
Example #20
0
 private object Idle_Operator(char c)
 {
     AddChar(this, c);
     State = StateNames.Operator;
     return(null);
 }
Example #21
0
 private void Identifier_Operator(IRuntime runtime, int myId, Message message) {
     // item 381
     CreateIdentifier(Data);
     // item 376
     AddChar(Data, message.C);
     // item 379
     CurrentState = StateNames.Operator;
 }
Example #22
0
 private object Identifier_Whitespace(char c)
 {
     CreateIdentifier(this);
     State = StateNames.Idle;
     return(null);
 }
Example #23
0
 private void Number_Operator(IRuntime runtime, int myId, Message message) {
     // item 398
     CreateNumber(Data);
     // item 393
     AddChar(Data, message.C);
     // item 396
     CurrentState = StateNames.Operator;
 }
Example #24
0
 private object Identifier_Digit(char c)
 {
     AddChar(this, c);
     State = StateNames.Identifier;
     return(null);
 }
Example #25
0
 private void Operator_Digit(IRuntime runtime, int myId, Message message) {
     // item 416
     CreateOperator(Data);
     // item 409
     AddChar(Data, message.C);
     // item 412
     CurrentState = StateNames.Number;
 }
Example #26
0
 private object Number_Whitespace(char c)
 {
     CreateNumber(this);
     State = StateNames.Idle;
     return(null);
 }
Example #27
0
 private object Init_default(IRuntime runtime, int myId, Message message)
 {
     // item 783
     State = StateNames.Init;
     return(null);
 }
Example #28
0
 private object Number_Digit(char c)
 {
     AddChar(this, c);
     State = StateNames.Number;
     return(null);
 }
Example #29
0
        /// <summary>
        /// Invoked to execute the state machine.
        /// </summary>
        /// <param name="e">Provides an optional event type to post at normal priority before starting execution</param>
        /// <returns>A value of type R</returns>
        /// <exception cref="System.InvalidOperationException">Thrown if an event is chosen for
        /// execution and no transition from the current state maches the event.
        /// </exception>
        /// <exception cref="EnteredErrorStateException">Thrown if execution enters an error state</exception>
        /// <remarks>
        /// The state machine runs until one of the following conditions is met:
        /// - There are no remaining events to process
        /// - A stop or error state is entered
        /// - An event is encountered and no transition matches the event type
        /// - An action raises an exception
        /// For each state, the next event to be processed is chosen from the head of the
        /// internal event queue, and if no event is found, then the external event queue.
        /// </remarks>
        public R Execute(int?e)
        {
            if (e.HasValue)
            {
                PostNormalPriorityEvent(e.Value);
            }

            R returnValue = default;

            switch (ExecutionState)
            {
            case ExecutionStates.Idle:
                ExecutionState = ExecutionStates.Executing;

                while (StateClassifications[CurrentState] == StateTypes.Normal && (CurrentEvent = GetNextEvent()).HasValue)
                {
                    EventTrace.Add(new EventTraceInstance(CurrentState, CurrentEvent.Value));
                    Transition <Action> transition = Transitions[CurrentState, CurrentEvent.Value];
                    foreach (Action a in transition.Actions)
                    {
                        try
                        {
                            returnValue = a();
                        }
                        catch (UnexpectedEventException)
                        {
                            throw;
                        }
                        catch (Exception exc)
                        {
                            ExecutionState = ExecutionStates.Exception;
                            throw new ActionRaisedException(this,
                                                            (CurrentState >= StateNames.GetLowerBound(0) && CurrentState <= StateNames.GetUpperBound(0) ? StateNames[CurrentState] : CurrentState.ToString()),
                                                            exc);
                        }
                    }
                    CurrentState = transition.NextState;
                }

                if (StateClassifications[CurrentState] == StateTypes.Error)
                {
                    ExecutionState = ExecutionStates.Errored;
                    throw new EnteredErrorStateException(this,
                                                         (CurrentEvent.Value >= EventNames.GetLowerBound(0) && CurrentEvent.Value <= EventNames.GetUpperBound(0) ? EventNames[CurrentEvent.Value] : CurrentEvent.Value.ToString()),
                                                         (CurrentState >= StateNames.GetLowerBound(0) && CurrentState <= StateNames.GetUpperBound(0) ? StateNames[CurrentState] : CurrentState.ToString()));
                }

                ExecutionState = ExecutionStates.Idle;
                return(returnValue);

            case ExecutionStates.Errored:
            case ExecutionStates.Exception:
                throw new EnteredErrorStateException(this,
                                                     (CurrentEvent.Value >= EventNames.GetLowerBound(0) && CurrentEvent.Value <= EventNames.GetUpperBound(0) ? EventNames[CurrentEvent.Value] : CurrentEvent.Value.ToString()),
                                                     (CurrentState >= StateNames.GetLowerBound(0) && CurrentState <= StateNames.GetUpperBound(0) ? StateNames[CurrentState] : CurrentState.ToString()));

            case ExecutionStates.Executing:
            case ExecutionStates.Finished:
                return(returnValue);

            default:
                throw new NotImplementedException();
            }
        }
Example #30
0
 private object Number_dummy(char c)
 {
     State = StateNames.Operator;
     return(null);
 }
Example #31
0
 private void Number_Operator(char c) {
     // item 276
     CreateNumber(Data);
     // item 271
     AddChar(Data, c);
     // item 274
     CurrentState = StateNames.Operator;
 }
Example #32
0
 private object Operator_Whitespace(char c)
 {
     CreateOperator(this);
     State = StateNames.Idle;
     return(null);
 }
Example #33
0
 private void Operator_Whitespace(char c) {
     // item 292
     CreateOperator(Data);
     // item 219
     CurrentState = StateNames.Idle;
 }
Example #34
0
 private object Working_default(int msg)
 {
     State = StateNames.Working;
     return(null);
 }
Example #35
0
 private void Operator_Digit(char c) {
     // item 294
     CreateOperator(Data);
     // item 287
     AddChar(Data, c);
     // item 290
     CurrentState = StateNames.Number;
 }
Example #36
0
 private void Idle_Whitespace(char c)
 {
     // item 216
     CurrentState = StateNames.Idle;
 }
Example #37
0
 private void Idle_Whitespace(IRuntime runtime, int myId, Message message) {
     // item 338
     CurrentState = StateNames.Idle;
 }
Example #38
0
 private void Number_dummy(char c)
 {
     // item 274
     CurrentState = StateNames.Operator;
 }
Example #39
0
 private void Identifier_Whitespace(IRuntime runtime, int myId, Message message) {
     // item 380
     CreateIdentifier(Data);
     // item 346
     CurrentState = StateNames.Idle;
 }
Example #40
0
 private void Idle_Whitespace(IRuntime runtime, int myId, Message message)
 {
     // item 338
     CurrentState = StateNames.Idle;
 }
Example #41
0
 private void Identifier_Digit(IRuntime runtime, int myId, Message message) {
     // item 375
     AddChar(Data, message.C);
     // item 378
     CurrentState = StateNames.Identifier;
 }
Example #42
0
 private void Number_dummy(IRuntime runtime, int myId, Message message)
 {
     // item 396
     CurrentState = StateNames.Operator;
 }
Example #43
0
 private void Number_Whitespace(IRuntime runtime, int myId, Message message) {
     // item 397
     CreateNumber(Data);
     // item 349
     CurrentState = StateNames.Idle;
 }
Example #44
0
 private void Idle_Operator(char c) {
     // item 239
     AddChar(Data, c);
     // item 242
     CurrentState = StateNames.Operator;
 }
Example #45
0
 private void Number_Digit(IRuntime runtime, int myId, Message message) {
     // item 392
     AddChar(Data, message.C);
     // item 395
     CurrentState = StateNames.Number;
 }
Example #46
0
 private void Identifier_Whitespace(char c) {
     // item 258
     CreateIdentifier(Data);
     // item 224
     CurrentState = StateNames.Idle;
 }
Example #47
0
 private void Number_dummy(IRuntime runtime, int myId, Message message) {
     // item 396
     CurrentState = StateNames.Operator;
 }
Example #48
0
 private void Identifier_Letter(char c) {
     // item 252
     AddChar(Data, c);
     // item 255
     CurrentState = StateNames.Identifier;
 }
Example #49
0
 private void Operator_Letter(IRuntime runtime, int myId, Message message) {
     // item 415
     CreateOperator(Data);
     // item 408
     AddChar(Data, message.C);
     // item 411
     CurrentState = StateNames.Identifier;
 }
Example #50
0
 private void Identifier_Digit(char c) {
     // item 253
     AddChar(Data, c);
     // item 256
     CurrentState = StateNames.Identifier;
 }
Example #51
0
 private void Operator_Operator(IRuntime runtime, int myId, Message message) {
     // item 417
     if (TryMakeLongOperator(Data, message.C)) {
         // item 420
         CurrentState = StateNames.Idle;
     } else {
         // item 421
         CreateOperator(Data);
         // item 410
         AddChar(Data, message.C);
         // item 413
         CurrentState = StateNames.Operator;
     }
 }
Example #52
0
 private void Identifier_Operator(char c) {
     // item 259
     CreateIdentifier(Data);
     // item 254
     AddChar(Data, c);
     // item 257
     CurrentState = StateNames.Operator;
 }
Example #53
0
    private void NextStateTransition(StateNames aStateName, Vector2 cellCoordinates)
    {
        SOState nextState = SetNextState(this.statesDictionary.GetState(aStateName));

        nextState.StateAction(cellCoordinates);
    }
Example #54
0
 private void Number_Whitespace(char c) {
     // item 275
     CreateNumber(Data);
     // item 227
     CurrentState = StateNames.Idle;
 }
Example #55
0
 private object Sending_default(IRuntime runtime, int myId, Message message)
 {
     // item 819
     State = StateNames.Sending;
     return(null);
 }
Example #56
0
 private void Number_Letter(char c) {
     // item 269
     AddChar(Data, c);
     // item 272
     CurrentState = StateNames.Number;
 }
Example #57
0
 /// <summary>
 /// Invoked when none of the transitions for the current state have a trigger event matching the current event type
 /// </summary>
 protected R InvalidTransition()
 {
     throw new UnexpectedEventException(this,
                                        (CurrentEvent.Value >= EventNames.GetLowerBound(0) && CurrentEvent.Value <= EventNames.GetUpperBound(0) ? EventNames[CurrentEvent.Value] : CurrentEvent.Value.ToString()),
                                        (CurrentState >= StateNames.GetLowerBound(0) && CurrentState <= StateNames.GetUpperBound(0) ? StateNames[CurrentState] : CurrentState.ToString()));
 }
Example #58
0
 private void Number_Digit(char c) {
     // item 270
     AddChar(Data, c);
     // item 273
     CurrentState = StateNames.Number;
 }
Example #59
0
 private void JustRead_CallResult_Cancelled(IRuntime runtime, int myId, Message message)
 {
     // item 345
     CurrentState = StateNames.Deleting;
     runtime.RemoveActor(myId);
 }
Example #60
0
 public SOState GetStateFromDictionary(StateNames aState)
 {
     return(this.statesDictionary.GetState(aState));
 }