before merge

This commit is contained in:
Nitload
2026-06-27 00:49:01 +08:00
parent 062ffacf88
commit 2a6fc7b633
17 changed files with 184 additions and 121 deletions
+1 -1
View File
@@ -49,7 +49,7 @@ else()
set(STGSHARP_ARCH_TAG ${SN_RESOLVED_ARCH_NAME}) set(STGSHARP_ARCH_TAG ${SN_RESOLVED_ARCH_NAME})
endif() endif()
set(STGSHARP_BUILD_OUTPUT_DIR ${STGSHARP_SOLUTION_ROOT}/build/${STGSHARP_OS_TAG}-${STGSHARP_ARCH_TAG}) set(STGSHARP_BUILD_OUTPUT_DIR ${STGSHARP_SOLUTION_ROOT}/cmake_build/${STGSHARP_OS_TAG}_${STGSHARP_ARCH_TAG})
set(STGSHARP_OBJECT_ROOT_DIR ${STGSHARP_SOLUTION_ROOT}/obj/${PROJECT_NAME}) set(STGSHARP_OBJECT_ROOT_DIR ${STGSHARP_SOLUTION_ROOT}/obj/${PROJECT_NAME})
set(STGSHARP_NATIVE_PROJECT_FILES set(STGSHARP_NATIVE_PROJECT_FILES
${STGSHARP_NATIVE_SOURCES} ${STGSHARP_NATIVE_SOURCES}
+5 -5
View File
@@ -125,11 +125,11 @@ SN_MK_PROC_DECL_STD(float, avx, _fma, fma)
register __m256 a1 = _mm256_load_ps((float *)&a_base->y[1]); register __m256 a1 = _mm256_load_ps((float *)&a_base->y[1]);
register __m256 a2 = _mm256_load_ps((float *)&a_base->y[2]); register __m256 a2 = _mm256_load_ps((float *)&a_base->y[2]);
register __m256 a3 = _mm256_load_ps((float *)&a_base->y[3]); register __m256 a3 = _mm256_load_ps((float *)&a_base->y[3]);
SN_MK_FMA_F32_AVX2_FMA_CYCLE(0); SN_MK_FMA_F32_AVX2_CYCLE(0);
SN_MK_FMA_F32_AVX2_FMA_CYCLE(1); SN_MK_FMA_F32_AVX2_CYCLE(1);
SN_MK_FMA_F32_AVX2_FMA_CYCLE(2); SN_MK_FMA_F32_AVX2_CYCLE(2);
SN_MK_FMA_F32_AVX2_FMA_CYCLE(3); SN_MK_FMA_F32_AVX2_CYCLE(3);
} }
_mm256_store_ps((float *)&(ans_cur->y[0]), c0); _mm256_store_ps((float *)&(ans_cur->y[0]), c0);
_mm256_store_ps((float *)&(ans_cur->y[1]), c1); _mm256_store_ps((float *)&(ans_cur->y[1]), c1);
@@ -2,36 +2,55 @@
#if SN_IS_ARCH(SN_ARCH_X86_64) #if SN_IS_ARCH(SN_ARCH_X86_64)
#define SN_MK_FMA_F32_512_CYCLE(i) \ #define SN_MK_FMA_F32_512_CYCLE(i) \
do { \ do { \
c0 = _mm512_fmadd_ps(a0, _mm512_permute_ps(b0, _FMA_SELECT(i)), c0); \ c0 = _mm512_fmadd_ps(c0, a0, _mm512_permute_ps(b0, _FMA_SELECT(i))); \
c1 = _mm512_fmadd_ps(a1, _mm512_permute_ps(b1, _FMA_SELECT(i)), c1); \ c1 = _mm512_fmadd_ps(c1, a1, _mm512_permute_ps(b1, _FMA_SELECT(i))); \
c2 = _mm512_fmadd_ps(a2, _mm512_permute_ps(b2, _FMA_SELECT(i)), c2); \ c2 = _mm512_fmadd_ps(c2, a2, _mm512_permute_ps(b2, _FMA_SELECT(i))); \
c3 = _mm512_fmadd_ps(a3, _mm512_permute_ps(b3, _FMA_SELECT(i)), c3); \ c3 = _mm512_fmadd_ps(c3, a3, _mm512_permute_ps(b3, _FMA_SELECT(i))); \
} while (0) } while (0)
#define SN_MK_FMA_F32_AVX2_FMA_CYCLE(i) \ #define SN_MK_FMA_F32_AVX2_CYCLE(i) \
do { \ do { \
c0 = _mm256_fmadd_ps(a0, _mm256_permute_ps(b0, _FMA_SELECT(i)), c0); \ c0 = _mm256_fmadd_ps(c0, a0, _mm256_permute_ps(b0, _FMA_SELECT(i))); \
c1 = _mm256_fmadd_ps(a1, _mm256_permute_ps(b1, _FMA_SELECT(i)), c1); \ c1 = _mm256_fmadd_ps(c1, a1, _mm256_permute_ps(b1, _FMA_SELECT(i))); \
c2 = _mm256_fmadd_ps(a2, _mm256_permute_ps(b2, _FMA_SELECT(i)), c2); \ c2 = _mm256_fmadd_ps(c2, a2, _mm256_permute_ps(b2, _FMA_SELECT(i))); \
c3 = _mm256_fmadd_ps(a3, _mm256_permute_ps(b3, _FMA_SELECT(i)), c3); \ c3 = _mm256_fmadd_ps(c3, a3, _mm256_permute_ps(b3, _FMA_SELECT(i))); \
} while (0) } while (0)
#define SN_MK_FMA_F32_AVX2_CYCLE(i) \ #define SN_MK_FMA_F64_AVX2_CYCLE(i) \
do { \ do { \
c0 = _mm256_add_ps(_mm256_mul_ps(a0, _mm256_permute_ps(b0, _FMA_SELECT(i))), c0); \ c0 = _mm512_fmadd_ps(c0, a0, _mm512_permutex_pd(b0, _FMA_SELECT(i))); \
c1 = _mm256_add_ps(_mm256_mul_ps(a1, _mm256_permute_ps(b1, _FMA_SELECT(i))), c1); \ c1 = _mm512_fmadd_ps(c1, a1, _mm512_permutex_pd(b1, _FMA_SELECT(i))); \
c2 = _mm256_add_ps(_mm256_mul_ps(a2, _mm256_permute_ps(b2, _FMA_SELECT(i))), c2); \ c2 = _mm512_fmadd_ps(c2, a2, _mm512_permutex_pd(b2, _FMA_SELECT(i))); \
c3 = _mm256_add_ps(_mm256_mul_ps(a3, _mm256_permute_ps(b3, _FMA_SELECT(i))), c3); \ c3 = _mm512_fmadd_ps(c3, a3, _mm512_permutex_pd(b3, _FMA_SELECT(i))); \
} while (0) } while (0)
#define SN_MK_FMA_F64_AVX2_CYCLE(i) \ #define SN_FMA_F32_512_PACK_COLUMN(col, target) \
do { \ do { \
c0 = _mm512_fmadd_ps(a0, _mm512_permutex_pd(b0, _FMA_SELECT(i)), c0); \ register __m256 low = _mm512_castps512_ps256(col); \
c1 = _mm512_fmadd_ps(a1, _mm512_permutex_pd(b1, _FMA_SELECT(i)), c1); \ register __m256 high = _mm512_extractf32x8_ps(col, 1); \
c2 = _mm512_fmadd_ps(a2, _mm512_permutex_pd(b2, _FMA_SELECT(i)), c2); \ register __m256 half = _mm256_add_ps(high, low); \
c3 = _mm512_fmadd_ps(a3, _mm512_permutex_pd(b3, _FMA_SELECT(i)), c3); \ register __m128 high128 = _mm256_extractf32x4_ps(half, 1); \
register __m128 low128 = _mm256_castps256_ps128(half); \
register __m128 half128 = _mm_add_ps(high128, low128); \
_mm_store_ps(target, half128); \
} while (0)
#define SN_FMA_F32_AVX2_PACK_COLUMN(col, target) \
do { \
register __m128 high128 = _mm256_extractf32x4_ps(col, 1); \
register __m128 low128 = _mm256_castps256_ps128(col); \
register __m128 half128 = _mm_add_ps(high128, low128); \
_mm_store_ps(target, half128); \
} while (0)
#define SN_FMA_F64_512_PACK_COLUMN(col, target) \
do { \
register __m128 high128 = _mm256_extractf32x4_ps(col, 1); \
register __m128 low128 = _mm256_castps256_ps128(col); \
register __m128 half128 = _mm_add_ps(high128, low128); \
_mm_store_ps(target, half128); \
} while (0) } while (0)
// double // double
@@ -28,16 +28,14 @@
using StgSharp.RegularAnalysis.Abstraction; using StgSharp.RegularAnalysis.Abstraction;
using System.Runtime.CompilerServices; using System.Runtime.CompilerServices;
namespace StgSharp.RegularAnalysis.TextRegex namespace StgSharp.RegularAnalysis.Text
{ {
internal class RegexAstNode : ISyntaxNode<RegexAstNode, RegexElementLabel> internal class RegexAstNode : ISyntaxNode<RegexAstNode, RegexElementLabel>
{ {
// private RegexAstNode _left, _right; // private RegexAstNode _left, _right;
public RegexAstNode( public RegexAstNode(Token<RegexElementLabel> source)
Token<RegexElementLabel> source
)
{ {
Source = source; Source = source;
} }
@@ -89,19 +87,14 @@ namespace StgSharp.RegularAnalysis.TextRegex
public Token<RegexElementLabel> Source { get; private protected set; } public Token<RegexElementLabel> Source { get; private protected set; }
public void AppendNode( public void AppendNode(RegexAstNode nextToken)
RegexAstNode nextToken
)
{ {
Next = nextToken; Next = nextToken;
nextToken.Previous = this; nextToken.Previous = this;
} }
[MethodImpl(MethodImplOptions.AggressiveInlining)] [MethodImpl(MethodImplOptions.AggressiveInlining)]
public static (bool Valid, int Value) ComparePrecedence( public static (bool Valid, int Value) ComparePrecedence(RegexElementLabel left, RegexElementLabel right)
RegexElementLabel left,
RegexElementLabel right
)
{ {
left &= RegexElementLabel.OPERATOR; left &= RegexElementLabel.OPERATOR;
right &= RegexElementLabel.OPERATOR; right &= RegexElementLabel.OPERATOR;
@@ -113,25 +106,19 @@ namespace StgSharp.RegularAnalysis.TextRegex
} }
[MethodImpl(MethodImplOptions.AggressiveInlining)] [MethodImpl(MethodImplOptions.AggressiveInlining)]
public static bool IsNullOrEmpty( public static bool IsNullOrEmpty(RegexAstNode node)
RegexAstNode node
)
{ {
return node is null || ReferenceEquals(node, Empty); return node is null || ReferenceEquals(node, Empty);
} }
/**/ /**/
public void PrependNode( public void PrependNode(RegexAstNode previousNode)
RegexAstNode previousNode
)
{ {
Previous = previousNode; Previous = previousNode;
previousNode.Next = this; previousNode.Next = this;
} }
public void RemoveChild( public void RemoveChild(RegexAstNode node)
RegexAstNode node
)
{ {
if (Left == node) if (Left == node)
{ {
@@ -149,9 +136,7 @@ namespace StgSharp.RegularAnalysis.TextRegex
return new EmptyRegexAstNode(); return new EmptyRegexAstNode();
} }
internal void RemoveAndAsChild( internal void RemoveAndAsChild(bool useLeft)
bool useLeft
)
{ {
if (useLeft) if (useLeft)
{ {
@@ -176,9 +161,7 @@ namespace StgSharp.RegularAnalysis.TextRegex
/// <param name="node"> /// <param name="node">
/// The node to replace the current node with. /// The node to replace the current node with.
/// </param> /// </param>
internal void ReplaceBy( internal void ReplaceBy(RegexAstNode node)
RegexAstNode node
)
{ {
Source = node.Source; Source = node.Source;
Left = node.Left; Left = node.Left;
@@ -31,7 +31,7 @@ using System.Linq;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
namespace StgSharp.RegularAnalysis.TextRegex namespace StgSharp.RegularAnalysis.Text
{ {
[Flags] [Flags]
public enum RegexElementLabel public enum RegexElementLabel
@@ -32,7 +32,7 @@ using System.Runtime.CompilerServices;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
namespace StgSharp.RegularAnalysis.TextRegex namespace StgSharp.RegularAnalysis.Text
{ {
internal enum RegexIRCommand internal enum RegexIRCommand
{ {
@@ -32,7 +32,7 @@ using System.Runtime.CompilerServices;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
namespace StgSharp.RegularAnalysis.TextRegex namespace StgSharp.RegularAnalysis.Text
{ {
internal class RegexIRGenerator internal class RegexIRGenerator
{ {
@@ -1,6 +1,6 @@
//----------------------------------------------------------------------- //-----------------------------------------------------------------------
// ----------------------------------------------------------------------- // -----------------------------------------------------------------------
// file="RegexInterpreter.IRGenerate" // file="RegexInterpreter.IREmit"
// Project: StgSharp // Project: StgSharp
// AuthorGroup: Nitload // AuthorGroup: Nitload
// Copyright (c) Nitload. All rights reserved. // Copyright (c) Nitload. All rights reserved.
@@ -38,14 +38,12 @@ using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
using System.Xml; using System.Xml;
namespace StgSharp.RegularAnalysis.TextRegex namespace StgSharp.RegularAnalysis.Text
{ {
public partial class RegexInterpreter public partial class RegexInterpreter
{ {
internal static List<RegexIR> GenerateIR( internal static List<RegexIR> GenerateIR(AbstractSyntaxTree<RegexAstNode, RegexElementLabel> tree)
AbstractSyntaxTree<RegexAstNode, RegexElementLabel> tree
)
{ {
return GenerateIRRecursion(tree.Root, 0).ToList(); return GenerateIRRecursion(tree.Root, 0).ToList();
} }
@@ -57,8 +55,7 @@ namespace StgSharp.RegularAnalysis.TextRegex
int min, int min,
int max, int max,
bool isGreedy, bool isGreedy,
RegexAstNode right RegexAstNode right)
)
{ {
bool isRightOperator = !RegexAstNode.IsNullOrEmpty(right) && bool isRightOperator = !RegexAstNode.IsNullOrEmpty(right) &&
(right.Source.Flag & RegexElementLabel.OPERATOR) != 0; (right.Source.Flag & RegexElementLabel.OPERATOR) != 0;
@@ -89,10 +86,7 @@ namespace StgSharp.RegularAnalysis.TextRegex
} }
} }
private static RegexIRGenerator GenerateIRRecursion( private static RegexIRGenerator GenerateIRRecursion(RegexAstNode node, int depth)
RegexAstNode node,
int depth
)
{ {
#pragma warning disable IDE0010 #pragma warning disable IDE0010
if (depth > 1024) if (depth > 1024)
@@ -37,7 +37,7 @@ using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
using System.Xml.Linq; using System.Xml.Linq;
namespace StgSharp.RegularAnalysis.TextRegex namespace StgSharp.RegularAnalysis.Text
{ {
public partial class RegexInterpreter public partial class RegexInterpreter
{ {
@@ -0,0 +1,37 @@
//-----------------------------------------------------------------------
// -----------------------------------------------------------------------
// file="RegexInterpreter.SourceEmit"
// Project: StgSharp
// AuthorGroup: Nitload
// Copyright (c) Nitload. All rights reserved.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.
//
// -----------------------------------------------------------------------
// -----------------------------------------------------------------------
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace StgSharp.RegularAnalysis.Text
{
public partial class RegexInterpreter { }
}
@@ -35,7 +35,7 @@ using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
namespace StgSharp.RegularAnalysis.TextRegex namespace StgSharp.RegularAnalysis.Text
{ {
public partial class RegexInterpreter public partial class RegexInterpreter
{ {
@@ -58,9 +58,7 @@ namespace StgSharp.RegularAnalysis.TextRegex
} }
} }
public static RegexInterpreter Analyze( public static RegexInterpreter Analyze(string regex)
string regex
)
{ {
RegexInterpreter interpreter = new(); RegexInterpreter interpreter = new();
interpreter._source = regex; interpreter._source = regex;
@@ -222,14 +220,11 @@ namespace StgSharp.RegularAnalysis.TextRegex
// TODO enum AST again , do ALT tail merge and simple ALT front merge // TODO enum AST again , do ALT tail merge and simple ALT front merge
} }
private void ProcessOperator( private void ProcessOperator(RegexAstNode op)
RegexAstNode op
)
{ {
if (op.EqualityTypeConvert == RegexElementLabel.CONCAT) if (op.EqualityTypeConvert == RegexElementLabel.CONCAT)
{ {
if (_stack.TryPopOperand(out RegexAstNode? _1) && if (_stack.TryPopOperand(out RegexAstNode? _1) && _stack.TryPopOperand(out RegexAstNode? _2))
_stack.TryPopOperand(out RegexAstNode? _2))
{ {
op.Left = _2; op.Left = _2;
op.Right = _1; op.Right = _1;
@@ -255,8 +250,7 @@ namespace StgSharp.RegularAnalysis.TextRegex
} }
} else if (op.EqualityTypeConvert == RegexElementLabel.ALT) } else if (op.EqualityTypeConvert == RegexElementLabel.ALT)
{ {
if (_stack.TryPopOperand(out RegexAstNode? _1) && if (_stack.TryPopOperand(out RegexAstNode? _1) && _stack.TryPopOperand(out RegexAstNode? _2))
_stack.TryPopOperand(out RegexAstNode? _2))
{ {
op.Left = _2; op.Left = _2;
op.Right = _1; op.Right = _1;
@@ -34,7 +34,7 @@ using System.Linq;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
namespace StgSharp.RegularAnalysis.TextRegex namespace StgSharp.RegularAnalysis.Text
{ {
internal class RegexTokenParser : TokenParser<RegexElementLabel, RegexElementLabel> internal class RegexTokenParser : TokenParser<RegexElementLabel, RegexElementLabel>
{ {
@@ -34,7 +34,7 @@ using System.Security.Permissions;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
namespace StgSharp.RegularAnalysis.TextRegex namespace StgSharp.RegularAnalysis.Text
{ {
internal class RegexTokenReader : ITokenReader<RegexElementLabel> internal class RegexTokenReader : ITokenReader<RegexElementLabel>
{ {
@@ -45,9 +45,7 @@ namespace StgSharp.RegularAnalysis.TextRegex
public RegexTokenReader() { } public RegexTokenReader() { }
public RegexTokenReader( public RegexTokenReader(string source)
string source
)
{ {
_source = source; _source = source;
} }
@@ -67,11 +65,9 @@ namespace StgSharp.RegularAnalysis.TextRegex
{ {
string value = _source[(pos + 1)..(pos + 3)]; string value = _source[(pos + 1)..(pos + 3)];
pos += 4; pos += 4;
if (uint.TryParse(value, out uint code) && if (uint.TryParse(value, out uint code) && Rune.TryCreate(code, out Rune result))
Rune.TryCreate(code, out Rune result))
{ {
return new Token<RegexElementLabel>(result.ToString(), 0, pos, return new Token<RegexElementLabel>(result.ToString(), 0, pos, RegexElementLabel.UNIT);
RegexElementLabel.UNIT);
} else } else
{ {
throw new InvalidCastException($"Failed to convert {value} to a valid ascii code point."); throw new InvalidCastException($"Failed to convert {value} to a valid ascii code point.");
@@ -80,11 +76,9 @@ namespace StgSharp.RegularAnalysis.TextRegex
{ {
string value = _source[(pos + 1)..(pos + 5)]; string value = _source[(pos + 1)..(pos + 5)];
pos += 6; pos += 6;
if (uint.TryParse(value, out uint code) && if (uint.TryParse(value, out uint code) && Rune.TryCreate(code, out Rune result))
Rune.TryCreate(code, out Rune result))
{ {
return new Token<RegexElementLabel>(result.ToString(), 0, pos, return new Token<RegexElementLabel>(result.ToString(), 0, pos, RegexElementLabel.UNIT);
RegexElementLabel.UNIT);
} else } else
{ {
throw new InvalidCastException($"Failed to convert {value} to a valid unicode code point."); throw new InvalidCastException($"Failed to convert {value} to a valid unicode code point.");
@@ -118,24 +112,21 @@ namespace StgSharp.RegularAnalysis.TextRegex
{ {
int length = (i - pos - 1); int length = (i - pos - 1);
position = i + 1; position = i + 1;
return new Token<RegexElementLabel>(_source[(pos)..(i + 1)], 0, return new Token<RegexElementLabel>(_source[(pos)..(i + 1)], 0, position,
position,
RegexElementLabel.UNIT_SET); RegexElementLabel.UNIT_SET);
} }
} }
throw new InvalidOperationException("Unclosed character set"); throw new InvalidOperationException("Unclosed character set");
case '|': case '|':
position = pos + 1; position = pos + 1;
return new Token<RegexElementLabel>(_source[(pos)..(pos + 1)], 0, pos, return new Token<RegexElementLabel>(_source[(pos)..(pos + 1)], 0, pos, RegexElementLabel.ALT);
RegexElementLabel.ALT);
case '(': case '(':
// very comlex here // very comlex here
return ReadGroupBeginToken(); return ReadGroupBeginToken();
case ')': case ')':
position = pos + 1; position = pos + 1;
return new Token<RegexElementLabel>(_source[(pos)..(pos + 1)], 0, pos, return new Token<RegexElementLabel>(_source[(pos)..(pos + 1)], 0, pos, RegexElementLabel.GROUP_END);
RegexElementLabel.GROUP_END);
case '{': case '{':
for (int i = pos + 1; i < _source.Length; i++) for (int i = pos + 1; i < _source.Length; i++)
{ {
@@ -150,26 +141,20 @@ namespace StgSharp.RegularAnalysis.TextRegex
case '*' or '+': case '*' or '+':
int count = pos + 1 >= _source.Length ? 1 : (_source[pos + 1] == '?' ? 2 : 1); int count = pos + 1 >= _source.Length ? 1 : (_source[pos + 1] == '?' ? 2 : 1);
position = pos + count; position = pos + count;
return new Token<RegexElementLabel>(_source[(pos)..(pos + count)], 0, pos, return new Token<RegexElementLabel>(_source[(pos)..(pos + count)], 0, pos, RegexElementLabel.COUNT);
RegexElementLabel.COUNT);
case '?': case '?':
position = pos + 1; position = pos + 1;
return new Token<RegexElementLabel>(_source[(pos)..(pos + 1)], 0, pos, return new Token<RegexElementLabel>(_source[(pos)..(pos + 1)], 0, pos, RegexElementLabel.COUNT);
RegexElementLabel.COUNT);
case '.': case '.':
position = pos + 1; position = pos + 1;
return new Token<RegexElementLabel>(_source[(pos)..(pos + 1)], 0, pos, return new Token<RegexElementLabel>(_source[(pos)..(pos + 1)], 0, pos, RegexElementLabel.UNIT);
RegexElementLabel.UNIT);
default: default:
position = pos + 1; position = pos + 1;
return new Token<RegexElementLabel>(_source[(pos)..(pos + 1)], 0, pos, return new Token<RegexElementLabel>(_source[(pos)..(pos + 1)], 0, pos, RegexElementLabel.UNIT);
RegexElementLabel.UNIT);
} }
} }
public bool TryReadToken( public bool TryReadToken(out Token<RegexElementLabel> t)
out Token<RegexElementLabel> t
)
{ {
if (IsEmpty) if (IsEmpty)
{ {
@@ -32,7 +32,7 @@ using System.Linq;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
namespace StgSharp.RegularAnalysis.TextRegex namespace StgSharp.RegularAnalysis.Text
{ {
internal static class RegexTokenUtil internal static class RegexTokenUtil
{ {
@@ -0,0 +1,45 @@
//-----------------------------------------------------------------------
// -----------------------------------------------------------------------
// file="TextRegex"
// Project: StgSharp
// AuthorGroup: Nitload
// Copyright (c) Nitload. All rights reserved.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.
//
// -----------------------------------------------------------------------
// -----------------------------------------------------------------------
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace StgSharp.RegularAnalysis.Text
{
public abstract class TextRegex
{
public ref struct Match
{
private ReadOnlySpan<char> _sequence;
}
}
}
+12 -5
View File
@@ -32,17 +32,18 @@ using StgSharp.Mathematics;
using StgSharp.Mathematics.Numeric; using StgSharp.Mathematics.Numeric;
using StgSharp.Timing; using StgSharp.Timing;
using StgSharp.Timing; using StgSharp.Timing;
using System;
namespace StgSharp namespace StgSharp
{ {
internal static partial class Program internal static partial class Program
{ {
private static bool _hasError;
private static string testExpPath = @"D:\Programmer\stepcode\data\ap203\ap203.exp"; private static string testExpPath = @"D:\Programmer\stepcode\data\ap203\ap203.exp";
internal static unsafe void Main( internal static unsafe void Main(string[] args)
string[] args
)
{ {
try try
{ {
@@ -63,12 +64,13 @@ namespace StgSharp
// TestMatrix(); // TestMatrix();
/* /**/
} }
catch (Exception ex) catch (Exception ex)
{ {
Console.WriteLine(ex); Console.WriteLine(ex);
Console.ReadLine(); _ = Console.ReadLine();
_hasError = true;
/* /*
World.WriteLog($"{ex}", LogType.Error); World.WriteLog($"{ex}", LogType.Error);
Dialogue.PostError(ex); Dialogue.PostError(ex);
@@ -79,6 +81,11 @@ namespace StgSharp
} }
finally finally
{ {
if (!_hasError)
{
Console.WriteLine("Program has exited with no error, press any key to exit.");
_ = Console.ReadKey();
}
World.Terminate(0); World.Terminate(0);
} }
/**/ /**/
+2 -3
View File
@@ -26,7 +26,7 @@
// ----------------------------------------------------------------------- // -----------------------------------------------------------------------
// ----------------------------------------------------------------------- // -----------------------------------------------------------------------
using StgSharp.RegularAnalysis.Abstraction; using StgSharp.RegularAnalysis.Abstraction;
using StgSharp.RegularAnalysis.TextRegex; using StgSharp.RegularAnalysis.Text;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
@@ -44,8 +44,7 @@ namespace StgSharp
@"abc[0-9]x|abc[0-9]y|abd[0-9]x|abd[0-9]y|xyz", @"abc[0-9]x|abc[0-9]y|abd[0-9]x|abd[0-9]y|xyz",
@"get_name|get_value|get_type|set_name|set_value|set_type", @"get_name|get_value|get_type|set_name|set_value|set_type",
@"helix|hello|help|hero|hers|her", @"helix|hello|help|hero|hers|her",
@"a*.[abc]*(abcd|a(bc)c)+(?<name>abc)" @"a*.[abc]*(abcd|a(bc)c)+(?<name>abc)"];
];
public static void Run() public static void Run()
{ {