|
@@ -35,26 +35,41 @@ namespace MoonSharp.Interpreter.Execution.VM
|
|
|
{
|
|
{
|
|
|
int entrypoint = 0;
|
|
int entrypoint = 0;
|
|
|
|
|
|
|
|
- if (m_State != CoroutineState.NotStarted && m_State != CoroutineState.Suspended)
|
|
|
|
|
|
|
+ if (m_State != CoroutineState.NotStarted && m_State != CoroutineState.Suspended && m_State != CoroutineState.ForceSuspended)
|
|
|
throw ScriptRuntimeException.CannotResumeNotSuspended(m_State);
|
|
throw ScriptRuntimeException.CannotResumeNotSuspended(m_State);
|
|
|
|
|
|
|
|
if (m_State == CoroutineState.NotStarted)
|
|
if (m_State == CoroutineState.NotStarted)
|
|
|
{
|
|
{
|
|
|
entrypoint = PushClrToScriptStackFrame(CallStackItemFlags.ResumeEntryPoint, null, args);
|
|
entrypoint = PushClrToScriptStackFrame(CallStackItemFlags.ResumeEntryPoint, null, args);
|
|
|
}
|
|
}
|
|
|
- else
|
|
|
|
|
|
|
+ else if (m_State == CoroutineState.Suspended)
|
|
|
{
|
|
{
|
|
|
m_ValueStack.Push(DynValue.NewTuple(args));
|
|
m_ValueStack.Push(DynValue.NewTuple(args));
|
|
|
entrypoint = m_SavedInstructionPtr;
|
|
entrypoint = m_SavedInstructionPtr;
|
|
|
}
|
|
}
|
|
|
|
|
+ else if (m_State == CoroutineState.ForceSuspended)
|
|
|
|
|
+ {
|
|
|
|
|
+ if (args != null && args.Length > 0)
|
|
|
|
|
+ throw new ArgumentException("When resuming a force-suspended coroutine, args must be empty.");
|
|
|
|
|
+
|
|
|
|
|
+ entrypoint = m_SavedInstructionPtr;
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
m_State = CoroutineState.Running;
|
|
m_State = CoroutineState.Running;
|
|
|
DynValue retVal = Processing_Loop(entrypoint);
|
|
DynValue retVal = Processing_Loop(entrypoint);
|
|
|
|
|
|
|
|
if (retVal.Type == DataType.YieldRequest)
|
|
if (retVal.Type == DataType.YieldRequest)
|
|
|
{
|
|
{
|
|
|
- m_State = CoroutineState.Suspended;
|
|
|
|
|
- return DynValue.NewTuple(retVal.YieldRequest.ReturnValues);
|
|
|
|
|
|
|
+ if (retVal.YieldRequest.Forced)
|
|
|
|
|
+ {
|
|
|
|
|
+ m_State = CoroutineState.ForceSuspended;
|
|
|
|
|
+ return retVal;
|
|
|
|
|
+ }
|
|
|
|
|
+ else
|
|
|
|
|
+ {
|
|
|
|
|
+ m_State = CoroutineState.Suspended;
|
|
|
|
|
+ return DynValue.NewTuple(retVal.YieldRequest.ReturnValues);
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
else
|
|
else
|
|
|
{
|
|
{
|