process cases of ALT as special rules

This commit is contained in:
Youmu Liu
2026-09-10 18:17:09 +08:00
parent 8755185e78
commit f372f83171
18 changed files with 486 additions and 166 deletions
+32
View File
@@ -16,4 +16,36 @@ Run the active debug harness directly when investigating a subsystem:
dotnet run --project test/StgSharpDebug/StgSharpDebug.csproj
```
## NGRA generation preview
`StgSharpDebug/TestRegexGenerate.cs` contains a standalone debugging routine that calls the
existing NGRA emitter without Roslyn attribute binding. Select it from the debug `Main`:
```powershell
dotnet run --project test/StgSharpDebug/StgSharpDebug.csproj -- --regex-preview
```
This branch returns before `World` or native-memory initialization. Without the switch, the
existing debug flow is unchanged. You can also call `TestRegexGenerate.Run()` directly from
`Main` while debugging; pass a pattern to `Run("abc")` for a single preview.
The switch only selects runtime behavior; building the debug project still builds its normal
project references, including Graphics and Mathematics, and prepares the native library with
CMake. `BuildNativeBeforeManaged` defaults to true; Debug selects `clang-debug`, and other
configurations select `clang-release`. `RequireNativeLibrary` reports a missing DLL at build
time instead of allowing the default runtime path to fail later.
For managed-only preview work without a native toolchain or DLL, add
`-p:BuildNativeBeforeManaged=false -p:RequireNativeLibrary=false` before `--` in the run command.
Enter raw regular expressions without C# string delimiters. The routine prints only the emitted
code, without status headers or file output. Exceptions propagate directly to the caller/debugger.
Use `:exit` or end-of-input to leave the loop. Empty input is an empty regex. For one-shot mode:
```powershell
dotnet run --project test/StgSharpDebug/StgSharpDebug.csproj -- --regex-preview 'a{2,3}'
```
Set breakpoints in `TestRegexGenerate.cs` or any existing `Generate*` method. The output is a
method-body fragment; this routine does not compile or execute it.
New repeatable tests should use a test project and avoid machine-specific paths, external mutable data, and dependencies on previous test execution. Keep one-off investigations in `SingleFile` or the manual debug harness until their expected behavior is stable enough for automation.
+12 -10
View File
@@ -5,13 +5,13 @@
// SPDX-License-Identifier: MIT
// -----------------------------------------------------------------------------
using Nitload.Graphics;
using Nitload.Common.HighPerformance.Memory;
using Nitload.Common.Internal;
using Nitload.Common.Timing;
using Nitload.Common.Timing;
using Nitload.Graphics;
using Nitload.Mathematics;
using Nitload.Mathematics.Numeric;
using Nitload.Common.Timing;
using Nitload.Common.Timing;
using System;
using System.Runtime.InteropServices;
@@ -28,6 +28,13 @@ namespace Nitload
string[] args
)
{
// Select the managed-only emitter preview before initializing the normal runtime.
if (args.Length > 0 && args[0] == "--regex-preview")
{
Environment.ExitCode = TestRegexGenerate.Run(args[1..]);
return;
}
try
{
World.Initialize(new()
@@ -39,13 +46,8 @@ namespace Nitload
// .UseModule<GraphicModule>()
.InitializeModule();
_ = SlabAllocator.FromBuffer<int>(
(nuint)NativeMemory.AlignedAlloc(65536 * 4, 4),
65536,
buffer => NativeMemory.AlignedFree((void*)buffer)
);
TestRegexAnalyse.Run();
// TestRegexAnalyse.Run();
_ = TestRegexGenerate.Run("abc|123");
// TestHlsf();
+9 -1
View File
@@ -2,6 +2,10 @@
<PropertyGroup>
<OutputType>Exe</OutputType>
<BuildNativeBeforeManaged>true</BuildNativeBeforeManaged>
<RequireNativeLibrary>true</RequireNativeLibrary>
<!-- Let MSBuild run the incremental CMake build even when managed inputs are unchanged. -->
<DisableFastUpToDateCheck>true</DisableFastUpToDateCheck>
</PropertyGroup>
@@ -9,6 +13,11 @@
<None Remove="SSG_errorlog.log" />
</ItemGroup>
<ItemGroup>
<!-- The debug host calls the emitter directly and needs Roslyn at runtime. -->
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" Version="4.13.0" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\src\Nitload.Common\Nitload.Common.csproj" />
<ProjectReference Include="..\..\src\Nitload.Graphics\Nitload.Graphics.csproj" />
@@ -18,4 +27,3 @@
</ItemGroup>
</Project>
+65
View File
@@ -0,0 +1,65 @@
// -----------------------------------------------------------------------------
// file="TestRegexGenerate"
// Project: Nitload
// Copyright (c) Nitload.
// SPDX-License-Identifier: MIT
// -----------------------------------------------------------------------------
using Nitload.RegularAnalysis.Abstraction;
using Nitload.RegularAnalysis.Text;
using System;
using System.Collections.Generic;
using System.Runtime.ExceptionServices;
using static Nitload.RegularAnalysis.Text.TextRegexSourceGen;
namespace Nitload
{
internal static class TestRegexGenerate
{
public static int Run(params string[] args)
{
if (args.Length > 1) {
throw new ArgumentException("Expected at most one regex pattern.", nameof(args));
}
if (args.Length == 1)
{
Print(args[0]);
return 0;
}
while (true)
{
Console.Write("regex> ");
string? pattern = Console.ReadLine();
if (pattern is null or ":exit") {
return 0;
}
Print(pattern);
}
}
private static void Print(string pattern)
{
TextRegexSource analysis = RegexAnalyzer.Analyze(pattern);
if (analysis.AnalyseException is not null) {
ExceptionDispatchInfo.Throw(analysis.AnalyseException);
}
SequenceEmitter<string> body = new();
List<SequenceEmitter<string>> functions = [];
SourceGenContext context = new();
ExitLabel exit = context.RequestExitLabel(ExitMode.Goto);
GenerateMethodSource(analysis.Ast.Root, body, functions, context, exit);
foreach (string line in body.ToList()) {
Console.WriteLine(line);
}
foreach (SequenceEmitter<string> function in functions)
{
foreach (string line in function.ToList()) {
Console.WriteLine(line);
}
}
}
}
}