Пример #1
0
        protected override void ExecuteInternal(IExecutionEnvironment environment, IList <IInstruction> instructions)
        {
            CurrentInstruction.Execute(environment);
            if (CurrentInstruction is BranchAndExchangeInstruction baeInstruction)
            {
                // TODO: Implement thumb mode
                if (baeInstruction.IsThumbMode)
                {
                    throw new InvalidOperationException("Thumb mode is not supported.");
                }
            }

            if (!(environment.CpuState is Aarch32CpuState armCpuState))
            {
                throw new InvalidOperationException("CpuState is not supported.");
            }

            // If a branch was executed
            if (CurrentInstruction is BranchInstruction branchInstruction && branchInstruction.IsBranching)
            {
                // Clear buffer and and get 2 new instructions from new PC
                _instructionBuffer.Clear();

                // Buffer next 2 instructions
                GetNextInstruction(environment, instructions);
                GetNextInstruction(environment, instructions);
            }
Пример #2
0
        public int ExecuteNext()
        {
            var(move, increase) = CurrentInstruction.Execute();
            Position           += move;
            Accumulator        += increase;

            if (Position > LoadedProgram.Count - 1)
            {
                RanToCompletion = true;
            }

            return(Accumulator);
        }
Пример #3
0
        public bool Step()
        {
            if (quit)
            {
                return(false);
            }

            CurrentInstruction = Environment.Delegate.instructions[Environment.ProgramCounter];

#if DEBUG
            Environment.AddHistoryEntry(CurrentInstruction);
#endif

            try
            {
                CurrentInstruction.Execute(Environment);
            }
            catch (ScriptException e)
            {
                HandleException(e, Environment);
            }
            catch (TargetInvocationException e)
            {
                HandleException(new ScriptException(CurrentInstruction, e.InnerException), Environment);
            }
            catch (Exception e)
            {
                HandleException(new ScriptException(CurrentInstruction, e), Environment);
            }

            if (Environment.ProgramCounter < -1 ||
                Environment.ProgramCounter >= Environment.Delegate.instructions.Length)
            {
                throw new ScriptException(CurrentInstruction, new IndexOutOfRangeException());
            }

            Environment.ProgramCounter++;

            if (Environment.IsReturning ||
                Environment.ProgramCounter >= Environment.Delegate.instructions.Length)
            {
                quit = true;
                return(false);
            }
            return(true);
        }
Пример #4
0
    protected void Update()
    {
        if (CurrentInstruction != null)
        {
            CurrentInstruction.Execute();
        }
        else
        {
            GetNextInstruction();
        }

        if (CurrentInstruction == null)
        {
            return;
        }
        else if ((CurrentInstruction.GetType() != typeof(Attack) && CurrentInstruction.GetType() != typeof(FixBreaker) && CurrentInstruction.GetType() != typeof(CreateNest) && CurrentInstruction.GetType() != typeof(CreateQueen)) && isWalking == true)
        {
            isWalking = false;
            StartCoroutine(walkingLoop());
        }
    }