From 6f494f25eff44526a1e002d5ebeab8cf7b86a51d Mon Sep 17 00:00:00 2001 From: Nitload Date: Sun, 9 Mar 2025 06:31:12 +0800 Subject: [PATCH] Daily update on 20250309-063111 by Nitload Youmu. Additional Message : Building AST generator, Name property removed from AST Node, Line And Colum property added as replacement. Signed-off-by: Nitload --- .../net8.0/StgSharp.Common.AssemblyInfo.cs | 2 +- .../net8.0/StgSharp.Common.sourcelink.json | 2 +- StgSharp.Script/Common/CompileStack.cs | 72 ++++++++++++++++--- StgSharp.Script/Common/IASTNode.cs | 9 ++- .../Express/ExpAstNode/_ExpNode.cs | 2 - .../ExpNodeGenerator.FunctionCalling.cs | 45 +++++++++--- StgSharp.Script/Express/ExpNodeGenerator.cs | 1 + .../net8.0/StgSharp.Script.AssemblyInfo.cs | 2 +- .../net8.0/StgSharp.Script.sourcelink.json | 2 +- 9 files changed, 110 insertions(+), 27 deletions(-) diff --git a/StgSharp.Common/obj/x64/Debug/net8.0/StgSharp.Common.AssemblyInfo.cs b/StgSharp.Common/obj/x64/Debug/net8.0/StgSharp.Common.AssemblyInfo.cs index 34f27741..02a664ed 100644 --- a/StgSharp.Common/obj/x64/Debug/net8.0/StgSharp.Common.AssemblyInfo.cs +++ b/StgSharp.Common/obj/x64/Debug/net8.0/StgSharp.Common.AssemblyInfo.cs @@ -14,7 +14,7 @@ using System.Reflection; [assembly: System.Reflection.AssemblyCompanyAttribute("StgSharp.Common")] [assembly: System.Reflection.AssemblyConfigurationAttribute("Debug")] [assembly: System.Reflection.AssemblyFileVersionAttribute("1.0.0.0")] -[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+825e68853cd1738287eecc8a4390ee9c78550308")] +[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+df321a3bae3d97d043473f4595cc8d229d0f2722")] [assembly: System.Reflection.AssemblyProductAttribute("StgSharp.Common")] [assembly: System.Reflection.AssemblyTitleAttribute("StgSharp.Common")] [assembly: System.Reflection.AssemblyVersionAttribute("1.0.0.0")] diff --git a/StgSharp.Common/obj/x64/Debug/net8.0/StgSharp.Common.sourcelink.json b/StgSharp.Common/obj/x64/Debug/net8.0/StgSharp.Common.sourcelink.json index 48222c59..47034813 100644 --- a/StgSharp.Common/obj/x64/Debug/net8.0/StgSharp.Common.sourcelink.json +++ b/StgSharp.Common/obj/x64/Debug/net8.0/StgSharp.Common.sourcelink.json @@ -1 +1 @@ -{"documents":{"D:\\NitloadIndustry\\研究项目\\1-Flagship\\TH2020\\ProjectFile\\内核源代码\\*":"https://raw.githubusercontent.com/Nitload-NSI/CCD_Github/825e68853cd1738287eecc8a4390ee9c78550308/*"}} \ No newline at end of file +{"documents":{"D:\\NitloadIndustry\\研究项目\\1-Flagship\\TH2020\\ProjectFile\\内核源代码\\*":"https://raw.githubusercontent.com/Nitload-NSI/CCD_Github/df321a3bae3d97d043473f4595cc8d229d0f2722/*"}} \ No newline at end of file diff --git a/StgSharp.Script/Common/CompileStack.cs b/StgSharp.Script/Common/CompileStack.cs index a45cf760..dae8b978 100644 --- a/StgSharp.Script/Common/CompileStack.cs +++ b/StgSharp.Script/Common/CompileStack.cs @@ -74,14 +74,16 @@ namespace StgSharp.Script CompileDepthMark mark = _depthStack.Pop(); } - public void IncreaseDepth() + public CompileDepthMark IncreaseDepth() { - _depthStack.Push( + CompileDepthMark mark = new CompileDepthMark - { - OperandBegin = OperandCount, - OperatorBegin = OperatorCount - } ); + { + OperandBegin = OperandCount, + OperatorBegin = OperatorCount + }; + _depthStack.Push( mark ); + return mark; } public bool PeekOperand( out Token t, out TNode n ) @@ -112,6 +114,11 @@ namespace StgSharp.Script public bool PopOperand( out Token t, out TNode n ) { + if( OperandAheadOfDepth <= 0 ) { + t = Token.Empty; + n = TNode.Empty; + return false; + } if( _isNode.Pop() ) { t = Token.Empty; n = _nodeArray[ --_nodeCount ]; @@ -125,8 +132,11 @@ namespace StgSharp.Script public Token PopOperator() { - _operatorCount--; - return _operatorArray[ _operatorCount ]; + if( OperatorAheadOfDepth > 0 ) { + _operatorCount--; + return _operatorArray[ _operatorCount ]; + } + return Token.Empty; } public void PushOperand( TNode node ) @@ -159,13 +169,53 @@ namespace StgSharp.Script _isNode.Push( false ); } + public bool TryPopOperand( out bool isNode, out Token t, out TNode n ) + { + if( OperandAheadOfDepth <= 0 ) { + t = Token.Empty; + n = TNode.Empty; + isNode = false; + return false; + } + if( _isNode.Pop() ) { + t = Token.Empty; + n = _nodeArray[ --_nodeCount ]; + isNode = true; + return true; + } else { + t = _tokenArray[ --_tokenCount ]; + n = TNode.Empty; + isNode = false; + return false; + } + } + + public bool TryPopOperator( out Token op ) + { + if( OperatorAheadOfDepth > 0 ) { + op = _operatorArray[ --_operatorCount ]; + return true; + } + op = Token.Empty; + return false; + } + } - public struct CompileDepthMark + public class CompileDepthMark { - public int OperandBegin; - public int OperatorBegin; + public int OperandBegin + { + get; + set; + } + + public int OperatorBegin + { + get; + set; + } } } diff --git a/StgSharp.Script/Common/IASTNode.cs b/StgSharp.Script/Common/IASTNode.cs index dcab775a..22487b1f 100644 --- a/StgSharp.Script/Common/IASTNode.cs +++ b/StgSharp.Script/Common/IASTNode.cs @@ -43,12 +43,17 @@ namespace StgSharp.Script where TType: ITypeSource { - long NodeFlag + int Line { get; } - string Name + int Column + { + get; + } + + long NodeFlag { get; } diff --git a/StgSharp.Script/Express/ExpAstNode/_ExpNode.cs b/StgSharp.Script/Express/ExpAstNode/_ExpNode.cs index e5b29316..31261ced 100644 --- a/StgSharp.Script/Express/ExpAstNode/_ExpNode.cs +++ b/StgSharp.Script/Express/ExpAstNode/_ExpNode.cs @@ -95,8 +95,6 @@ namespace StgSharp.Script.Express init; } - public string Name => _name; - public void AppendNode( ExpNode nextNode ) { Next.Previous = nextNode; diff --git a/StgSharp.Script/Express/ExpNodeGenerator.FunctionCalling.cs b/StgSharp.Script/Express/ExpNodeGenerator.FunctionCalling.cs index ca78f800..1f356401 100644 --- a/StgSharp.Script/Express/ExpNodeGenerator.FunctionCalling.cs +++ b/StgSharp.Script/Express/ExpNodeGenerator.FunctionCalling.cs @@ -42,31 +42,61 @@ namespace StgSharp.Script.Express { private bool _isCallingFunction = false; - private Stack _callDepth = new Stack(); + private List _funcCallDepthCount = new List( + ); - private void EnterFunctionCalling( Token funcNameToken ) + private void EnterFunctionCalling() { _isCallingFunction = true; - _callDepth.Push( _operandsToken.Count ); + CompileDepthMark mark = _cache.IncreaseDepth(); + _funcCallDepthCount.Add( mark ); } private void ExitFunctionCalling() { - _callDepth.Pop(); - if( _callDepth.Count == 0 ) { + CompileDepthMark mark = _funcCallDepthCount.Last(); + if( _funcCallDepthCount.Count == 0 ) { _isCallingFunction = false; } } - //TODO cannot process occasion of void input or null at first + //checking _operandAheadOfDepth can be used to check if the function calling has no param. //put one of param to tail of function calling pram expression node + /// + /// Compile a parameter expression and add it to head of function parameter node list. + /// private void MergeFunctionCallingParameter() { if( _cache.OperandAheadOfDepth == 1 ) { if( _cache.PopOperand( out Token t, out ExpNode? n ) ) { n!.PrependNode( ExpNode.NonOperation( PoolString( "FuncParam" ) ) ); - } else { } + } else { + switch( t.Flag ) { + case TokenFlag.Number: + if( int.TryParse( t.Value, out int intVal ) ) { + n = new ExpLiteralGenericNode( + t.Value, intVal ); + } else if( float.TryParse( + t.Value, out float floatVal ) ) { + n = new ExpLiteralGenericNode( + t.Value, floatVal ); + } + break; + case TokenFlag.String: + n = new ExpLiteralGenericNode( + t.Value, t.Value ); + break; + case TokenFlag.Member: + + // case1: name of a instance, make ref copy + // case2: name of a function, make a function call + // case3: unknown, make a instance member node, check while link + break; + default: + break; + } + } } else { //TODO compile the param expression } @@ -74,4 +104,3 @@ namespace StgSharp.Script.Express } } -} diff --git a/StgSharp.Script/Express/ExpNodeGenerator.cs b/StgSharp.Script/Express/ExpNodeGenerator.cs index 868c2e7e..bddcaa0a 100644 --- a/StgSharp.Script/Express/ExpNodeGenerator.cs +++ b/StgSharp.Script/Express/ExpNodeGenerator.cs @@ -110,6 +110,7 @@ namespace StgSharp.Script.Express private void ConvertOneOperator() { Token @operator = _cache.PopOperator(); + switch( @operator.Flag ) { case TokenFlag.Symbol_Unary: TryGenerateUnaryNode( @operator, out ExpNode? node ); diff --git a/StgSharp.Script/obj/x64/Debug/net8.0/StgSharp.Script.AssemblyInfo.cs b/StgSharp.Script/obj/x64/Debug/net8.0/StgSharp.Script.AssemblyInfo.cs index 5c623611..7ada6516 100644 --- a/StgSharp.Script/obj/x64/Debug/net8.0/StgSharp.Script.AssemblyInfo.cs +++ b/StgSharp.Script/obj/x64/Debug/net8.0/StgSharp.Script.AssemblyInfo.cs @@ -14,7 +14,7 @@ using System.Reflection; [assembly: System.Reflection.AssemblyCompanyAttribute("StgSharp.Script")] [assembly: System.Reflection.AssemblyConfigurationAttribute("Debug")] [assembly: System.Reflection.AssemblyFileVersionAttribute("1.0.0.0")] -[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+8460bfd56ad622a66ba2c972a2de7e7f4d5f80d3")] +[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+df321a3bae3d97d043473f4595cc8d229d0f2722")] [assembly: System.Reflection.AssemblyProductAttribute("StgSharp.Script")] [assembly: System.Reflection.AssemblyTitleAttribute("StgSharp.Script")] [assembly: System.Reflection.AssemblyVersionAttribute("1.0.0.0")] diff --git a/StgSharp.Script/obj/x64/Debug/net8.0/StgSharp.Script.sourcelink.json b/StgSharp.Script/obj/x64/Debug/net8.0/StgSharp.Script.sourcelink.json index 48222c59..47034813 100644 --- a/StgSharp.Script/obj/x64/Debug/net8.0/StgSharp.Script.sourcelink.json +++ b/StgSharp.Script/obj/x64/Debug/net8.0/StgSharp.Script.sourcelink.json @@ -1 +1 @@ -{"documents":{"D:\\NitloadIndustry\\研究项目\\1-Flagship\\TH2020\\ProjectFile\\内核源代码\\*":"https://raw.githubusercontent.com/Nitload-NSI/CCD_Github/825e68853cd1738287eecc8a4390ee9c78550308/*"}} \ No newline at end of file +{"documents":{"D:\\NitloadIndustry\\研究项目\\1-Flagship\\TH2020\\ProjectFile\\内核源代码\\*":"https://raw.githubusercontent.com/Nitload-NSI/CCD_Github/df321a3bae3d97d043473f4595cc8d229d0f2722/*"}} \ No newline at end of file