Daily update on 20250618-051714 by Nitload Youmu. Additional Message : Brief support to collection operation in EXPRESS. A collection type added in core lib and compilestack.

Signed-off-by: Nitload <YoumuLiu_NSI@whv0t.onmicrosoft.com>
This commit is contained in:
Nitload
2025-06-18 05:17:14 +08:00
parent 74c01effe4
commit c624a8ca38
300 changed files with 12227 additions and 4303 deletions
+3 -8
View File
@@ -51,8 +51,7 @@ namespace StgSharp.Script
ReadOnlySpan<char> subSpan = sourceSpan.Slice( startIndex );
int start = 0;
while( start < subSpan.Length && char.IsWhiteSpace(
subSpan[ start ] ) ) {
while( start < subSpan.Length && char.IsWhiteSpace( subSpan[ start ] ) ) {
start++;
}
int end = subSpan.Length - 1;
@@ -67,10 +66,7 @@ namespace StgSharp.Script
return new string( subSpan.Slice( start, finalLength ) );
}
public static string SliceAndTrim(
this string line,
int startIndex,
int length )
public static string SliceAndTrim( this string line, int startIndex, int length )
{
if( line == null ) {
throw new ArgumentNullException( nameof( line ) );
@@ -88,8 +84,7 @@ namespace StgSharp.Script
ReadOnlySpan<char> subSpan = sourceSpan.Slice( startIndex, length );
int start = 0;
while( start < subSpan.Length && char.IsWhiteSpace(
subSpan[ start ] ) ) {
while( start < subSpan.Length && char.IsWhiteSpace( subSpan[ start ] ) ) {
start++;
}
int end = subSpan.Length - 1;
+50 -8
View File
@@ -28,6 +28,8 @@
//
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
using StgSharp.Collections;
using System;
using System.Collections.Generic;
using System.Data;
@@ -49,9 +51,10 @@ namespace StgSharp.Script
private Token[] _tokenArray = new Token[4];
private int _nodeCount,_tokenCount, _operatorCount;
private Stack<CompileDepthMark> _depthStack = new Stack<CompileDepthMark>();
private Stack<bool> _isNode = new Stack<bool>();
private RandomAccessibleStack<OperandIndex> _isNode = new RandomAccessibleStack<OperandIndex>(
8 );
private Stack<CompileDepthMark> _depthStack = new Stack<CompileDepthMark>();
private Stack<Stack<TNode>> _statementCache = new Stack<Stack<TNode>>();
private TNode _lastNode;
@@ -97,6 +100,43 @@ namespace StgSharp.Script
Stack<TNode> statementsInDepth = _statementCache.Pop();
}
public bool GetOperandAt( Index i, out TNode operandNode, out Token operandToken )
{
OperandIndex index = _isNode[ i ];
if( index.IsNode )
{
operandNode = _nodeArray[ index.Index ];
operandToken = Token.Empty;
return true;
} else
{
operandToken = _tokenArray[ index.Index ];
operandNode = default!;
return false;
}
}
public bool GetOperandAt(
CompileDepthMark depth,
Index i,
out Token operandToken,
out TNode operandNode )
{
OperandIndex index = _isNode[ i ];
_depthStack.Contains( depth );
if( index.IsNode )
{
operandNode = _nodeArray[ index.Index ];
operandToken = Token.Empty;
return true;
} else
{
operandToken = _tokenArray[ index.Index ];
operandNode = default!;
return false;
}
}
public CompileDepthMark IncreaseDepth( int usage )
{
CompileDepthMark mark =
@@ -131,7 +171,7 @@ namespace StgSharp.Script
n = TNode.Empty;
return false;
}
if( _isNode.Pop() )
if( _isNode.Pop().IsNode )
{
t = Token.Empty;
n = _nodeArray[ _nodeCount - 1 ];
@@ -160,7 +200,7 @@ namespace StgSharp.Script
n = TNode.Empty;
return false;
}
if( _isNode.Pop() )
if( _isNode.Pop().IsNode )
{
t = Token.Empty;
n = _nodeArray[ --_nodeCount ];
@@ -189,8 +229,8 @@ namespace StgSharp.Script
Array.Resize( ref _nodeArray, _nodeArray.Length * 2 );
}
_nodeArray[ _nodeCount ] = node;
_isNode.Push( new( true, _nodeCount ) );
_nodeCount++;
_isNode.Push( true );
IsLastAddedOperator = false;
}
@@ -200,8 +240,8 @@ namespace StgSharp.Script
Array.Resize( ref _tokenArray, _tokenArray.Length * 2 );
}
_tokenArray[ _tokenCount ] = token;
_isNode.Push( new( false, _tokenCount ) );
_tokenCount++;
_isNode.Push( false );
IsLastAddedOperator = false;
}
@@ -229,7 +269,7 @@ namespace StgSharp.Script
isNode = false;
return false;
}
if( _isNode.Pop() )
if( _isNode.Pop().IsNode )
{
t = Token.Empty;
n = _nodeArray[ _nodeCount - 1 ];
@@ -264,7 +304,7 @@ namespace StgSharp.Script
isNode = false;
return false;
}
if( _isNode.Pop() )
if( _isNode.Pop().IsNode )
{
t = Token.Empty;
n = _nodeArray[ --_nodeCount ];
@@ -290,5 +330,7 @@ namespace StgSharp.Script
return false;
}
private record struct OperandIndex( bool IsNode, int Index );
}
}
@@ -37,15 +37,9 @@ namespace StgSharp.Script
public interface IScriptSourceProvider
{
bool IsEmpty
{
get;
}
bool IsEmpty { get; }
int Location
{
get;
}
int Location { get; }
void EndWriting();
@@ -54,10 +48,14 @@ namespace StgSharp.Script
string ReadLine( out int position );
/// <summary>
/// Return part of current provider.
/// Return part of current provider.
/// </summary>
/// <param name="count"> Count of lines to be sliced </param>
/// <returns></returns>
/// <param name="count">
/// Count of lines to be sliced
/// </param>
/// <returns>
///
/// </returns>
public IScriptSourceProvider Slice( int location, int count );
}
+1 -2
View File
@@ -36,8 +36,7 @@ using System.Threading.Tasks;
namespace StgSharp.Script
{
public interface ITypeSource<in TConvert>
where TConvert: ITypeSource<TConvert>
public interface ITypeSource<in TConvert> where TConvert: ITypeSource<TConvert>
{
bool IsConvertable( TConvert targetType );
@@ -38,9 +38,9 @@ using System.Text.RegularExpressions;
namespace StgSharp.Script
{
/// <summary>
/// Transmit a continuous part of script code to interpreter or compiler. This transmitter is
/// designed for single-thread-write and single-thread read. Any multi thread operation will
/// cause undefined behaviour.
/// Transmit a continuous part of script code to interpreter or compiler. This transmitter is
/// designed for single-thread-write and single-thread read. Any multi thread operation will
/// cause undefined behaviour.
/// </summary>
public class ScriptSourceTransmitter : IScriptSourceProvider
{
@@ -73,10 +73,7 @@ namespace StgSharp.Script
_index = 0;
}
public ScriptSourceTransmitter(
string endMark,
int start,
int capacity )
public ScriptSourceTransmitter( string endMark, int start, int capacity )
{
_cache = new List<string>( capacity );
_completeMark = endMark;
@@ -85,8 +82,7 @@ namespace StgSharp.Script
}
public bool IsEmpty => _isWriting ?
( _cache.Count == 0 ) : ( _buffer.Length == 0 ) || ( _index >=
_buffer.Length );
( _cache.Count == 0 ) : ( _buffer.Length == 0 ) || ( _index >= _buffer.Length );
public bool IsFrozen => !_isWriting;
@@ -107,8 +103,7 @@ namespace StgSharp.Script
public string ReadLine()
{
if( _isWriting ) {
throw new InvalidOperationException(
"Cannot read before all writing operation." );
throw new InvalidOperationException( "Cannot read before all writing operation." );
}
if( _index >= _buffer.Length ) {
return string.Empty;
@@ -121,10 +116,10 @@ namespace StgSharp.Script
public string ReadLine( out int position )
{
if( _isWriting ) {
throw new InvalidOperationException(
"Cannot read before all writing operation." );
throw new InvalidOperationException( "Cannot read before all writing operation." );
}
if( _index >= _buffer.Length ) {
if( _index >= _buffer.Length )
{
position = -1;
return string.Empty;
}
@@ -148,7 +143,8 @@ namespace StgSharp.Script
if( !_isWriting ) {
return;
}
if( string.Equals( _completeMark, line ) ) {
if( string.Equals( _completeMark, line ) )
{
EndWriting();
return;
}