mirror of
https://github.com/Stone-Red-Code/YesNt-Interpreter.git
synced 2026-09-08 23:43:18 +02:00
Upgrade to .NET 10, update packages, enable AOT and cleanup code
This commit is contained in:
@@ -26,15 +26,58 @@ internal static class ExitMessages
|
||||
internal const string NoInArgumentInStack = "No in argument in stack";
|
||||
internal const string NoFunctionInStack = "No function in stack";
|
||||
|
||||
internal static string LabelNotFound(string label) => $"Label \"{label}\" not found";
|
||||
internal static string FunctionNotFound(string function) => $"Function \"{function}\" not found";
|
||||
internal static string VariableNotFound(string variable) => $"Variable \"{variable}\" not found";
|
||||
internal static string ListNotFound(string list) => $"List \"{list}\" not found";
|
||||
internal static string InvalidIndex(string rawIndex) => $"\"{rawIndex}\" is not a valid index";
|
||||
internal static string IndexOutOfRange(int index) => $"Index {index} out of range";
|
||||
internal static string InvalidTimeoutValue(string value) => $"\"{value}\" is not a valid time-out value";
|
||||
internal static string CouldNotLoadFile(string path) => $"Could not load file \"{path}\"";
|
||||
internal static string CouldNotFindFile(string path) => $"Could not find file \"{path}\"";
|
||||
internal static string CannotFindFile(string path) => $"Cannot find file \"{path}\".";
|
||||
internal static string FailedToStart(string program, string message) => $"Failed to start \"{program}\". {message}";
|
||||
internal static string LabelNotFound(string label)
|
||||
{
|
||||
return $"Label \"{label}\" not found";
|
||||
}
|
||||
|
||||
internal static string FunctionNotFound(string function)
|
||||
{
|
||||
return $"Function \"{function}\" not found";
|
||||
}
|
||||
|
||||
internal static string VariableNotFound(string variable)
|
||||
{
|
||||
return $"Variable \"{variable}\" not found";
|
||||
}
|
||||
|
||||
internal static string ListNotFound(string list)
|
||||
{
|
||||
return $"List \"{list}\" not found";
|
||||
}
|
||||
|
||||
internal static string InvalidIndex(string rawIndex)
|
||||
{
|
||||
return $"\"{rawIndex}\" is not a valid index";
|
||||
}
|
||||
|
||||
internal static string IndexOutOfRange(int index)
|
||||
{
|
||||
return $"Index {index} out of range";
|
||||
}
|
||||
|
||||
internal static string InvalidTimeoutValue(string value)
|
||||
{
|
||||
return $"\"{value}\" is not a valid time-out value";
|
||||
}
|
||||
|
||||
internal static string CouldNotLoadFile(string path)
|
||||
{
|
||||
return $"Could not load file \"{path}\"";
|
||||
}
|
||||
|
||||
internal static string CouldNotFindFile(string path)
|
||||
{
|
||||
return $"Could not find file \"{path}\"";
|
||||
}
|
||||
|
||||
internal static string CannotFindFile(string path)
|
||||
{
|
||||
return $"Cannot find file \"{path}\".";
|
||||
}
|
||||
|
||||
internal static string FailedToStart(string program, string message)
|
||||
{
|
||||
return $"Failed to start \"{program}\". {message}";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -23,9 +23,7 @@ internal sealed class RuntimeInformation
|
||||
private static int internalTaskId = 0;
|
||||
private readonly Dictionary<string, string> topVariables = [];
|
||||
private readonly Dictionary<string, List<string>> topLists = [];
|
||||
private readonly Dictionary<string, int> topLabels = [];
|
||||
private RuntimeInformation parentRuntimeInformation;
|
||||
private int taskId = 0;
|
||||
|
||||
public Dictionary<string, string> GlobalVariables { get; set; } = [];
|
||||
public Dictionary<string, int> Functions { get; } = [];
|
||||
public Stack<FunctionScope> FunctionCallStack { get; } = new();
|
||||
@@ -41,7 +39,7 @@ internal sealed class RuntimeInformation
|
||||
public bool IsDebugMode { get; set; } = false;
|
||||
public string WorkingDirectory { get; set; } = string.Empty;
|
||||
public bool IsTask => ParentRuntimeInformation is not null;
|
||||
public int TaskId => IsTask ? taskId : 0;
|
||||
public int TaskId { get => IsTask ? field : 0; private set; } = 0;
|
||||
public bool InternalIsInFunction { get; set; }
|
||||
|
||||
public bool IsInFunction
|
||||
@@ -53,18 +51,15 @@ internal sealed class RuntimeInformation
|
||||
public Dictionary<string, string> Variables => FunctionCallStack.Count == 0 ? topVariables : FunctionCallStack.Peek().Variables;
|
||||
public Dictionary<string, List<string>> Lists => FunctionCallStack.Count == 0 ? topLists : FunctionCallStack.Peek().Lists;
|
||||
|
||||
public Dictionary<string, int> Labels => FunctionCallStack.Count == 0 ? topLabels : FunctionCallStack.Peek().Labels;
|
||||
public Dictionary<string, int> Labels { get => FunctionCallStack.Count == 0 ? field : FunctionCallStack.Peek().Labels; } = [];
|
||||
|
||||
public RuntimeInformation ParentRuntimeInformation
|
||||
{
|
||||
get => parentRuntimeInformation;
|
||||
get;
|
||||
set
|
||||
{
|
||||
parentRuntimeInformation = value;
|
||||
if (parentRuntimeInformation is not null)
|
||||
{
|
||||
parentRuntimeInformation.OnExit += ParentRuntimeInformation_OnExit;
|
||||
}
|
||||
field = value;
|
||||
field?.OnExit += ParentRuntimeInformation_OnExit;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -73,7 +68,7 @@ internal sealed class RuntimeInformation
|
||||
|
||||
public void WriteLine(string output, bool forceWrite = false)
|
||||
{
|
||||
if ((Stop && !forceWrite) || (parentRuntimeInformation?.StopAllTasks == true && !forceWrite))
|
||||
if ((Stop && !forceWrite) || (ParentRuntimeInformation?.StopAllTasks == true && !forceWrite))
|
||||
{
|
||||
return;
|
||||
}
|
||||
@@ -82,7 +77,7 @@ internal sealed class RuntimeInformation
|
||||
{
|
||||
if (IsTask)
|
||||
{
|
||||
parentRuntimeInformation!.WriteLine(output.FromSafeString(), forceWrite);
|
||||
ParentRuntimeInformation!.WriteLine(output.FromSafeString(), forceWrite);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -97,7 +92,7 @@ internal sealed class RuntimeInformation
|
||||
|
||||
public void Write(string output, bool forceWrite = false)
|
||||
{
|
||||
if ((Stop && !forceWrite) || (parentRuntimeInformation?.StopAllTasks == true && !forceWrite))
|
||||
if ((Stop && !forceWrite) || (ParentRuntimeInformation?.StopAllTasks == true && !forceWrite))
|
||||
{
|
||||
return;
|
||||
}
|
||||
@@ -106,7 +101,7 @@ internal sealed class RuntimeInformation
|
||||
{
|
||||
if (IsTask)
|
||||
{
|
||||
parentRuntimeInformation!.Write(output.FromSafeString(), forceWrite);
|
||||
ParentRuntimeInformation!.Write(output.FromSafeString(), forceWrite);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -154,7 +149,7 @@ internal sealed class RuntimeInformation
|
||||
{
|
||||
StopAllTasks = true;
|
||||
OnExit?.Invoke(message, StopAllTasks);
|
||||
parentRuntimeInformation?.Exit(ExitMessages.TerminatedByChildTask, true);
|
||||
ParentRuntimeInformation?.Exit(ExitMessages.TerminatedByChildTask, true);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -162,7 +157,7 @@ internal sealed class RuntimeInformation
|
||||
{
|
||||
if (IsTask)
|
||||
{
|
||||
parentRuntimeInformation.LineExecuted(debugEventArgs);
|
||||
ParentRuntimeInformation.LineExecuted(debugEventArgs);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -192,10 +187,8 @@ internal sealed class RuntimeInformation
|
||||
IsInFunction = false;
|
||||
IsLocalSearch = false;
|
||||
LineNumber = 0;
|
||||
taskId = internalTaskId + 1;
|
||||
#pragma warning disable S2696 // Instance members should not write to "static" fields
|
||||
TaskId = internalTaskId + 1;
|
||||
internalTaskId++;
|
||||
#pragma warning restore S2696 // Instance members should not write to "static" fields
|
||||
}
|
||||
|
||||
private void ParentRuntimeInformation_OnExit(string exitMessage, bool stopAllTasks)
|
||||
|
||||
@@ -44,7 +44,7 @@ public class YesNtInterpreter
|
||||
private readonly RuntimeInformation runtimeInfo = new RuntimeInformation();
|
||||
private Dictionary<StatementAttribute, Action<string>> statements;
|
||||
private readonly List<KeyValuePair<StaticStatementAttribute, Action>> staticStatements;
|
||||
private readonly Dictionary<string, List<KeyValuePair<StatementAttribute, Action<string>>>> disabledStatements = new();
|
||||
private readonly Dictionary<string, List<KeyValuePair<StatementAttribute, Action<string>>>> disabledStatements = [];
|
||||
|
||||
/// <summary>
|
||||
/// Gets a read-only snapshot of all currently registered statements.
|
||||
@@ -138,10 +138,10 @@ public class YesNtInterpreter
|
||||
{
|
||||
foreach (StatementAttribute key in statements.Keys.Where(k => k.Name == name).ToList())
|
||||
{
|
||||
statements.Remove(key);
|
||||
_ = statements.Remove(key);
|
||||
}
|
||||
|
||||
disabledStatements.Remove(name);
|
||||
_ = disabledStatements.Remove(name);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -191,7 +191,7 @@ public class YesNtInterpreter
|
||||
statements[kv.Key] = kv.Value;
|
||||
}
|
||||
|
||||
disabledStatements.Remove(name);
|
||||
_ = disabledStatements.Remove(name);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -50,7 +50,7 @@ internal partial class ProcessingStatements : StatementRuntimeInformation
|
||||
_ = Task.Run(() =>
|
||||
{
|
||||
YesNtInterpreter interpreter = new YesNtInterpreter();
|
||||
interpreter.Execute(lines, RuntimeInfo.GlobalVariables, lineNumber, RuntimeInfo);
|
||||
interpreter.Execute(lines, RuntimeInfo.GlobalVariables, lineNumber, RuntimeInfo);
|
||||
});
|
||||
|
||||
RuntimeInfo.CurrentLine = string.Empty;
|
||||
|
||||
@@ -1,18 +1,54 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net8.0</TargetFramework>
|
||||
<TargetFramework>net10.0</TargetFramework>
|
||||
<RootNamespace>YesNt.Interpreter</RootNamespace>
|
||||
<ApplicationIcon />
|
||||
<OutputType>Library</OutputType>
|
||||
<StartupObject />
|
||||
<Platforms>AnyCPU;x64</Platforms>
|
||||
<GeneratePackageOnBuild>True</GeneratePackageOnBuild>
|
||||
<PackageReadmeFile>README.md</PackageReadmeFile>
|
||||
<RepositoryUrl>https://github.com/Stone-Red-Code/YesNt-Interpreter/</RepositoryUrl>
|
||||
<PackageTags>scripting, modding, language</PackageTags>
|
||||
<PackageIcon>Logo.png</PackageIcon>
|
||||
<GenerateDocumentationFile>True</GenerateDocumentationFile>
|
||||
<PackageLicenseFile>LICENSE</PackageLicenseFile>
|
||||
</PropertyGroup>
|
||||
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
|
||||
<IsAotCompatible>True</IsAotCompatible>
|
||||
</PropertyGroup>
|
||||
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
|
||||
<IsAotCompatible>True</IsAotCompatible>
|
||||
</PropertyGroup>
|
||||
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'">
|
||||
<IsAotCompatible>True</IsAotCompatible>
|
||||
</PropertyGroup>
|
||||
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
|
||||
<IsAotCompatible>True</IsAotCompatible>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\YesNt.Interpreter.Generator\YesNt.Interpreter.Generator.csproj"
|
||||
OutputItemType="Analyzer"
|
||||
ReferenceOutputAssembly="false" />
|
||||
<None Include="..\assets\Logo.png">
|
||||
<Pack>True</Pack>
|
||||
<PackagePath>\</PackagePath>
|
||||
</None>
|
||||
<None Include="..\LICENSE">
|
||||
<Pack>True</Pack>
|
||||
<PackagePath>\</PackagePath>
|
||||
</None>
|
||||
<None Include="..\README.md">
|
||||
<Pack>True</Pack>
|
||||
<PackagePath>\</PackagePath>
|
||||
</None>
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\YesNt.Interpreter.Generator\YesNt.Interpreter.Generator.csproj" OutputItemType="Analyzer" ReferenceOutputAssembly="false" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
||||
Reference in New Issue
Block a user