正在新增编译缓存功能,用于加速与加密
This commit is contained in:
@@ -6,6 +6,66 @@ namespace Convention.RScript.Runner
|
||||
{
|
||||
public class DefineVariableRunner : IRSentenceRunner
|
||||
{
|
||||
public void Compile(ExpressionParser parser, RScriptSentence sentence, RScriptContext context)
|
||||
{
|
||||
var varTypeName = sentence.info[0];
|
||||
var varName = sentence.info[1];
|
||||
var varInitExpression = sentence.info[2];
|
||||
Type varType;
|
||||
object varDefaultValue;
|
||||
{
|
||||
if (varTypeName == "string")
|
||||
{
|
||||
varType = typeof(string);
|
||||
varDefaultValue = "";
|
||||
}
|
||||
else if (varTypeName == "int")
|
||||
{
|
||||
varType = typeof(int);
|
||||
if (varInitExpression != null) parser.Compile<int>(varInitExpression);
|
||||
varDefaultValue = 0;
|
||||
}
|
||||
else if (varTypeName == "double")
|
||||
{
|
||||
varType = typeof(double);
|
||||
if (varInitExpression != null) parser.Compile<double>(varInitExpression);
|
||||
varDefaultValue = 0.0;
|
||||
}
|
||||
else if (varTypeName == "float")
|
||||
{
|
||||
varType = typeof(float);
|
||||
if (varInitExpression != null) parser.Compile<float>(varInitExpression);
|
||||
varDefaultValue = 0.0f;
|
||||
}
|
||||
else if (varTypeName == "bool")
|
||||
{
|
||||
varType = typeof(bool);
|
||||
if (varInitExpression != null) parser.Compile<bool>(varInitExpression);
|
||||
varDefaultValue = false;
|
||||
}
|
||||
else if (varTypeName == "var")
|
||||
{
|
||||
varType = typeof(object);
|
||||
if (varInitExpression != null) parser.Compile(varInitExpression);
|
||||
varDefaultValue = new object();
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new RScriptRuntimeException($"Unsupported variable type '{varTypeName}'.", context.CurrentRuntimePointer);
|
||||
}
|
||||
}
|
||||
if (context.CurrentLocalSpaceVariableNames.Peek().Contains(varName) == false)
|
||||
{
|
||||
context.Variables.Add(varName, new(varType, default));
|
||||
parser.context.Variables[varName] = varDefaultValue;
|
||||
context.CurrentLocalSpaceVariableNames.Peek().Add(varName);
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new RScriptRuntimeException($"Variable '{varName}' already defined on this namespace.", context.CurrentRuntimePointer);
|
||||
}
|
||||
}
|
||||
|
||||
[return: MaybeNull]
|
||||
public object Run(ExpressionParser parser, RScriptSentence sentence, RScriptContext context)
|
||||
{
|
||||
|
Reference in New Issue
Block a user