HLSF full functionally available. Working on Matrix.

Signed-off-by: Youmu Liu <105042599+Nitload-NSI@users.noreply.github.com>
This commit is contained in:
Youmu Liu
2025-08-25 22:13:45 +08:00
parent fe097fd94c
commit e5e4b1dd36
1479 changed files with 2083 additions and 619964 deletions
@@ -44,14 +44,16 @@ using System.Xml.Schema;
using ExpKeyword = StgSharp.Script.Express.ExpressCompile.Keyword;
namespace StgSharp.Modeling.Step
namespace StgSharp.Model.Step
{
internal partial class StepExpSyntaxAnalyzer
{
private static Regex _entityTypeCheckPattern = GetEntityTypeCheckPattern();
[GeneratedRegex( @"^[A-Z_]+$", RegexOptions.Singleline )]
private StepDependencyDetector _dependencyDetector = new StepDependencyDetector();
[GeneratedRegex( @"^[A-Z0-9_]+$", RegexOptions.Singleline )]
private static partial Regex GetEntityTypeCheckPattern();
private bool IsSeparatorMatch( Token leftSeparator, Token rightSeparator )
@@ -147,10 +149,16 @@ namespace StgSharp.Modeling.Step
goto case 1;
case 1:
_cache.PopOperand( out _, out ExpSyntaxNode? statement );
_cache.StatementsInDepth.Push( statement );
if( t.Value == ";" ) {
StepEntityInitStatements.Enqueue( statement );
if( t.Value == ";" )
{
StepEntityDefineSequence sequence = new StepEntityDefineSequence(
statement, _dependencyDetector.ExportAllDependencies() );
StepEntityInitStatements.Enqueue( sequence );
} else
{
_cache.StatementsInDepth.Push( statement );
}
return true;
default:
ExpInvalidSyntaxException.ThrowNoOperator( t );
@@ -213,6 +221,12 @@ namespace StgSharp.Modeling.Step
{
switch( t.Value )
{
case "$":
_cache.PushOperand( StepEntityInstanceNode.RegisterNull( t ) );
return true;
case "*":
_cache.PushOperand( StepEntityInstanceNode.RegisterRuntimeInference( t ) );
return true;
case ExpKeyword.E:
_cache.PushOperand( new ExpRealNumberNode( t, MathF.E, true ) );
return true;
@@ -246,8 +260,15 @@ namespace StgSharp.Modeling.Step
private bool TryParseFunction( Token t )
{
if( _entityTypeCheckPattern.IsMatch( t.Value ) ) {
if( _entityTypeCheckPattern.IsMatch( t.Value ) )
{
if( _cache.PeekOperator().Flag == TokenFlag.Member )
{
Token op = _cache.PopOperator();
ConvertAndPushOneOperator( op );
}
_cache.PushOperator( t );
return true;
}
return false;
}
@@ -256,7 +277,11 @@ namespace StgSharp.Modeling.Step
{
if( t.Value[ 0 ] == '#' )
{
_cache.PushOperand( StepEntityInstanceNode.Register( t ) );
StepEntityInstanceNode node = StepEntityInstanceNode.Register( t );
if( t.Column != 0 ) {
_dependencyDetector.AddDependency( node );
}
_cache.PushOperand( node );
return true;
}
return false;
@@ -34,7 +34,7 @@ using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace StgSharp.Modeling.Step
namespace StgSharp.Model.Step
{
internal partial class StepExpSyntaxAnalyzer
{
@@ -28,7 +28,6 @@
//
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
using StgSharp.Model.Step.SyntaxNode;
using StgSharp.Script;
using StgSharp.Script.Express;
@@ -40,7 +39,7 @@ using System.Threading.Tasks;
using ExpKeyword = StgSharp.Script.Express.ExpressCompile.Keyword;
namespace StgSharp.Modeling.Step
namespace StgSharp.Model.Step
{
internal partial class StepExpSyntaxAnalyzer
{
@@ -92,7 +91,7 @@ namespace StgSharp.Modeling.Step
_cache.PopOperand( out _, out ExpSyntaxNode? p );
StepEntityInitCaller caller = StepEntityInitCaller.CreateCaller( op.Value );
node = ExpFunctionCallingNode.CallFunction( op, caller, p );
_cache.PushOperand( node );
_cache.StatementsInDepth.Push( node );
return node;
default:
throw new NotImplementedException();
@@ -101,43 +100,27 @@ namespace StgSharp.Modeling.Step
private bool TryGenerateBinaryNode( Token t, out ExpSyntaxNode node )
{
/*
ExpSyntaxNode right = GetNextOperandCache();
ExpSyntaxNode left = GetNextOperandCache();
/**/
switch( t.Value )
{
case ExpKeyword.Add:
node = ExpBinaryOperatorNode.Add( t, left, right );
return true;
case ExpKeyword.Sub:
node = ExpBinaryOperatorNode.Sub( t, left, right );
return true;
case ExpKeyword.Mul:
node = ExpBinaryOperatorNode.Mul( t, left, right );
return true;
case ExpKeyword.Div:
node = ExpBinaryOperatorNode.Div( t, left, right );
return true;
case ExpKeyword.Equal:
node = ExpBinaryOperatorNode.EqualTo( t, left, right );
return true;
case ExpKeyword.NotEqual:
node = ExpBinaryOperatorNode.NotEqualTo( t, left, right );
return true;
case ExpKeyword.GreaterThan:
node = ExpBinaryOperatorNode.GreaterThan( t, left, right );
return true;
case ExpKeyword.LessThan:
node = ExpBinaryOperatorNode.LessThan( t, left, right );
return true;
case ExpKeyword.Assignment:
case "=":
ExpSyntaxNode right = GetNextOperandCache();
ExpSyntaxNode left;
if( right is ExpTupleNode tuple )
{
right = StepComplexEntityNode.FromTuple( tuple );
left = GetNextOperandCache();
} else
{
left = right;
right = _cache.StatementsInDepth.Pop();
}
node = ExpBinaryOperatorNode.Assign( t, left, right );
return true;
case ExpKeyword.InstanceEqual:
node = ExpBinaryOperatorNode.CompareInstanceEqual( t, left, right );
return true;
case ExpKeyword.InstanceNotEqual:
node = ExpBinaryOperatorNode.CompareInstanceNotEqual( t, left, right );
return true;
default:
node = ExpSyntaxNode.Empty;
return false;
@@ -40,7 +40,7 @@ using System.Threading.Tasks;
using ExpKeyword = StgSharp.Script.Express.ExpressCompile.Keyword;
namespace StgSharp.Modeling.Step
namespace StgSharp.Model.Step
{
internal partial class StepExpSyntaxAnalyzer
{
@@ -57,15 +57,19 @@ namespace StgSharp.Modeling.Step
_cache.StatementsInDepth.Push( statement );
} else
{
ExpInvalidSyntaxException.ThrowNoOperator( rightSeparator );
_cache.StatementsInDepth.Push( ExpSyntaxNode.Empty );
}
} else
{
while( _cache.TryPopOperator( out op ) ) {
ConvertAndPushOneOperator( op );
while( _cache.TryPopOperator( out op ) )
{
ExpSyntaxNode node = ConvertAndPushOneOperator( op );
}
if( _cache.OperandAheadOfDepth == 1 )
{
_cache.PopOperand( out _, out root );
_cache.StatementsInDepth.Push( root );
}
_cache.PopOperand( out _, out root );
_cache.StatementsInDepth.Push( root );
}
root = _cache.PackAllStatements();
@@ -73,6 +77,7 @@ namespace StgSharp.Modeling.Step
if( IsSeparatorMatch( _cache.PeekOperator(), rightSeparator ) )
{
_cache.PopOperator();
root = ExpTupleNode.Pack( root );
_cache.PushOperand( root );
} else
{
@@ -45,7 +45,7 @@ using System.Threading.Tasks;
using ExpKeyword = StgSharp.Script.Express.ExpressCompile.Keyword;
namespace StgSharp.Modeling.Step
namespace StgSharp.Model.Step
{
internal partial class StepExpSyntaxAnalyzer : ISyntaxAnalyzer
{
@@ -62,24 +62,10 @@ namespace StgSharp.Modeling.Step
public StepExpSyntaxAnalyzer()
{
_cache = new CompileStack<ExpSyntaxNode, IExpElementSource>();
_context = new ExpressStepUtil();
}
public StepExpSyntaxAnalyzer( ExpSchema context, IExpElementSource local )
{
_cache = new CompileStack<ExpSyntaxNode, IExpElementSource>();
ArgumentNullException.ThrowIfNull( context );
if( context is not ExpSchema_Builtin )
{
_context = context;
} else
{
throw new InvalidCastException( "Not a valid Schema type" );
}
_local = local;
}
public ConcurrentQueue<ExpSyntaxNode> StepEntityInitStatements { get; } = new ConcurrentQueue<ExpSyntaxNode>(
);
public ConcurrentQueue<StepEntityDefineSequence> StepEntityInitStatements { get; } = new();
/// <summary>
/// Append a token to top of cache. This method will automatically convert token to node
@@ -114,6 +100,9 @@ namespace StgSharp.Modeling.Step
case TokenFlag.Member:
TryAppendMember( expToken );
break;
case TokenFlag.Enum:
TryAppendEnum( expToken );
break;
default:
break;
}
@@ -38,44 +38,44 @@ using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace StgSharp.Modeling.Step
namespace StgSharp.Model.Step
{
public class StepDataSectionTransmitter : IScriptSourceProvider
{
private const string EndDataText = "ENDSEC;";
private bool _isEmpty;
//private bool _isEmpty;
private ConcurrentQueue<string> _cache = new ConcurrentQueue<string>();
private int _line = 0;
public bool IsEmpty => _isEmpty;
public StepDataSectionTransmitter() { }
public StepDataSectionTransmitter( int begins )
{
Begin = begins;
_line = Begin;
}
public bool IsEmpty => _cache.IsEmpty && !IsWriting;
public bool IsWriting { get; private set; } = true;
public int Begin { get; internal set; }
public int Location => _line;
public void EndWriting()
{
_cache.Enqueue( EndDataText );
IsWriting = false;
}
public string ReadLine()
{
_cache.TryDequeue( out string? line );
while( !IsEmpty )
if( _cache.TryDequeue( out string? line ) )
{
if( _cache.TryDequeue( out line ) )
{
if( line == EndDataText )
{
_isEmpty = true;
return string.Empty;
}
_line++;
return line;
}
_line++;
return line;
}
return string.Empty;
}
@@ -89,10 +89,17 @@ namespace StgSharp.Modeling.Step
public void WriteLine( string line )
{
if( line == EndDataText ) {
if( line == "DATA;" ) {
return;
}
if( line == EndDataText )
{
EndWriting();
return;
}
if( IsWriting ) {
_cache.Enqueue( line );
}
_cache.Enqueue( line );
}
IScriptSourceProvider IScriptSourceProvider.Slice( int location, int count )
@@ -28,7 +28,7 @@
//
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
using StgSharp.Modeling.Step;
using StgSharp.Model.Step;
using StgSharp.Script;
using StgSharp.Script.Express;
@@ -41,14 +41,14 @@ using System.Text.RegularExpressions;
using System.Threading;
using System.Threading.Tasks;
namespace StgSharp.Modeling.Step
namespace StgSharp.Model.Step
{
public class StepDataTokenReader : IScriptTokenReader
public partial class StepDataTokenReader : IScriptTokenReader
{
private ExpTokenReader _reader;
private HashSet<string> token1Hash = [
private HashSet<string> tokenHash = [
"T","F","UNSPECIFIED"
];
private Queue<Token> _cache = new Queue<Token>();
@@ -63,7 +63,13 @@ namespace StgSharp.Modeling.Step
public bool IsEmpty
{
get => _reader.IsEmpty && _transmitter.IsWriting;
get
{
if( _reader.IsEmpty ) {
return !_transmitter.IsWriting;
}
return false;
}
}
public Token ReadToken()
@@ -76,40 +82,93 @@ namespace StgSharp.Modeling.Step
return _reader.TryReadToken( out t );
}
private class TokenPreReader : ExpTokenReaderPreProcessor
private partial class TokenPreReader : ExpTokenReaderPreProcessor
{
private static Regex NextEnumPattern = GetNextEnumPattern();
private static Regex
_nextHashtagSymbolPattern = GetEntityTagSymbolPattern(),
_nextEnumPattern = GetNextEnumPattern(),
_stringPattern = GetStringPattern();
public override bool Process( string codeLine, int line, ref int current, out Token t )
{
ReadOnlySpan<char> chars = codeLine.AsSpan( current );
char c = chars[ 0 ];
if( c != '.' )
Match match;
switch( c )
{
t = Token.Empty;
return false;
}
Match match = NextEnumPattern.Match( codeLine, current );
if( match.Success )
{
int begin = match.Groups[ "begin" ].Index;
int end = match.Groups[ "end" ].Length;
int rest = match.Groups[ "rets" ].Length;
current = rest;
t = new Token( match.Groups[ "begin" ].Value, line, begin, TokenFlag.Enum );
return true;
} else
{
t = Token.Empty;
return false;
case '#':
match = _nextHashtagSymbolPattern.Match( codeLine, current );
if( match.Success )
{
int begin = match.Groups[ "token" ].Index;
int end = match.Groups[ "end" ].Index;
int rest = match.Groups[ "rest" ].Index;
current = rest;
t = new(
ExpressCompile.PoolString( chars[ 0..( end - begin ) ] ), line,
begin, TokenFlag.Member );
return true;
}
break;
case '.':
match = _nextEnumPattern.Match( codeLine, current );
if( match.Success )
{
int begin = match.Groups[ "token" ].Index;
int end = match.Groups[ "end" ].Index;
int rest = match.Groups[ "rest" ].Index;
current = rest;
t = new Token(
match.Groups[ "token" ].Value, line, begin, TokenFlag.Enum );
return true;
}
break;
case '$':
t = new Token( "$", line, current, TokenFlag.Member );
current++;
return true;
case '*':
t = new Token( "*", line, current, TokenFlag.Member );
current++;
return true;
case '\'':
match = _stringPattern.Match( codeLine, current );
if( match.Success )
{
int begin = match.Groups[ "token" ].Index;
int end = match.Groups[ "end" ].Index;
int rest = match.Groups[ "rest" ].Index;
current = rest;
string value = chars.Slice( 1, ( end - begin - 1 ) ).ToString();
if( string.IsNullOrWhiteSpace( value ) ) {
value = string.Empty;
}
t = new Token( value, line, begin, TokenFlag.String );
return true;
}
break;
default:
break;
}
t = Token.Empty;
return false;
}
[GeneratedRegex(
@"(?<begin>\.[A-Za-z_]+\.)(?<end>\s*)(?<rest>\S*)",
@"(?<token>#[0-9A-Za-z]+)(?<end>\s*?)(?<rest>\S|$)",
RegexOptions.Singleline )]
private static extern Regex GetNextEnumPattern();
private static partial Regex GetEntityTagSymbolPattern();
[GeneratedRegex(
@"(?<token>\.[A-Za-z_]+\.)(?<end>\s*)(?<rest>\S*)",
RegexOptions.Singleline )]
private static partial Regex GetNextEnumPattern();
[GeneratedRegex(
@"(?<token>')(?>\\\\|''|(?!')[^'])*(?<end>')\s*?(?<rest>\S|$)",
RegexOptions.Singleline )]
private static partial Regex GetStringPattern();
}