Daily update 2 on 20240228 by nitload youmu
This commit is contained in:
@@ -0,0 +1,142 @@
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
// file="DefaultSchema.cs"
|
||||
// Project: StgSharp
|
||||
// AuthorGroup: Nitload Space
|
||||
// Copyright (c) Nitload Space. 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;
|
||||
using System.Collections.Frozen;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Xml.Linq;
|
||||
|
||||
using static StgSharp.Script.Express.ExpCompile;
|
||||
|
||||
namespace StgSharp.Script.Express
|
||||
{
|
||||
internal partial class ExpSchema_Nitload : ExpSchema
|
||||
{
|
||||
|
||||
private static readonly ExpSchema_Nitload _onlyInstance = new ExpSchema_Nitload(
|
||||
);
|
||||
|
||||
private ExpSchema_Nitload()
|
||||
: base()
|
||||
{
|
||||
Name = "Nitload";
|
||||
}
|
||||
|
||||
public static ExpSchema Only
|
||||
{
|
||||
get => _onlyInstance;
|
||||
}
|
||||
|
||||
public override void LoadFromSource( ExpSchemaSource source )
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
public override bool TryGetConst(
|
||||
string name,
|
||||
out ExpElementInstanceBase c )
|
||||
{
|
||||
return ConstDict.TryGetValue( name, out c );
|
||||
}
|
||||
|
||||
public override bool TryGetEntity( string name, out ExpEntitySource e )
|
||||
{
|
||||
e = null;
|
||||
return false;
|
||||
}
|
||||
|
||||
public override bool TryGetFunction(
|
||||
string name,
|
||||
out ExpFunctionSource f )
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public override bool TryGetRule( string name, out ExpRuleSource r )
|
||||
{
|
||||
r = null!;
|
||||
return false;
|
||||
}
|
||||
|
||||
public override bool TryGetSchemaInclude(
|
||||
string name,
|
||||
out ExpSchema include )
|
||||
{
|
||||
include = null!;
|
||||
return false;
|
||||
}
|
||||
|
||||
public override bool TryGetType( string name, out ExpTypeSource t )
|
||||
{
|
||||
return TypeDict.TryGetValue( name, out t );
|
||||
}
|
||||
|
||||
internal void Init()
|
||||
{
|
||||
IEnumerable<KeyValuePair<string, ExpTypeSource>> builtinTypeSource = [
|
||||
new KeyValuePair<string, ExpTypeSource>(
|
||||
PoolString( KeyWord.Int ),
|
||||
new ExpBuiltinType( KeyWord.Int, typeof( int ) ) ),
|
||||
new KeyValuePair<string, ExpTypeSource>(
|
||||
PoolString( KeyWord.Real ),
|
||||
new ExpBuiltinType( KeyWord.Real, typeof( float ) ) ),
|
||||
new KeyValuePair<string, ExpTypeSource>(
|
||||
PoolString( KeyWord.Bool ),
|
||||
new ExpBuiltinType( KeyWord.Bool, typeof( bool ) ) ),
|
||||
new KeyValuePair<string, ExpTypeSource>(
|
||||
PoolString( KeyWord.Logic ),
|
||||
new ExpBuiltinType( KeyWord.Logic, typeof( ExpLogic ) ) ),
|
||||
new KeyValuePair<string, ExpTypeSource>(
|
||||
PoolString( KeyWord.String ),
|
||||
new ExpBuiltinType( KeyWord.String, typeof( string ) ) ),
|
||||
new KeyValuePair<string, ExpTypeSource>(
|
||||
PoolString( KeyWord.Binary ),
|
||||
new ExpBuiltinType( KeyWord.Binary, typeof( BitArray ) ) ),
|
||||
|
||||
];
|
||||
TypeDict = new Dictionary<string, ExpTypeSource>(
|
||||
builtinTypeSource, Multiplexer ).ToFrozenDictionary();
|
||||
|
||||
|
||||
ConstDict = new Dictionary<string, ExpElementInstanceBase>(
|
||||
Multiplexer ) {
|
||||
{ PoolString( "PI" ), new ExpBuiltinConstant<float>(
|
||||
PoolString( "PI" ), MathF.PI ) },
|
||||
{ PoolString( "E" ), new ExpBuiltinConstant<float>(
|
||||
PoolString( "E" ), MathF.E ) },
|
||||
}.ToFrozenDictionary();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,120 @@
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
// file="ExpCompile.cs"
|
||||
// Project: StgSharp
|
||||
// AuthorGroup: Nitload Space
|
||||
// Copyright (c) Nitload Space. 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 CommunityToolkit.HighPerformance.Buffers;
|
||||
|
||||
using StgSharp.Collections;
|
||||
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Frozen;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.ComponentModel;
|
||||
using System.Text;
|
||||
|
||||
namespace StgSharp.Script.Express
|
||||
{
|
||||
public static partial class ExpCompile
|
||||
{
|
||||
|
||||
private static string[] _operatorsWithLetter;
|
||||
private static ConcurrentStringHashMultiplexer _multiplexer;
|
||||
private static FrozenDictionary<string, ExpElementInstanceBase> _builtinConst;
|
||||
private static FrozenDictionary<string, ExpTypeSource> _builtinType;
|
||||
private static FrozenDictionary<string, ExpBinaryOperatorNode> _operators;
|
||||
private static StringPool _compileStringCache;
|
||||
|
||||
internal static ConcurrentStringHashMultiplexer Multiplexer
|
||||
{
|
||||
get
|
||||
{
|
||||
if( _multiplexer == null ) {
|
||||
throw new ExpCompileNotInitializedException();
|
||||
}
|
||||
return _multiplexer;
|
||||
}
|
||||
}
|
||||
|
||||
public static void ClearStringCache()
|
||||
{
|
||||
_compileStringCache.Reset();
|
||||
}
|
||||
|
||||
public static void DeinitCompile()
|
||||
{
|
||||
_compileStringCache.Reset();
|
||||
_compileStringCache = null!;
|
||||
|
||||
_multiplexer.Dispose();
|
||||
_multiplexer = null!;
|
||||
}
|
||||
|
||||
public static void InitCompile()
|
||||
{
|
||||
_compileStringCache = new StringPool();
|
||||
_multiplexer = new ConcurrentStringHashMultiplexer();
|
||||
|
||||
PoolKeywords();
|
||||
InitPrecedence();
|
||||
|
||||
_operatorsWithLetter = [
|
||||
KeyWord.ADD,
|
||||
KeyWord.SUB,
|
||||
KeyWord.MUL,
|
||||
KeyWord.DIV,
|
||||
KeyWord.AND,
|
||||
KeyWord.OR,
|
||||
KeyWord.XOR,
|
||||
KeyWord.ANDOR,
|
||||
KeyWord.NOT,
|
||||
];
|
||||
}
|
||||
|
||||
public static bool LetterIsOperator( string str )
|
||||
{
|
||||
if( char.IsLetter( str[ 0 ] ) ) {
|
||||
return Array.IndexOf( _operatorsWithLetter, str ) != -1;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public static string PoolString( string str )
|
||||
{
|
||||
return _compileStringCache.GetOrAdd( str );
|
||||
}
|
||||
|
||||
public static string PoolString( ReadOnlySpan<char> str )
|
||||
{
|
||||
return _compileStringCache.GetOrAdd( str );
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,106 @@
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
// file="ExpOperatorPrecedence.cs"
|
||||
// Project: StgSharp
|
||||
// AuthorGroup: Nitload Space
|
||||
// Copyright (c) Nitload Space. 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.Frozen;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace StgSharp.Script.Express
|
||||
{
|
||||
public static partial class ExpCompile
|
||||
{
|
||||
|
||||
public static bool TryGetOperatorPrecedence(
|
||||
string operatorName,
|
||||
out int precedence )
|
||||
{
|
||||
return _operatorPrecedence.TryGetValue(
|
||||
operatorName, out precedence );
|
||||
}
|
||||
|
||||
public static bool TryGetSuperTypeOperatorPrecedence(
|
||||
string operatorName,
|
||||
out int precedence )
|
||||
{
|
||||
return _superTypeOperatorPrecedent.TryGetValue(
|
||||
operatorName, out precedence );
|
||||
}
|
||||
|
||||
private static void InitPrecedence()
|
||||
{
|
||||
KeyValuePair<string, int>[] source = [
|
||||
new KeyValuePair<string, int>( PoolString( "[" ), 1 ),
|
||||
new KeyValuePair<string, int>( PoolString( "." ), 1 ),
|
||||
new KeyValuePair<string, int>( PoolString( "\\" ), 1 ),
|
||||
new KeyValuePair<string, int>( PoolString( "unary+" ), 2 ),
|
||||
new KeyValuePair<string, int>( PoolString( "unary-" ), 2 ),
|
||||
new KeyValuePair<string, int>( PoolString( "NOT" ), 2 ),
|
||||
new KeyValuePair<string, int>( PoolString( "**" ), 3 ),
|
||||
new KeyValuePair<string, int>( PoolString( "*" ), 4 ),
|
||||
new KeyValuePair<string, int>( PoolString( "/" ), 4 ),
|
||||
new KeyValuePair<string, int>( PoolString( "AND" ), 4 ),
|
||||
new KeyValuePair<string, int>( PoolString( "MOD" ), 4 ),
|
||||
new KeyValuePair<string, int>( PoolString( "DIV" ), 4 ),
|
||||
new KeyValuePair<string, int>( PoolString( "||" ), 4 ),
|
||||
new KeyValuePair<string, int>( PoolString( "+" ), 5 ),
|
||||
new KeyValuePair<string, int>( PoolString( "-" ), 5 ),
|
||||
new KeyValuePair<string, int>( PoolString( "OR" ), 5 ),
|
||||
new KeyValuePair<string, int>( PoolString( "XOR" ), 5 ),
|
||||
new KeyValuePair<string, int>( PoolString( "=" ), 6 ),
|
||||
new KeyValuePair<string, int>( PoolString( "<>" ), 6 ),
|
||||
new KeyValuePair<string, int>( PoolString( "<=" ), 6 ),
|
||||
new KeyValuePair<string, int>( PoolString( ">=" ), 6 ),
|
||||
new KeyValuePair<string, int>( PoolString( ">" ), 6 ),
|
||||
new KeyValuePair<string, int>( PoolString( "<" ), 6 ),
|
||||
new KeyValuePair<string, int>( PoolString( ":=:" ), 6 ),
|
||||
new KeyValuePair<string, int>( PoolString( ":<>:" ), 6 ),
|
||||
new KeyValuePair<string, int>( PoolString( "IN" ), 6 ),
|
||||
new KeyValuePair<string, int>( PoolString( "LIKE" ), 6 ),
|
||||
];
|
||||
_operatorPrecedence = new Dictionary<string, int>(
|
||||
source, _multiplexer ).ToFrozenDictionary();
|
||||
source = [
|
||||
new KeyValuePair<string, int>( "ONEOF", 1 ),
|
||||
new KeyValuePair<string, int>( "AND", 2 ),
|
||||
new KeyValuePair<string, int>( "ANDOR", 3 ),
|
||||
];
|
||||
_superTypeOperatorPrecedent = new Dictionary<string, int>(
|
||||
source, _multiplexer ).ToFrozenDictionary();
|
||||
}
|
||||
|
||||
#pragma warning disable CS8618
|
||||
private static FrozenDictionary<string, int> _superTypeOperatorPrecedent;
|
||||
private static FrozenDictionary<string, int> _operatorPrecedence;
|
||||
#pragma warning restore CS8618
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,93 @@
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
// file="KeyWord.cs"
|
||||
// Project: StgSharp
|
||||
// AuthorGroup: Nitload Space
|
||||
// Copyright (c) Nitload Space. 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.Reflection;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace StgSharp.Script.Express
|
||||
{
|
||||
public static partial class ExpCompile
|
||||
{
|
||||
|
||||
private static void PoolKeywords()
|
||||
{
|
||||
FieldInfo[] fields = typeof( KeyWord ).GetFields(
|
||||
BindingFlags.Public );
|
||||
ParallelLoopResult result = Parallel.ForEach(
|
||||
fields, static( field ) => {
|
||||
if( field.FieldType == typeof( string ) && field.GetValue(
|
||||
null ) is string str ) {
|
||||
_compileStringCache.GetOrAdd( str );
|
||||
}
|
||||
} );
|
||||
while( !result.IsCompleted ) { }
|
||||
}
|
||||
|
||||
public static class KeyWord
|
||||
{
|
||||
|
||||
public const string Int = "INTAGER",
|
||||
Real = "REAL",
|
||||
Bool = "BOOLEAN",
|
||||
String = "STRING",
|
||||
Logic = "LOGIC",
|
||||
Binary = "BINARY",
|
||||
Constant = "CONSTANT",
|
||||
AND = "AND",
|
||||
OR = "OR",
|
||||
XOR = "XOR",
|
||||
ADD = "+",
|
||||
SUB = "-",
|
||||
MUL = "*",
|
||||
DIV = "/",
|
||||
NOT = "NOT",
|
||||
Assignment = ":=",
|
||||
Equal = "=",
|
||||
Mod = "MOD",
|
||||
Self = "SELF",
|
||||
Pi = "PI",
|
||||
True = "TRUE",
|
||||
False = "FALSE",
|
||||
Insert = "INSERT",
|
||||
Remove = "REMOVE",
|
||||
ANDOR = "ANDOR",
|
||||
GetIndex = "[",
|
||||
UnaryAdd = "+",
|
||||
UnarySub = "-",
|
||||
Exp = "**";
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user