Skip to content

Commit c20f4c6

Browse files
committed
refactor & modernize code base
1 parent 9cf0f66 commit c20f4c6

File tree

73 files changed

+7733
-7705
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

73 files changed

+7733
-7705
lines changed

.editorconfig

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
[*.cs]
2+
3+
# IDE0290: Use primary constructor
4+
csharp_style_prefer_primary_constructors = false:suggestion
5+
6+
# IDE0090: Use 'new(...)'
7+
csharp_style_implicit_object_creation_when_type_is_apparent = false
8+
9+
# IDE0017: Simplify object initialization
10+
dotnet_style_object_initializer = false
11+
12+
###
13+
14+
csharp_using_directive_placement = outside_namespace:silent
15+
csharp_prefer_simple_using_statement = true:suggestion
16+
csharp_prefer_braces = true:silent
17+
csharp_style_namespace_declarations = block_scoped:silent
18+
csharp_style_prefer_method_group_conversion = true:silent
19+
csharp_style_prefer_top_level_statements = true:silent
20+
csharp_prefer_system_threading_lock = true:suggestion
21+
csharp_style_expression_bodied_methods = false:silent
22+
csharp_style_expression_bodied_constructors = false:silent
23+
csharp_style_expression_bodied_operators = false:silent
24+
csharp_style_expression_bodied_properties = true:silent
25+
csharp_style_expression_bodied_indexers = true:silent
26+
csharp_style_expression_bodied_accessors = true:silent
27+
csharp_style_expression_bodied_lambdas = true:silent
28+
csharp_style_expression_bodied_local_functions = false:silent
29+
csharp_indent_labels = one_less_than_current
30+
31+
[*.{cs,vb}]
32+
#### Naming styles ####
33+
34+
# Naming rules
35+
36+
dotnet_naming_rule.interface_should_be_begins_with_i.severity = suggestion
37+
dotnet_naming_rule.interface_should_be_begins_with_i.symbols = interface
38+
dotnet_naming_rule.interface_should_be_begins_with_i.style = begins_with_i
39+
40+
dotnet_naming_rule.types_should_be_pascal_case.severity = suggestion
41+
dotnet_naming_rule.types_should_be_pascal_case.symbols = types
42+
dotnet_naming_rule.types_should_be_pascal_case.style = pascal_case
43+
44+
dotnet_naming_rule.non_field_members_should_be_pascal_case.severity = suggestion
45+
dotnet_naming_rule.non_field_members_should_be_pascal_case.symbols = non_field_members
46+
dotnet_naming_rule.non_field_members_should_be_pascal_case.style = pascal_case
47+
48+
# Symbol specifications
49+
50+
dotnet_naming_symbols.interface.applicable_kinds = interface
51+
dotnet_naming_symbols.interface.applicable_accessibilities = public, internal, private, protected, protected_internal, private_protected
52+
dotnet_naming_symbols.interface.required_modifiers =
53+
54+
dotnet_naming_symbols.types.applicable_kinds = class, struct, interface, enum
55+
dotnet_naming_symbols.types.applicable_accessibilities = public, internal, private, protected, protected_internal, private_protected
56+
dotnet_naming_symbols.types.required_modifiers =
57+
58+
dotnet_naming_symbols.non_field_members.applicable_kinds = property, event, method
59+
dotnet_naming_symbols.non_field_members.applicable_accessibilities = public, internal, private, protected, protected_internal, private_protected
60+
dotnet_naming_symbols.non_field_members.required_modifiers =
61+
62+
# Naming styles
63+
64+
dotnet_naming_style.begins_with_i.required_prefix = I
65+
dotnet_naming_style.begins_with_i.required_suffix =
66+
dotnet_naming_style.begins_with_i.word_separator =
67+
dotnet_naming_style.begins_with_i.capitalization = pascal_case
68+
69+
dotnet_naming_style.pascal_case.required_prefix =
70+
dotnet_naming_style.pascal_case.required_suffix =
71+
dotnet_naming_style.pascal_case.word_separator =
72+
dotnet_naming_style.pascal_case.capitalization = pascal_case
73+
74+
dotnet_naming_style.pascal_case.required_prefix =
75+
dotnet_naming_style.pascal_case.required_suffix =
76+
dotnet_naming_style.pascal_case.word_separator =
77+
dotnet_naming_style.pascal_case.capitalization = pascal_case
78+
dotnet_style_coalesce_expression = true:suggestion
79+
dotnet_style_operator_placement_when_wrapping = beginning_of_line
80+
tab_width = 4
81+
indent_size = 4
82+
end_of_line = crlf
83+
dotnet_style_null_propagation = true:suggestion

GTAdhocToolchain.CLI/GTAdhocToolchain.CLI.csproj

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@
88
<BaseOutputPath></BaseOutputPath>
99
<AssemblyName>adhoc</AssemblyName>
1010
<SignAssembly>False</SignAssembly>
11-
<AssemblyVersion>1.2.1</AssemblyVersion>
12-
<FileVersion>1.2.1</FileVersion>
13-
<Version>1.2.1</Version>
11+
<AssemblyVersion>1.2.2</AssemblyVersion>
12+
<FileVersion>1.2.2</FileVersion>
13+
<Version>1.2.2</Version>
1414
</PropertyGroup>
1515

1616
<ItemGroup>

GTAdhocToolchain.CLI/Program.cs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -369,13 +369,12 @@ private static void BuildScript(string inputPath, string output, uint version =
369369
return;
370370
}
371371

372-
var compiler = new AdhocScriptCompiler();
372+
var compiler = new AdhocScriptCompiler(version);
373373
if (!string.IsNullOrWhiteSpace(baseIncludeFolder))
374374
{
375375
compiler.SetBaseIncludeFolder(absoluteIncludePath);
376376
}
377377
compiler.SetSourcePath(inputPath);
378-
compiler.Setup(version);
379378

380379
if (debugExceptions)
381380
compiler.BuildTryCatchDebugStatements();
@@ -435,7 +434,7 @@ private static void DissasemblyRepl(DissasemblyReplVerbs replVerbs)
435434
}
436435
else if (line.StartsWith("/version"))
437436
{
438-
ReadOnlySpan<char> range = line.AsSpan().Slice("/version".Length).Trim();
437+
ReadOnlySpan<char> range = line.AsSpan()["/version".Length..].Trim();
439438
if (range.IsEmpty)
440439
{
441440
Console.WriteLine($"Current adhoc version is set to {replVerbs.Version}.");
@@ -476,9 +475,8 @@ private static void DissasemblyRepl(DissasemblyReplVerbs replVerbs)
476475
{
477476
try
478477
{
479-
var compiler = new AdhocScriptCompiler();
478+
var compiler = new AdhocScriptCompiler(replVerbs.Version);
480479
compiler.SetSourcePath("test.ad");
481-
compiler.Setup(replVerbs.Version);
482480
compiler.CompileScript(program);
483481

484482
AdhocCodeGen codeGen = new AdhocCodeGen(compiler.MainFrame, compiler.SymbolMap);

GTAdhocToolchain.CodeGen/AdhocCodeGen.cs

Lines changed: 36 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -9,54 +9,53 @@
99
using GTAdhocToolchain.Core.Instructions;
1010
using GTAdhocToolchain.Core;
1111

12-
namespace GTAdhocToolchain.CodeGen
12+
namespace GTAdhocToolchain.CodeGen;
13+
14+
public class AdhocCodeGen
1315
{
14-
public class AdhocCodeGen
15-
{
16-
private static readonly NLog.Logger Logger = NLog.LogManager.GetCurrentClassLogger();
16+
private static readonly NLog.Logger Logger = NLog.LogManager.GetCurrentClassLogger();
1717

18-
public AdhocCodeFrame Frame { get; set; }
19-
public AdhocSymbolMap SymbolMap { get; set; }
18+
public AdhocCodeFrame Frame { get; set; }
19+
public AdhocSymbolMap SymbolMap { get; set; }
2020

21-
private AdhocStream stream;
21+
private AdhocStream stream;
2222

23-
public AdhocCodeGen(AdhocCodeFrame frame, AdhocSymbolMap symbols)
24-
{
25-
Frame = frame;
26-
SymbolMap = symbols;
27-
}
23+
public AdhocCodeGen(AdhocCodeFrame frame, AdhocSymbolMap symbols)
24+
{
25+
Frame = frame;
26+
SymbolMap = symbols;
27+
}
2828

29-
public void Generate()
30-
{
31-
Logger.Info("Generating code...");
32-
var ms = new MemoryStream();
33-
stream = new AdhocStream(ms, Frame.Version);
29+
public void Generate()
30+
{
31+
Logger.Info("Generating code...");
32+
var ms = new MemoryStream();
33+
stream = new AdhocStream(ms, Frame.Version);
3434

35-
// ADhoc Compiled Header?
36-
stream.WriteString($"ADCH{Frame.Version.VersionNumber:D3}", StringCoding.ZeroTerminated); // ADCH012
35+
// ADhoc Compiled Header?
36+
stream.WriteString($"ADCH{Frame.Version.VersionNumber:D3}", StringCoding.ZeroTerminated); // ADCH012
3737

38-
if (Frame.Version.HasSymbolTable())
39-
SerializeSymbolTable();
38+
if (Frame.Version.HasSymbolTable())
39+
SerializeSymbolTable();
4040

41-
Frame.Write(stream);
41+
Frame.Write(stream);
4242

43-
Logger.Info($"Code generated (Size: {stream.Length} bytes, {Frame.Instructions.Count} main instructions)");
44-
Logger.Debug($"[Stack] Stack Size: {Frame.Stack.GetStackSize()} - Locals: {Frame.Stack.GetLocalVariableStorageSize()}");
45-
}
43+
Logger.Info($"Code generated (Size: {stream.Length} bytes, {Frame.Instructions.Count} main instructions)");
44+
Logger.Debug($"[Stack] Stack Size: {Frame.Stack.GetStackSize()} - Locals: {Frame.Stack.GetLocalVariableStorageSize()}");
45+
}
4646

47-
public void SaveTo(string path)
48-
{
49-
File.WriteAllBytes(path, (stream.BaseStream as MemoryStream).ToArray());
50-
Logger.Info($"Compiled script -> '{path}'");
51-
}
47+
public void SaveTo(string path)
48+
{
49+
File.WriteAllBytes(path, (stream.BaseStream as MemoryStream).ToArray());
50+
Logger.Info($"Compiled script -> '{path}'");
51+
}
5252

53-
private void SerializeSymbolTable()
54-
{
55-
Logger.Debug($"Serializing symbol table ({SymbolMap.Symbols.Count} symbols)");
53+
private void SerializeSymbolTable()
54+
{
55+
Logger.Debug($"Serializing symbol table ({SymbolMap.Symbols.Count} symbols)");
5656

57-
stream.WriteVarInt(SymbolMap.Symbols.Count);
58-
foreach (AdhocSymbol symb in SymbolMap.Symbols.Values)
59-
stream.WriteVarString(symb.Name, !symb.HasHexEscape);
60-
}
57+
stream.WriteVarInt(SymbolMap.Symbols.Count);
58+
foreach (AdhocSymbol symb in SymbolMap.Symbols.Values)
59+
stream.WriteVarString(symb.Name, !symb.HasHexEscape);
6160
}
6261
}

GTAdhocToolchain.CodeGen/GTAdhocToolchain.CodeGen.csproj

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
<PropertyGroup>
44
<TargetFramework>net9.0</TargetFramework>
55
<ImplicitUsings>enable</ImplicitUsings>
6-
<Nullable>disable</Nullable>
76
</PropertyGroup>
87

98
<ItemGroup>

GTAdhocToolchain.Compiler/AdhocCompilationException.cs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,13 @@
44
using System.Text;
55
using System.Threading.Tasks;
66

7-
namespace GTAdhocToolchain.Compiler
7+
namespace GTAdhocToolchain.Compiler;
8+
9+
public class AdhocCompilationException : Exception
810
{
9-
public class AdhocCompilationException : Exception
11+
public AdhocCompilationException(string message)
12+
: base(message)
1013
{
11-
public AdhocCompilationException(string message)
12-
: base(message)
13-
{
1414

15-
}
1615
}
1716
}

0 commit comments

Comments
 (0)