add ir emitter

This commit is contained in:
Youmu Liu
2026-06-16 21:04:51 +08:00
parent 3cfd29f793
commit a7bb3209dd
9 changed files with 711 additions and 148 deletions
+64 -79
View File
@@ -38,13 +38,10 @@ namespace StgSharp.RegularAnalysis.TextRegex
Search = 0,
Jump = 1,
Compare = 2,
Check = 3,
Uncheck = 4,
Span = 5,
Define = 6,
Assign = 7,
Back = 8,
Condition = 2,
Count = 3,
Try = 4,
Pop = 5,
}
@@ -53,10 +50,48 @@ namespace StgSharp.RegularAnalysis.TextRegex
internal abstract RegexIRCommand Command { get; }
public static RegexIR Condition(
int success,
int fail
)
{
return new RegexConditionIR(success, fail);
}
public static RegexIR PopLevel(
bool isSuccess
)
{
return new RegexPopIR(isSuccess);
}
public static RegexIR Try(
int count
)
{
return new RegexTryIR(count);
}
internal abstract void Execute();
}
internal sealed class RegexPopIR(
bool isSuccess
) : RegexIR
{
public bool IsSuccess { get; } = isSuccess;
internal override RegexIRCommand Command => RegexIRCommand.Pop;
internal override void Execute()
{
throw new NotImplementedException();
}
}
/// <summary>
/// Searches for a certain string pattern or charset from current position.
/// </summary>
@@ -92,12 +127,12 @@ namespace StgSharp.RegularAnalysis.TextRegex
}
internal sealed class RegexSearchCharIR(
char c
internal sealed class RegexSearchCharSetIR(
string c
) : RegexIR
{
public char target { get; } = c;
public string Target { get; } = c;
internal override RegexIRCommand Command => RegexIRCommand.Search;
@@ -130,23 +165,7 @@ namespace StgSharp.RegularAnalysis.TextRegex
}
internal sealed class RegexBackIR(
int index
) : RegexIR
{
public int Target { get; } = index;
internal override RegexIRCommand Command => RegexIRCommand.Back;
internal override void Execute()
{
throw new NotImplementedException();
}
}
internal sealed class RegexCompareIR(
internal sealed class RegexConditionIR(
int success,
int fail
) : RegexIR
@@ -156,7 +175,7 @@ namespace StgSharp.RegularAnalysis.TextRegex
public int FailCase { get; } = fail;
internal override RegexIRCommand Command => RegexIRCommand.Compare;
internal override RegexIRCommand Command => RegexIRCommand.Condition;
internal override void Execute()
{
@@ -165,38 +184,23 @@ namespace StgSharp.RegularAnalysis.TextRegex
}
internal sealed class RegexCheckIR : RegexIR
{
internal override RegexIRCommand Command => RegexIRCommand.Check;
internal override void Execute()
{
throw new NotImplementedException();
}
}
internal sealed class RegexUncheckIR : RegexIR
{
internal override RegexIRCommand Command => RegexIRCommand.Check;
internal override void Execute()
{
throw new NotImplementedException();
}
}
internal sealed class RegexSpanIR(
string name
internal sealed class RegexCountIR(
int min,
int max,
bool isGreedy,
int operation
) : RegexIR
{
public string Name { get; } = name;
public bool IsGreedy { get; } = isGreedy;
internal override RegexIRCommand Command => RegexIRCommand.Span;
public int Min { get; } = min;
public int Max { get; } = max;
public int OperationIndex { get; } = operation;
internal override RegexIRCommand Command => throw new NotImplementedException();
internal override void Execute()
{
@@ -205,33 +209,14 @@ namespace StgSharp.RegularAnalysis.TextRegex
}
internal sealed class RegexDefineCommand(
string name
internal sealed class RegexTryIR(
int count
) : RegexIR
{
public string Name { get; } = name;
public int CountOfCommand { get; } = count;
internal override RegexIRCommand Command => RegexIRCommand.Define;
internal override void Execute()
{
throw new NotImplementedException();
}
}
internal sealed class RegexAssignCommand<T>(
string name,
T value
) : RegexIR
{
public string Name { get; } = name;
public T Value { get; } = value;
internal override RegexIRCommand Command => RegexIRCommand.Assign;
internal override RegexIRCommand Command => RegexIRCommand.Try;
internal override void Execute()
{