diff --git a/YesNt.Interpreter/Runtime/RuntimeInformation.cs b/YesNt.Interpreter/Runtime/RuntimeInformation.cs index 0833eb0..9b5efc1 100644 --- a/YesNt.Interpreter/Runtime/RuntimeInformation.cs +++ b/YesNt.Interpreter/Runtime/RuntimeInformation.cs @@ -6,7 +6,7 @@ using YesNt.Interpreter.Utilities; namespace YesNt.Interpreter.Runtime { - internal class RuntimeInformation + internal sealed class RuntimeInformation { private RuntimeInformation parentRuntimeInformation; private static int internalTaskId = 0; diff --git a/YesNt.Interpreter/Statements/PredifinedVariableStatements.cs b/YesNt.Interpreter/Statements/PredifinedVariableStatements.cs index 6974940..6740f44 100644 --- a/YesNt.Interpreter/Statements/PredifinedVariableStatements.cs +++ b/YesNt.Interpreter/Statements/PredifinedVariableStatements.cs @@ -11,13 +11,34 @@ namespace YesNt.Interpreter.Statements { 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) { - while (args.Contains("%tim")) - { - args = args.ReplaceFirstOccurrence("%tim", $"{DateTimeOffset.Now.ToUnixTimeSeconds()}"); - } + args = args.Replace("%time", DateTimeOffset.Now.ToUnixTimeSeconds().ToString()); + + 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(); } @@ -25,7 +46,7 @@ namespace YesNt.Interpreter.Statements [Statement("%pi", SearchMode.Contains, SpaceAround.None, ConsoleColor.Blue, KeepStatementInArgs = true, Priority = Priority.Highest)] public void GetPi(string args) { - args = args.Replace("%pi", $"{Math.PI}"); + args = args.Replace("%pi", Math.PI.ToString()); RuntimeInfo.CurrentLine = args.TrimEnd(); } @@ -35,7 +56,7 @@ namespace YesNt.Interpreter.Statements { 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(); diff --git a/YesNt.Interpreter/Statements/VariableStatements.cs b/YesNt.Interpreter/Statements/VariableStatements.cs index 8716075..3d2e48a 100644 --- a/YesNt.Interpreter/Statements/VariableStatements.cs +++ b/YesNt.Interpreter/Statements/VariableStatements.cs @@ -9,6 +9,8 @@ namespace YesNt.Interpreter.Statements { internal class VariableStatements : StatementRuntimeInformation { + private static readonly Regex variableStatementRegex = new Regex(@">[a-zA-Z0-9]+"); + [Statement("<", SearchMode.StartOfLine, SpaceAround.None, Priority = Priority.VeryLow)] public void DefineVariable(string args) { @@ -105,7 +107,7 @@ namespace YesNt.Interpreter.Statements 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++) {