mirror of
https://github.com/Stone-Red-Code/YesNt-Interpreter.git
synced 2026-09-09 16:06:08 +02:00
Code structure and speed imporvments
This commit is contained in:
@@ -6,7 +6,7 @@ using YesNt.Interpreter.Utilities;
|
|||||||
|
|
||||||
namespace YesNt.Interpreter.Runtime
|
namespace YesNt.Interpreter.Runtime
|
||||||
{
|
{
|
||||||
internal class RuntimeInformation
|
internal sealed class RuntimeInformation
|
||||||
{
|
{
|
||||||
private RuntimeInformation parentRuntimeInformation;
|
private RuntimeInformation parentRuntimeInformation;
|
||||||
private static int internalTaskId = 0;
|
private static int internalTaskId = 0;
|
||||||
|
|||||||
@@ -11,13 +11,34 @@ namespace YesNt.Interpreter.Statements
|
|||||||
{
|
{
|
||||||
private readonly Random random = new Random();
|
private readonly Random random = new Random();
|
||||||
|
|
||||||
[Statement("%tim", SearchMode.Contains, SpaceAround.None, ConsoleColor.Blue, KeepStatementInArgs = true, Priority = Priority.Highest)]
|
[Statement("%time", SearchMode.Contains, SpaceAround.None, ConsoleColor.Blue, KeepStatementInArgs = true, Priority = Priority.Highest)]
|
||||||
public void GetUnixTimestamp(string args)
|
public void GetUnixTimestamp(string args)
|
||||||
{
|
{
|
||||||
while (args.Contains("%tim"))
|
args = args.Replace("%time", DateTimeOffset.Now.ToUnixTimeSeconds().ToString());
|
||||||
{
|
|
||||||
args = args.ReplaceFirstOccurrence("%tim", $"{DateTimeOffset.Now.ToUnixTimeSeconds()}");
|
RuntimeInfo.CurrentLine = args.TrimEnd();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[Statement("%os", SearchMode.Contains, SpaceAround.None, ConsoleColor.Blue, KeepStatementInArgs = true, Priority = Priority.Highest)]
|
||||||
|
public void GetOperatingSystem(string args)
|
||||||
|
{
|
||||||
|
args = args.Replace("%os", Environment.OSVersion.Platform.ToString());
|
||||||
|
|
||||||
|
RuntimeInfo.CurrentLine = args.TrimEnd();
|
||||||
|
}
|
||||||
|
|
||||||
|
[Statement("%cpu", SearchMode.Contains, SpaceAround.None, ConsoleColor.Blue, KeepStatementInArgs = true, Priority = Priority.Highest)]
|
||||||
|
public void GetProcessorArchitecture(string args)
|
||||||
|
{
|
||||||
|
args = args.Replace("%cpu", System.Runtime.InteropServices.RuntimeInformation.ProcessArchitecture.ToString());
|
||||||
|
|
||||||
|
RuntimeInfo.CurrentLine = args.TrimEnd();
|
||||||
|
}
|
||||||
|
|
||||||
|
[Statement("%is64", SearchMode.Contains, SpaceAround.None, ConsoleColor.Blue, KeepStatementInArgs = true, Priority = Priority.Highest)]
|
||||||
|
public void GetIsOperatingSystem64Bit(string args)
|
||||||
|
{
|
||||||
|
args = args.Replace("%is64", $"{Environment.Is64BitOperatingSystem}");
|
||||||
|
|
||||||
RuntimeInfo.CurrentLine = args.TrimEnd();
|
RuntimeInfo.CurrentLine = args.TrimEnd();
|
||||||
}
|
}
|
||||||
@@ -25,7 +46,7 @@ namespace YesNt.Interpreter.Statements
|
|||||||
[Statement("%pi", SearchMode.Contains, SpaceAround.None, ConsoleColor.Blue, KeepStatementInArgs = true, Priority = Priority.Highest)]
|
[Statement("%pi", SearchMode.Contains, SpaceAround.None, ConsoleColor.Blue, KeepStatementInArgs = true, Priority = Priority.Highest)]
|
||||||
public void GetPi(string args)
|
public void GetPi(string args)
|
||||||
{
|
{
|
||||||
args = args.Replace("%pi", $"{Math.PI}");
|
args = args.Replace("%pi", Math.PI.ToString());
|
||||||
|
|
||||||
RuntimeInfo.CurrentLine = args.TrimEnd();
|
RuntimeInfo.CurrentLine = args.TrimEnd();
|
||||||
}
|
}
|
||||||
@@ -35,7 +56,7 @@ namespace YesNt.Interpreter.Statements
|
|||||||
{
|
{
|
||||||
while (args.Contains("%rnd"))
|
while (args.Contains("%rnd"))
|
||||||
{
|
{
|
||||||
args = args.ReplaceFirstOccurrence("%rnd", $"{random.Next(32767, int.MaxValue)}");
|
args = args.ReplaceFirstOccurrence("%rnd", random.Next(32767, int.MaxValue).ToString());
|
||||||
}
|
}
|
||||||
|
|
||||||
RuntimeInfo.CurrentLine = args.TrimEnd();
|
RuntimeInfo.CurrentLine = args.TrimEnd();
|
||||||
|
|||||||
@@ -9,6 +9,8 @@ namespace YesNt.Interpreter.Statements
|
|||||||
{
|
{
|
||||||
internal class VariableStatements : StatementRuntimeInformation
|
internal class VariableStatements : StatementRuntimeInformation
|
||||||
{
|
{
|
||||||
|
private static readonly Regex variableStatementRegex = new Regex(@">[a-zA-Z0-9]+");
|
||||||
|
|
||||||
[Statement("<", SearchMode.StartOfLine, SpaceAround.None, Priority = Priority.VeryLow)]
|
[Statement("<", SearchMode.StartOfLine, SpaceAround.None, Priority = Priority.VeryLow)]
|
||||||
public void DefineVariable(string args)
|
public void DefineVariable(string args)
|
||||||
{
|
{
|
||||||
@@ -105,7 +107,7 @@ namespace YesNt.Interpreter.Statements
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
MatchCollection matches = Regex.Matches(RuntimeInfo.CurrentLine, @">[a-zA-Z0-9]+");
|
MatchCollection matches = variableStatementRegex.Matches(RuntimeInfo.CurrentLine);
|
||||||
|
|
||||||
for (int i = 0; i < matches.Count; i++)
|
for (int i = 0; i < matches.Count; i++)
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user