更新异步step

This commit is contained in:
2025-12-11 18:03:28 +08:00
parent e4b7dc0f55
commit 0a7f6eb362
11 changed files with 219 additions and 27 deletions

View File

@@ -1,4 +1,5 @@
using Convention.RScript.Parser;
using System.Collections;
using System.Diagnostics.CodeAnalysis;
namespace Convention.RScript.Runner
@@ -48,5 +49,43 @@ namespace Convention.RScript.Runner
}
return null;
}
[return: MaybeNull]
public override IEnumerator RunAsync(ExpressionParser parser, RScriptSentence sentence, RScriptContext context)
{
// 检查并跳转到指定标签
if (parser.Evaluate<bool>(sentence.info[0]))
{
if (context.Labels.TryGetValue(sentence.content, out var labelPointer))
{
context.GotoPointerStack.Push(context.CurrentRuntimePointer);
DoJumpRuntimePointer(parser, labelPointer, context);
}
else if (context.NamespaceLabels.TryGetValue(sentence.content, out labelPointer))
{
int current = context.CurrentRuntimePointer;
//DoEnterNamespace(parser);
context.SentenceRunners[RScriptSentence.Mode.EnterNamespace].Run(parser, context.CurrentSentence, context);
context.CurrentRuntimePointer = labelPointer;
for (int e = context.NamespaceLayer[context.NamespaceLabels[sentence.content]]; ;)
{
yield return context.RunNextStepAsync(parser);
if (context.CurrentRuntimePointer >= context.Sentences.Length)
break;
else if (context.CurrentRuntimePointer == e)
break;
else
context.CurrentRuntimePointer++;
}
//context.DoExitNamespace(parser);
context.SentenceRunners[RScriptSentence.Mode.ExitNamespace].Run(parser, context.CurrentSentence, context);
context.CurrentRuntimePointer = current;
}
else
{
throw new RScriptRuntimeException($"Label '{sentence.content}' not found.", context.CurrentRuntimePointer);
}
}
}
}
}