1.新增context内置变量2.修复一些问题
This commit is contained in:
@@ -169,6 +169,30 @@ namespace Convention.RScript
|
||||
}
|
||||
}
|
||||
|
||||
public class BuildInContext
|
||||
{
|
||||
private RScriptContext context;
|
||||
public BuildInContext(RScriptContext context)
|
||||
{
|
||||
this.context = context;
|
||||
}
|
||||
|
||||
public bool ExistVar(string name)
|
||||
{
|
||||
return context.Variables.ContainsKey(name);
|
||||
}
|
||||
|
||||
public bool ExistNamespace(string name)
|
||||
{
|
||||
return context.NamespaceLabels.ContainsKey(name);
|
||||
}
|
||||
|
||||
public bool ExistLabel(string name)
|
||||
{
|
||||
return context.Labels.ContainsKey(name);
|
||||
}
|
||||
}
|
||||
|
||||
public RScriptContext(string[] expressions,
|
||||
RScriptImportClass import = null,
|
||||
RScriptVariables variables = null,
|
||||
@@ -177,6 +201,7 @@ namespace Convention.RScript
|
||||
{
|
||||
this.Import = import ?? new();
|
||||
this.Variables = variables ?? new();
|
||||
this.Variables.Add("context", new(typeof(object), new BuildInContext(this)));
|
||||
this.Sentences = (from item in expressions select ParseToSentence(item)).ToArray();
|
||||
if (matcher != null)
|
||||
this.SentenceParser = matcher;
|
||||
@@ -221,13 +246,26 @@ namespace Convention.RScript
|
||||
return result;
|
||||
}
|
||||
|
||||
public void Run(ExpressionParser parser)
|
||||
private void BeforeRun(ExpressionParser parser)
|
||||
{
|
||||
CurrentLocalSpaceVariableNames.Clear();
|
||||
RuntimePointerStack.Clear();
|
||||
GotoPointerStack.Clear();
|
||||
CurrentLocalSpaceVariableNames.Clear();
|
||||
CurrentLocalSpaceVariableNames.Push(new());
|
||||
foreach (var staticType in Import)
|
||||
{
|
||||
parser.context.Imports.AddType(staticType);
|
||||
}
|
||||
foreach (var (name,varObject) in Variables)
|
||||
{
|
||||
parser.context.Variables[name] = varObject.data;
|
||||
}
|
||||
}
|
||||
|
||||
public void Run(ExpressionParser parser)
|
||||
{
|
||||
BeforeRun(parser);
|
||||
for (CurrentRuntimePointer = 0; CurrentRuntimePointer < Sentences.Length; CurrentRuntimePointer++)
|
||||
{
|
||||
RunNextStep(parser);
|
||||
@@ -242,11 +280,7 @@ namespace Convention.RScript
|
||||
|
||||
public IEnumerator RunAsync(ExpressionParser parser)
|
||||
{
|
||||
CurrentLocalSpaceVariableNames.Clear();
|
||||
RuntimePointerStack.Clear();
|
||||
GotoPointerStack.Clear();
|
||||
CurrentLocalSpaceVariableNames.Clear();
|
||||
CurrentLocalSpaceVariableNames.Push(new());
|
||||
BeforeRun(parser);
|
||||
for (CurrentRuntimePointer = 0; CurrentRuntimePointer < Sentences.Length; CurrentRuntimePointer++)
|
||||
{
|
||||
var ret = RunNextStep(parser);
|
||||
|
Reference in New Issue
Block a user