Skip to content

Commit eeff94e

Browse files
committed
validator was broken, won't push yet
(working on performance)
1 parent cc77625 commit eeff94e

File tree

16 files changed

+136
-110
lines changed

16 files changed

+136
-110
lines changed

RSML.Benchmarks/EvaluatorBenchmarks.cs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,29 +15,27 @@ namespace RSML.Benchmarks
1515
{
1616

1717
[MemoryDiagnoser]
18-
[SimpleJob(RuntimeMoniker.Net80, warmupCount: 2, iterationCount: 3)]
18+
[SimpleJob(RuntimeMoniker.Net80, warmupCount: 10, iterationCount: 50)]
1919
[HideColumns("Job", "StdDev")]
2020
[GroupBenchmarksBy(BenchmarkLogicalGroupRule.ByCategory)]
2121
[SuppressMessage("Performance", "CA1822:Mark members as static")]
2222
public class EvaluatorBenchmarks
2323
{
2424

25+
private const string SmallContent = "-> windows \"value\"\n@SpecialAction arg\n# Comment";
26+
2527
private readonly LocalMachine ubuntu = new("ubuntu", null, null);
2628

2729
private string? complexContent1;
2830
private string? complexContent2;
2931

30-
private const string SmallContent = "-> windows \"value\"\n@SpecialAction arg\n# Comment";
31-
private string? mediumContent;
32-
private string? largeContent;
33-
3432
private Evaluator? complexEvaluator1;
3533
private Evaluator? complexEvaluator2;
3634
private Evaluator? complexEvaluator3;
37-
38-
private Evaluator? smallEvaluator;
39-
private Evaluator? mediumEvaluator;
35+
private string? largeContent;
4036
private Evaluator? largeEvaluator;
37+
private string? mediumContent;
38+
private Evaluator? mediumEvaluator;
4139

4240
private Evaluator? primitiveEvaluatorAction;
4341
private Evaluator? primitiveEvaluatorComment;
@@ -46,6 +44,8 @@ public class EvaluatorBenchmarks
4644
private Evaluator? primitiveEvaluatorLogic;
4745
private Evaluator? primitiveEvaluatorNewlines;
4846

47+
private Evaluator? smallEvaluator;
48+
4949
[GlobalSetup]
5050
public void Setup()
5151
{

RSML.CLI/Helpers/LocalMachineOutput.cs

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ namespace RSML.CLI.Helpers
1313
internal static class LocalMachineOutput
1414
{
1515

16+
private static string Quote(string? str) => str is null or "null" ? "null" : $"\"{str}\"";
17+
1618
public static LocalMachine FromJson(string? json)
1719
{
1820

@@ -26,8 +28,8 @@ public static LocalMachine FromJson(string? json)
2628
int sysVersion = system.GetProperty("version").GetInt32();
2729

2830
var linuxDistro = document.RootElement.GetProperty("linuxDistro");
29-
string? distroName = system.GetProperty("name").GetString();
30-
string? distroFamily = system.GetProperty("family").GetString();
31+
string? distroName = linuxDistro.GetProperty("name").GetString();
32+
string? distroFamily = linuxDistro.GetProperty("family").GetString();
3133

3234
string? procArch = document.RootElement.GetProperty("processor").GetProperty("architecture").GetString();
3335

@@ -41,20 +43,20 @@ public static LocalMachine FromJson(string? json)
4143
public static string AsJson(LocalMachine machine)
4244
{
4345

44-
string systemVersion = machine.SystemVersion == -1 ? "null" : machine.SystemVersion.ToString();
46+
string systemVersion = machine.StringifiedSystemVersion ?? "null";
4547

4648
return $$"""
4749
{
4850
"system": {
49-
"name": "{{machine.SystemName ?? "null"}}",
51+
"name": {{Quote(machine.SystemName ?? "null")}},
5052
"version" : {{systemVersion}}
5153
},
5254
"linuxDistro": {
53-
"name": "{{machine.DistroName ?? "null"}}",
54-
"family": "{{machine.DistroFamily ?? "null"}}"
55+
"name": {{Quote(machine.DistroName ?? "null")}},
56+
"family": {{Quote(machine.DistroFamily ?? "null")}}
5557
},
5658
"processor": {
57-
"architecture": "{{machine.ProcessorArchitecture ?? "null"}}"
59+
"architecture": {{Quote(machine.ProcessorArchitecture ?? "null")}}
5860
}
5961
}
6062
""";
@@ -69,12 +71,12 @@ public static string AsPlainText(LocalMachine machine)
6971
{
7072

7173
6 => "Vista",
72-
7 or 8 or 10 or 11 => machine.SystemVersion.ToString(),
74+
7 or 8 or 10 or 11 => machine.StringifiedSystemVersion!,
7375
9 => "8.1",
7476
_ => "Unknown"
7577

7678
}
77-
: machine.SystemVersion.ToString();
79+
: machine.StringifiedSystemVersion ?? "Unknown";
7880

7981
if (machine.SystemVersion == -1)
8082
systemVersion = "Unknown";
@@ -99,12 +101,12 @@ public static void AsPrettyText(LocalMachine machine)
99101
{
100102

101103
6 => "Vista",
102-
7 or 8 or 10 or 11 => machine.SystemVersion.ToString(),
104+
7 or 8 or 10 or 11 => machine.StringifiedSystemVersion!,
103105
9 => "8.1",
104106
_ => "Unknown"
105107

106108
}
107-
: machine.SystemVersion.ToString();
109+
: machine.StringifiedSystemVersion ?? "Unknown";
108110

109111
if (machine.SystemVersion == -1)
110112
systemVersion = "Unknown";

RSML.Performance/RSML.Performance.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@
3232
<Link>Icon.png</Link>
3333
</None>
3434
<None Update="Icon.png">
35-
<Pack>True</Pack>
36-
<PackagePath></PackagePath>
35+
<Pack>True</Pack>
36+
<PackagePath></PackagePath>
3737
</None>
3838
</ItemGroup>
3939

RSML.Performance/Value/OptimizedLexer.cs renamed to RSML.Performance/Stateless/OptimizedLexer.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
using System;
22

33
using RSML.Analyzer.Syntax;
4+
using RSML.Performance.Value;
45
using RSML.Toolchain.Compliance;
56

67

7-
namespace RSML.Performance.Value
8+
namespace RSML.Performance.Stateless
89
{
910

1011
/// <summary>

RSML.Performance/Value/OptimizedNormalizer.cs renamed to RSML.Performance/Stateless/OptimizedNormalizer.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
using System;
22

33
using RSML.Analyzer.Syntax;
4+
using RSML.Performance.Value;
45
using RSML.Toolchain.Compliance;
56

67

7-
namespace RSML.Performance.Value
8+
namespace RSML.Performance.Stateless
89
{
910

1011
/// <summary>
@@ -141,6 +142,7 @@ public static SyntaxLine NormalizeLine(SyntaxLine line, out int length)
141142

142143
default:
143144
length = 0;
145+
144146
return new();
145147
}
146148

RSML.Performance/Value/OptimizedValidator.cs renamed to RSML.Performance/Stateless/OptimizedValidator.cs

Lines changed: 23 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
using System;
2-
using System.Linq;
32

43
using RSML.Analyzer.Semantics;
54
using RSML.Analyzer.Syntax;
65
using RSML.Exceptions;
6+
using RSML.Performance.Value;
77
using RSML.Toolchain.Compliance;
88

99

10-
namespace RSML.Performance.Value
10+
namespace RSML.Performance.Stateless
1111
{
1212

1313
/// <summary>
@@ -29,19 +29,23 @@ public static class OptimizedValidator
2929
public static void ValidateLine(SyntaxLine line)
3030
{
3131

32-
if (line.Length == 0)
32+
int len = line.Length;
33+
34+
if (len == 0)
3335
throw new InvalidRsmlSyntax("Empty token sequence.");
3436

35-
if (line.Length != 1 && line[line.Last()].Kind == TokenKind.Eol)
37+
if (len != 1 && line[line.Last()].Kind == TokenKind.Eol)
3638
line.Remove(line.Last()); // removes last
3739

40+
len = line.Length; // recalculate cuz it changed
41+
3842
switch (line[0].Kind)
3943
{
4044

4145
case TokenKind.Eol or TokenKind.Eof:
4246
return; // we're done here
4347

44-
case TokenKind.CommentSymbol when line.Length != 2:
48+
case TokenKind.CommentSymbol when len != 2:
4549
throw new InvalidRsmlSyntax(
4650
"A comment must be 2 tokens long."
4751
); // even if you have a comment with no text not even spaces, you'll have 2 tokens
@@ -55,7 +59,7 @@ public static void ValidateLine(SyntaxLine line)
5559
case TokenKind.CommentSymbol:
5660
return;
5761

58-
case TokenKind.SpecialActionSymbol when line.Length != 3:
62+
case TokenKind.SpecialActionSymbol when len != 3:
5963
throw new InvalidRsmlSyntax("A special action must be 3 tokens long."); // even with no arg, you'll have 3 tokens
6064

6165
case TokenKind.SpecialActionSymbol when !line[0].Value.IsEquals("@"):
@@ -78,7 +82,7 @@ public static void ValidateLine(SyntaxLine line)
7882
if (!line[0].Value.IsEquals("!>") && !line[0].Value.IsEquals("->"))
7983
throw new InvalidRsmlSyntax("Operator must be one of !> or ->.");
8084

81-
switch (line.Length)
85+
switch (len)
8286
{
8387

8488
case 2:
@@ -94,15 +98,13 @@ public static void ValidateLine(SyntaxLine line)
9498
line[2].Kind != TokenKind.LogicPathValue)
9599
throw new InvalidRsmlSyntax("A 3 token long logic path must be a *Operator + SystemName + LogicPathValue overload.");
96100

97-
string sysName1 = line[1].Value.ToString();
98-
99101
if (!line[1].Value.IsEquals("any") && line[1].Kind == TokenKind.WildcardKeyword)
100102
throw new InvalidRsmlSyntax("A token of type WildcardKeyword must have a value of 'any'.");
101103

102104
if (!line[1].Value.IsEquals("defined") && line[1].Kind == TokenKind.DefinedKeyword)
103105
throw new InvalidRsmlSyntax("A token of type DefinedKeyword must have a value of 'defined'.");
104106

105-
if (!Validator.ValidSystems.Any(s => sysName1.Equals(s, StringComparison.OrdinalIgnoreCase)) &&
107+
if (!line[1].Value.IsAsciiEqualsIgnoreCase(Validator.ValidSystems) &&
106108
line[1].Kind == TokenKind.SystemName)
107109
throw new InvalidRsmlSyntax("Invalid system name as of v2.0.0.");
108110

@@ -122,9 +124,6 @@ public static void ValidateLine(SyntaxLine line)
122124
);
123125
}
124126

125-
string sysName2 = line[1].Value.ToString();
126-
string archName1 = line[2].Value.ToString();
127-
128127
if (!line[1].Value.IsEquals("any") && line[1].Kind == TokenKind.WildcardKeyword)
129128
throw new InvalidRsmlSyntax("A token of type WildcardKeyword must have a value of 'any'.");
130129

@@ -137,12 +136,11 @@ public static void ValidateLine(SyntaxLine line)
137136
if (!line[2].Value.IsEquals("defined") && line[2].Kind == TokenKind.DefinedKeyword)
138137
throw new InvalidRsmlSyntax("A token of type DefinedKeyword must have a value of 'defined'.");
139138

140-
if (!Validator.ValidSystems.Any(s => sysName2.Equals(s, StringComparison.OrdinalIgnoreCase)) &&
141-
line[1].Kind == TokenKind.SystemName)
139+
if (!line[1].Value.IsAsciiEqualsIgnoreCase(Validator.ValidSystems) && line[1].Kind == TokenKind.SystemName)
142140
throw new InvalidRsmlSyntax("Invalid system name as of v2.0.0.");
143141

144-
if (!Validator.ValidArchitectures.Any(s => archName1.Equals(s, StringComparison.OrdinalIgnoreCase)) &&
145-
line[2].Kind == TokenKind.ArchitectureIdentifier)
142+
// ReSharper disable once InvertIf
143+
if (!line[2].Value.IsAsciiEqualsIgnoreCase(Validator.ValidArchitectures) && line[2].Kind == TokenKind.ArchitectureIdentifier)
146144
throw new InvalidRsmlSyntax("Invalid architecture identifier as of v2.0.0.");
147145

148146
return;
@@ -164,10 +162,6 @@ public static void ValidateLine(SyntaxLine line)
164162
);
165163
}
166164

167-
string sysName3 = line[1].Value.ToString();
168-
string major1 = line[2].Value.ToString();
169-
string archName2 = line[3].Value.ToString();
170-
171165
if (!line[1].Value.IsEquals("any") && line[1].Kind == TokenKind.WildcardKeyword)
172166
throw new InvalidRsmlSyntax("A token of type WildcardKeyword must have a value of 'any'.");
173167

@@ -186,15 +180,13 @@ public static void ValidateLine(SyntaxLine line)
186180
if (!line[3].Value.IsEquals("defined") && line[3].Kind == TokenKind.DefinedKeyword)
187181
throw new InvalidRsmlSyntax("A token of type DefinedKeyword must have a value of 'defined'.");
188182

189-
if (!Validator.ValidSystems.Any(s => sysName3.Equals(s, StringComparison.OrdinalIgnoreCase)) &&
190-
line[1].Kind == TokenKind.SystemName)
191-
throw new InvalidRsmlSyntax($"Invalid system name ({sysName3}) as of v2.0.0.");
183+
if (!line[1].Value.IsAsciiEqualsIgnoreCase(Validator.ValidSystems) && line[1].Kind == TokenKind.SystemName)
184+
throw new InvalidRsmlSyntax("Invalid system name as of v2.0.0.");
192185

193-
if (!Validator.ValidArchitectures.Any(s => archName2.Equals(s, StringComparison.OrdinalIgnoreCase)) &&
194-
line[3].Kind == TokenKind.ArchitectureIdentifier)
186+
if (!line[3].Value.IsAsciiEqualsIgnoreCase(Validator.ValidArchitectures) && line[3].Kind == TokenKind.ArchitectureIdentifier)
195187
throw new InvalidRsmlSyntax("Invalid architecture identifier as of v2.0.0.");
196188

197-
if (!Int32.TryParse(major1, out _) && line[2].Kind == TokenKind.MajorVersionId)
189+
if (!Int32.TryParse(line[2].Value, out _) && line[2].Kind == TokenKind.MajorVersionId)
198190
throw new InvalidRsmlSyntax("The major version must be a valid integer");
199191

200192
return;
@@ -222,11 +214,6 @@ public static void ValidateLine(SyntaxLine line)
222214
);
223215
}
224216

225-
string sysName4 = line[1].Value.ToString();
226-
string comp = line[2].Value.ToString();
227-
string major2 = line[3].Value.ToString();
228-
string archName3 = line[4].Value.ToString();
229-
230217
if (!line[1].Value.IsEquals("any") && line[1].Kind == TokenKind.WildcardKeyword)
231218
throw new InvalidRsmlSyntax("A token of type WildcardKeyword must have a value of 'any'.");
232219

@@ -239,18 +226,16 @@ public static void ValidateLine(SyntaxLine line)
239226
if (!line[4].Value.IsEquals("defined") && line[4].Kind == TokenKind.DefinedKeyword)
240227
throw new InvalidRsmlSyntax("A token of type DefinedKeyword must have a value of 'defined'.");
241228

242-
if (!Validator.ValidSystems.Any(s => sysName4.Equals(s, StringComparison.OrdinalIgnoreCase)) &&
243-
line[1].Kind == TokenKind.SystemName)
229+
if (!line[1].Value.IsAsciiEqualsIgnoreCase(Validator.ValidSystems) && line[1].Kind == TokenKind.SystemName)
244230
throw new InvalidRsmlSyntax("Invalid system name as of v2.0.0.");
245231

246-
if (!Validator.ValidArchitectures.Any(s => archName3.Equals(s, StringComparison.OrdinalIgnoreCase)) &&
247-
line[1].Kind == TokenKind.ArchitectureIdentifier)
232+
if (!line[4].Value.IsAsciiEqualsIgnoreCase(Validator.ValidArchitectures) && line[4].Kind == TokenKind.ArchitectureIdentifier)
248233
throw new InvalidRsmlSyntax("Invalid architecture identifier as of v2.0.0.");
249234

250-
if (!Validator.ValidComparators.Any(s => comp.Equals(s, StringComparison.OrdinalIgnoreCase)))
235+
if (!line[2].Value.IsAsciiEqualsIgnoreCase(Validator.ValidComparators))
251236
throw new InvalidRsmlSyntax("Invalid comparator.");
252237

253-
if (!Int32.TryParse(major2, out _))
238+
if (!Int32.TryParse(line[3].Value, out _))
254239
throw new InvalidRsmlSyntax("The major version must be a valid integer. Wildcards are not compatible with comparators.");
255240

256241
return;

RSML.Performance/Stateless/StatelessEvaluator.cs

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
using System.Collections.Generic;
33

44
using RSML.Actions;
5-
using RSML.Analyzer.Semantics;
65
using RSML.Analyzer.Syntax;
76
using RSML.Evaluation;
87
using RSML.Exceptions;
@@ -170,7 +169,7 @@ private static bool HandleLogicPath_Simple(SyntaxLine tokens, in LocalMachine ma
170169

171170
TokenKind.WildcardKeyword => true,
172171
TokenKind.DefinedKeyword => machine.SystemVersion != -1,
173-
_ => tokens[2].Value.IsEquals(machine.SystemVersion.ToString())
172+
_ => tokens[2].Value.IsEquals(machine.StringifiedSystemVersion)
174173

175174
};
176175

@@ -210,12 +209,12 @@ private static bool HandleLogicPath_Complex(SyntaxLine tokens, in LocalMachine m
210209
{
211210

212211
case TokenKind.Equals:
213-
systemVersionMatches = tokens[3].Value.IsEquals(machine.SystemVersion.ToString());
212+
systemVersionMatches = tokens[3].Value.IsEquals(machine.StringifiedSystemVersion);
214213

215214
break;
216215

217216
case TokenKind.Different:
218-
systemVersionMatches = !tokens[3].Value.IsEquals(machine.SystemVersion.ToString());
217+
systemVersionMatches = !tokens[3].Value.IsEquals(machine.StringifiedSystemVersion);
219218

220219
break;
221220

@@ -282,7 +281,7 @@ private static bool HandleLogicPath_Simple_Linux(SyntaxLine tokens, in LocalMach
282281

283282
TokenKind.WildcardKeyword => true,
284283
TokenKind.DefinedKeyword => machine.SystemVersion != -1,
285-
_ => tokens[2].Value.IsEquals(machine.SystemVersion.ToString())
284+
_ => tokens[2].Value.IsEquals(machine.StringifiedSystemVersion)
286285

287286
};
288287

@@ -321,12 +320,12 @@ private static bool HandleLogicPath_Complex_Linux(SyntaxLine tokens, in LocalMac
321320
{
322321

323322
case TokenKind.Equals:
324-
systemVersionMatches = tokens[3].Value.IsEquals(machine.SystemVersion.ToString());
323+
systemVersionMatches = tokens[3].Value.IsEquals(machine.StringifiedSystemVersion);
325324

326325
break;
327326

328327
case TokenKind.Different:
329-
systemVersionMatches = !tokens[3].Value.IsEquals(machine.SystemVersion.ToString());
328+
systemVersionMatches = !tokens[3].Value.IsEquals(machine.StringifiedSystemVersion);
330329

331330
break;
332331

0 commit comments

Comments
 (0)