예제 #1
0
        public DynValue Coroutine_Resume(DynValue[] args)
        {
            EnterProcessor();

            try
            {
                int entrypoint = 0;

                if (m_State != CoroutineState.NotStarted && m_State != CoroutineState.Suspended)
                {
                    throw ScriptRuntimeException.CannotResumeNotSuspended(m_State);
                }

                if (m_State == CoroutineState.NotStarted)
                {
                    entrypoint = PushClrToScriptStackFrame(CallStackItemFlags.ResumeEntryPoint, null, args);
                }
                else
                {
                    m_ValueStack.Push(DynValue.NewTuple(args));
                    entrypoint = m_SavedInstructionPtr;
                }

                m_State = CoroutineState.Running;
                DynValue retVal = Processing_Loop(entrypoint);

                if (retVal.Type == DataType.YieldRequest)
                {
                    m_State = CoroutineState.Suspended;
                    return(DynValue.NewTuple(retVal.YieldRequest.ReturnValues));
                }
                else
                {
                    m_State = CoroutineState.Dead;
                    return(retVal);
                }
            }
            catch (Exception)
            {
                // Unhandled exception - move to dead
                m_State = CoroutineState.Dead;
                throw;
            }
            finally
            {
                LeaveProcessor();
            }
        }
        public DynValue Coroutine_Resume(DynValue[] args)
        {
            this.EnterProcessor();

            try
            {
                int entryPoint = 0;

                if (this.State != CoroutineState.NotStarted && this.State != CoroutineState.Suspended &&
                    this.State != CoroutineState.ForceSuspended)
                {
                    throw ScriptRuntimeException.CannotResumeNotSuspended(this.State);
                }

                if (this.State == CoroutineState.NotStarted)
                {
                    entryPoint = this.PushClrToScriptStackFrame(CallStackItemFlags.ResumeEntryPoint, null, args);
                }
                else if (this.State == CoroutineState.Suspended)
                {
                    _valueStack.Push(DynValue.NewTuple(args));
                    entryPoint = _savedInstructionPtr;
                }
                else if (this.State == CoroutineState.ForceSuspended)
                {
                    if (args != null && args.Length > 0)
                    {
                        throw new ArgumentException("When resuming a force-suspended coroutine, args must be empty.");
                    }

                    entryPoint = _savedInstructionPtr;
                }

                this.State = CoroutineState.Running;
                var retVal = this.Processing_Loop(ExecutionControlToken.Dummy, entryPoint);

                if (retVal.Type == DataType.YieldRequest)
                {
                    if (retVal.YieldRequest.Forced)
                    {
                        this.State = CoroutineState.ForceSuspended;
                        return(retVal);
                    }
                    else
                    {
                        this.State = CoroutineState.Suspended;
                        return(DynValue.NewTuple(retVal.YieldRequest.ReturnValues));
                    }
                }
                else
                {
                    this.State = CoroutineState.Dead;
                    return(retVal);
                }
            }
            catch (Exception)
            {
                // Unhandled exception - move to dead
                this.State = CoroutineState.Dead;
                throw;
            }
            finally
            {
                this.LeaveProcessor();
            }
        }