From 9647c2c68a768a1d0a5a05cc1279d046403c4641 Mon Sep 17 00:00:00 2001 From: Nitload Date: Wed, 12 Mar 2025 07:46:48 +0800 Subject: [PATCH] Daily update on 20250312-074647 by Nitload Youmu. Additional Message : Change: Temp not want to compile RULE and PROCEDURE Add: Add factory method to generate more kind of binary operator node Add: more SIMD intrinsic C function Signed-off-by: Nitload --- StgSharp.C/intrinsic.c | 4 + StgSharp.C/mat2.c | 15 ++ StgSharp.C/mat3.c | 26 +++ StgSharp.C/mat4.c | 19 +++ StgSharp.C/ssc_intrinsic.h | 15 +- StgSharp.Common/Data/SSD/DataHead.cs | 2 +- StgSharp.Common/HighPerformance/M128.cs | 26 +-- StgSharp.Common/Internal/ClangLoad/gl.cs | 1 - .../Internal/Intrinsic/IntrinsicContext.cs | 3 + StgSharp.Common/Math/Linear/Matrix22.cs | 55 +++--- StgSharp.Common/Math/Linear/Matrix23.cs | 49 +++--- StgSharp.Common/Math/Linear/Matrix24.cs | 59 +++---- StgSharp.Common/Math/Linear/Matrix32.cs | 42 ++--- StgSharp.Common/Math/Linear/Matrix33.cs | 59 +++---- StgSharp.Common/Math/Linear/Matrix34.cs | 67 ++++---- StgSharp.Common/Math/Linear/Matrix42.cs | 64 +++---- StgSharp.Script/Common/Token.cs | 7 + .../Express/CompileEnv/BuiltinType.cs | 6 + .../Express/CompileEnv/ExpCompile.cs | 5 + StgSharp.Script/Express/CompileEnv/KeyWord.cs | 1 + .../ExpAstNode/ExpBinaryOperatorNode.cs | 70 ++++++++ .../Express/ExpAstNode/ExpLiteralNode.cs | 157 ++++++++++++++++++ .../Express/ExpAstNode/ExpRepeatNode.cs | 4 +- .../Express/ExpNodeGenerator.Operator.cs | 7 + StgSharp.Script/Express/ExpNodeGenerator.cs | 10 +- .../Express/ExpSchemaSource.Compile.cs | 72 ++++++++ .../net8.0/StgSharp.Script.AssemblyInfo.cs | 2 +- .../net8.0/StgSharp.Script.sourcelink.json | 2 +- StgSharpDebug/Program.cs | 40 +---- 29 files changed, 645 insertions(+), 244 deletions(-) create mode 100644 StgSharp.Script/Express/ExpAstNode/ExpLiteralNode.cs create mode 100644 StgSharp.Script/Express/ExpSchemaSource.Compile.cs diff --git a/StgSharp.C/intrinsic.c b/StgSharp.C/intrinsic.c index bfd00e20..2c6704e6 100644 --- a/StgSharp.C/intrinsic.c +++ b/StgSharp.C/intrinsic.c @@ -84,6 +84,10 @@ void load_intrinsic_sse(ssc_intrinsic *context) context->dot_43 = dot_43_sse; context->city_hash_simplify = city_hash_simplify_sse; context->index_pair = index_pair_sse; + context->sub_m2 = submatrix2_sse; + context->sub_m3 = submatrix3_sse; + context->sub_m4 = submatrix4_sse; + } void load_intrinsic_avx(ssc_intrinsic *context) diff --git a/StgSharp.C/mat2.c b/StgSharp.C/mat2.c index 211b1eab..aca21beb 100644 --- a/StgSharp.C/mat2.c +++ b/StgSharp.C/mat2.c @@ -40,3 +40,18 @@ INTERNAL void __cdecl addmatrix2_avx(__2_columnset *left, __2_columnset *right, __m256 temp = _mm256_add_ps(ALIGN256(left->column[0]), ALIGN256(right->column[0])); _mm256_storeu_ps(&ans->m[0][0], temp); } + +INTERNAL void __cdecl submatrix2_sse(__2_columnset *left, __2_columnset *right, __2_columnset *ans) +{ + __m128 temp0 = _mm_sub_ps(ALIGN(left->column[0]), ALIGN(right->column[0])); + __m128 temp1 = _mm_sub_ps(ALIGN(left->column[1]), ALIGN(right->column[1])); + + _mm_storeu_ps(&ans->m[0][0], temp0); + _mm_storeu_ps(&ans->m[0][1], temp1); +} + +INTERNAL void __cdecl submatrix2_avx(__2_columnset *left, __2_columnset *right, __2_columnset *ans) +{ + __m256 temp = _mm256_sub_ps(ALIGN256(left->column[0]), ALIGN256(right->column[0])); + _mm256_storeu_ps(&ans->m[0][0], temp); +} diff --git a/StgSharp.C/mat3.c b/StgSharp.C/mat3.c index b9dfeef6..96a8b35c 100644 --- a/StgSharp.C/mat3.c +++ b/StgSharp.C/mat3.c @@ -101,4 +101,30 @@ INTERNAL void __cdecl addmatrix3_512(__3_columnset *left, __3_columnset *right, _mm512_mask_store_ps(ans, 0x0fff, temp); } +INTERNAL void __cdecl submatrix3_sse(__3_columnset *left, __3_columnset *right, __3_columnset *ans) +{ + __m128 temp0 = _mm_sub_ps(ALIGN(left->column[0]), ALIGN(right->column[0])); + __m128 temp1 = _mm_sub_ps(ALIGN(left->column[1]), ALIGN(right->column[1])); + __m128 temp2 = _mm_sub_ps(ALIGN(left->column[2]), ALIGN(right->column[2])); + + _mm_storeu_ps(&ans->m[0][0], temp0); + _mm_storeu_ps(&ans->m[0][1], temp1); + _mm_storeu_ps(&ans->m[0][2], temp2); +} + +INTERNAL void __cdecl submatrix3_avx(__3_columnset *left, __3_columnset *right, __3_columnset *ans) +{ + __m256 temp0 = _mm256_sub_ps(ALIGN256(left->part), ALIGN256(right->part)); + __m128 temp1 = _mm_sub_ps(ALIGN(left->column[2]), ALIGN(right->column[2])); + + _mm256_storeu_ps(&ans->m[0][0], temp0); + _mm_storeu_ps(&ans->m[0][2], temp1); +} + +INTERNAL void __cdecl submatrix3_512(__3_columnset *left, __3_columnset *right, __3_columnset *ans) +{ + __m512 temp = _mm512_sub_ps(_mm512_loadu_ps(left), _mm512_loadu_ps(right)); + _mm512_mask_store_ps(ans, 0x0fff, temp); +} + #pragma endregion diff --git a/StgSharp.C/mat4.c b/StgSharp.C/mat4.c index 5ddd28f6..b7b322d4 100644 --- a/StgSharp.C/mat4.c +++ b/StgSharp.C/mat4.c @@ -82,3 +82,22 @@ INTERNAL void SSCDECL addmatrix4_512(__4_columnset *left, __4_columnset *right, { ans->stream = _mm512_add_ps(ALIGN512(left->stream), ALIGN512(right->stream)); } + +INTERNAL void SSCDECL submatrix4_sse(__4_columnset *left, __4_columnset *right, __4_columnset *ans) +{ + ans->column[0] = _mm_sub_ps(ALIGN(left->column[0]), ALIGN(right->column[0])); + ans->column[1] = _mm_sub_ps(ALIGN(left->column[1]), ALIGN(right->column[1])); + ans->column[2] = _mm_sub_ps(ALIGN(left->column[2]), ALIGN(right->column[2])); + ans->column[3] = _mm_sub_ps(ALIGN(left->column[3]), ALIGN(right->column[3])); +} + +INTERNAL void SSCDECL submatrix4_avx(__4_columnset *left, __4_columnset *right, __4_columnset *ans) +{ + ans->half[0] = _mm256_sub_ps(ALIGN256(left->half[0]), ALIGN256(right->half[0])); + ans->half[1] = _mm256_sub_ps(ALIGN256(left->half[1]), ALIGN256(right->half[1])); +} + +INTERNAL void SSCDECL submatrix4_512(__4_columnset *left, __4_columnset *right, __4_columnset *ans) +{ + ans->stream = _mm512_sub_ps(ALIGN512(left->stream), ALIGN512(right->stream)); +} diff --git a/StgSharp.C/ssc_intrinsic.h b/StgSharp.C/ssc_intrinsic.h index a82dd608..9a99f8ee 100644 --- a/StgSharp.C/ssc_intrinsic.h +++ b/StgSharp.C/ssc_intrinsic.h @@ -30,7 +30,7 @@ typedef union uint64_u { uint64_t u64; uint32_t u32[2]; -}uint64_u; +} uint64_u; typedef union column_2 { __m256 stream; @@ -64,12 +64,17 @@ INTERNAL void normalize(__m128 *source, __m128 *target); INTERNAL void SSCDECL addmatrix2_sse(__2_columnset *left, __2_columnset *right, __2_columnset *ans); INTERNAL void SSCDECL addmatrix2_avx(__2_columnset *left, __2_columnset *right, __2_columnset *ans); +INTERNAL void SSCDECL submatrix2_sse(__2_columnset *left, __2_columnset *right, __2_columnset *ans); +INTERNAL void SSCDECL addmatrix2_avx(__2_columnset *left, __2_columnset *right, __2_columnset *ans); INTERNAL void SSCDECL transpose23(__2_columnset const *source, __3_columnset *target); INTERNAL void SSCDECL transpose24(__2_columnset const *source, __4_columnset *target); INTERNAL void SSCDECL addmatrix3_sse(__3_columnset *left, __3_columnset *right, __3_columnset *ans); INTERNAL void SSCDECL addmatrix3_avx(__3_columnset *left, __3_columnset *right, __3_columnset *ans); INTERNAL void SSCDECL addmatrix3_512(__3_columnset *left, __3_columnset *right, __3_columnset *ans); +INTERNAL void SSCDECL submatrix3_sse(__3_columnset *left, __3_columnset *right, __3_columnset *ans); +INTERNAL void SSCDECL submatrix3_avx(__3_columnset *left, __3_columnset *right, __3_columnset *ans); +INTERNAL void SSCDECL submatrix3_512(__3_columnset *left, __3_columnset *right, __3_columnset *ans); INTERNAL void SSCDECL transpose32(__3_columnset const *source, __2_columnset *target); INTERNAL void SSCDECL transpose33(__3_columnset const *source, __3_columnset *target); INTERNAL void SSCDECL transpose34(__3_columnset const *source, __4_columnset *target); @@ -78,6 +83,9 @@ INTERNAL float SSCDECL det_mat3(__3_columnset *matrix, __3_columnset *tranpose); INTERNAL void SSCDECL addmatrix4_sse(__4_columnset *left, __4_columnset *right, __4_columnset *ans); INTERNAL void SSCDECL addmatrix4_avx(__4_columnset *left, __4_columnset *right, __4_columnset *ans); INTERNAL void SSCDECL addmatrix4_512(__4_columnset *left, __4_columnset *right, __4_columnset *ans); +INTERNAL void SSCDECL submatrix4_sse(__4_columnset *left, __4_columnset *right, __4_columnset *ans); +INTERNAL void SSCDECL submatrix4_avx(__4_columnset *left, __4_columnset *right, __4_columnset *ans); +INTERNAL void SSCDECL submatrix4_512(__4_columnset *left, __4_columnset *right, __4_columnset *ans); INTERNAL void SSCDECL transpose42(__4_columnset const *source, __2_columnset *target); INTERNAL void SSCDECL transpose43(__4_columnset const *source, __3_columnset *target); INTERNAL void SSCDECL transpose44(__4_columnset const *source, __4_columnset *target); @@ -99,7 +107,7 @@ INTERNAL void SSCDECL dot_42_avx(__4_columnset *transpose, __m128 *vector, __m12 INTERNAL void SSCDECL dot_43_sse(__4_columnset *transpose, __m128 *vector, __m128 *ans); INTERNAL void SSCDECL dot_43_avx(__4_columnset *transpose, __m128 *vector, __m128 *ans); -INTERNAL void SSCDECL dot_43_512(__4_columnset *transpose, __m128 *vector, __m128 *ans); +//INTERNAL void SSCDECL dot_43_512(__4_columnset *transpose, __m128 *vector, __m128 *ans); #pragma endregion @@ -124,6 +132,9 @@ typedef struct ssc_intrinsic { DOTPROC dot_43; int (*index_pair)(short const *str, uint32_t target, int length); VECTORNORMALIZEPROC normalize_3; + MATARITHMETIC sub_m2; + MATARITHMETIC sub_m3; + MATARITHMETIC sub_m4; MATRIXTRANSPOSEPROC transpose_23; MATRIXTRANSPOSEPROC transpose_24; MATRIXTRANSPOSEPROC transpose_32; diff --git a/StgSharp.Common/Data/SSD/DataHead.cs b/StgSharp.Common/Data/SSD/DataHead.cs index 07dd56a3..14ecb48f 100644 --- a/StgSharp.Common/Data/SSD/DataHead.cs +++ b/StgSharp.Common/Data/SSD/DataHead.cs @@ -66,7 +66,7 @@ namespace StgSharp.Internal public unsafe byte[] GetBytes() { byte[] ret = new byte[16]; - fixed( Vector4* vptr = &data.Vec ) { + fixed( M128* vptr = &data ) { byte* bptr = ( byte* )vptr; for( int i = 0; i < 15; i++ ) { ret[ i ] = *bptr; diff --git a/StgSharp.Common/HighPerformance/M128.cs b/StgSharp.Common/HighPerformance/M128.cs index 3ccf13cc..19b7062d 100644 --- a/StgSharp.Common/HighPerformance/M128.cs +++ b/StgSharp.Common/HighPerformance/M128.cs @@ -48,11 +48,11 @@ namespace StgSharp.HighPerformance { [FieldOffset( 0 )] internal fixed byte Buffer[ 16 ]; - [FieldOffset( 0 )] internal Vector4 Vec; + [FieldOffset( 0 )] internal Vector128 Vec; internal M128( Vector4 v ) { - Vec = v; + Vec = v.AsVector128().AsByte(); } public ref T AsRef() where T: struct, INumber @@ -77,7 +77,7 @@ namespace StgSharp.HighPerformance public T Read( int index ) where T: struct, INumber { - fixed( Vector4* p = &Vec ) { + fixed( byte* p = Buffer ) { #pragma warning disable CS8500 return *( ( T* )p + index ); #pragma warning restore CS8500 @@ -123,61 +123,61 @@ namespace StgSharp.HighPerformance [MethodImpl( MethodImplOptions.AggressiveInlining )] public static explicit operator Vector128( M128 m ) { - return m.Vec.AsVector128().As(); + return m.Vec.As(); } [MethodImpl( MethodImplOptions.AggressiveInlining )] public static explicit operator Vector128( M128 m ) { - return m.Vec.AsVector128().As(); + return m.Vec.As(); } [MethodImpl( MethodImplOptions.AggressiveInlining )] public static explicit operator Vector128( M128 m ) { - return m.Vec.AsVector128().As(); + return m.Vec.As(); } [MethodImpl( MethodImplOptions.AggressiveInlining )] public static explicit operator Vector128( M128 m ) { - return m.Vec.AsVector128().As(); + return m.Vec.As(); } [MethodImpl( MethodImplOptions.AggressiveInlining )] public static explicit operator Vector128( M128 m ) { - return m.Vec.AsVector128().As(); + return m.Vec.As(); } [MethodImpl( MethodImplOptions.AggressiveInlining )] public static explicit operator Vector128( M128 m ) { - return m.Vec.AsVector128().As(); + return m.Vec.As(); } [MethodImpl( MethodImplOptions.AggressiveInlining )] public static explicit operator Vector128( M128 m ) { - return m.Vec.AsVector128().As(); + return m.Vec.As(); } [MethodImpl( MethodImplOptions.AggressiveInlining )] public static explicit operator Vector128( M128 m ) { - return m.Vec.AsVector128().As(); + return m.Vec.As(); } [MethodImpl( MethodImplOptions.AggressiveInlining )] public static explicit operator Vector128( M128 m ) { - return m.Vec.AsVector128().As(); + return m.Vec.As(); } [MethodImpl( MethodImplOptions.AggressiveInlining )] public static explicit operator Vector128( M128 m ) { - return m.Vec.AsVector128().As(); + return m.Vec.As(); } } diff --git a/StgSharp.Common/Internal/ClangLoad/gl.cs b/StgSharp.Common/Internal/ClangLoad/gl.cs index 0fb83e57..0a412ac2 100644 --- a/StgSharp.Common/Internal/ClangLoad/gl.cs +++ b/StgSharp.Common/Internal/ClangLoad/gl.cs @@ -30,7 +30,6 @@ //----------------------------------------------------------------------- using StgSharp.Graphics; using StgSharp.Graphics.OpenGL; -using StgSharp.Internal.OpenGL; using System; using System.Collections.Generic; diff --git a/StgSharp.Common/Internal/Intrinsic/IntrinsicContext.cs b/StgSharp.Common/Internal/Intrinsic/IntrinsicContext.cs index a5016dce..e2aa5c0a 100644 --- a/StgSharp.Common/Internal/Intrinsic/IntrinsicContext.cs +++ b/StgSharp.Common/Internal/Intrinsic/IntrinsicContext.cs @@ -58,6 +58,9 @@ namespace StgSharp.Internal.Intrinsic public delegate* unmanaged[Cdecl] dot_43; public delegate* unmanaged[Cdecl] index_pair; public delegate* unmanaged[Cdecl] normalize_v3; + public delegate* unmanaged[Cdecl] sub_mat_2; + public delegate* unmanaged[Cdecl] sub_mat_3; + public delegate* unmanaged[Cdecl] sub_mat_4; public delegate* unmanaged[Cdecl] transpose23; public delegate* unmanaged[Cdecl] transpose24; public delegate* unmanaged[Cdecl] transpose32; diff --git a/StgSharp.Common/Math/Linear/Matrix22.cs b/StgSharp.Common/Math/Linear/Matrix22.cs index 84a9b0fb..176c6996 100644 --- a/StgSharp.Common/Math/Linear/Matrix22.cs +++ b/StgSharp.Common/Math/Linear/Matrix22.cs @@ -37,11 +37,12 @@ using System.Runtime.InteropServices; namespace StgSharp.Math { [StructLayout( - LayoutKind.Explicit, - Size = ( 2 * 2 * 4 * sizeof( float ) ) + sizeof( bool ), - Pack = 16 )] + LayoutKind.Explicit, + Size = ( 2 * 2 * 4 * sizeof( float ) ) + sizeof( bool ), + Pack = 16 )] public struct Matrix22 : IMat { + [FieldOffset( 2 * 2 * 4 * sizeof( float ) )] internal bool isTransposed = false; @@ -50,12 +51,6 @@ namespace StgSharp.Math [FieldOffset( 2 * 4 * sizeof( float ) )] internal ColumnSet2 _transpose; - public Matrix22() - { - Unsafe.SkipInit( out this ); - isTransposed = false; - } - internal Matrix22( ColumnSet2 mat ) { this._mat = mat; @@ -63,15 +58,21 @@ namespace StgSharp.Math internal Matrix22( Vector4 c0, Vector4 c1 ) { - Unsafe.SkipInit(out this); + Unsafe.SkipInit( out this ); isTransposed = false; _mat.colum0 = c0; _mat.colum1 = c1; } + public Matrix22() + { + Unsafe.SkipInit( out this ); + isTransposed = false; + } + public Matrix22( float a00, float a01, float a10, float a11 ) { - Unsafe.SkipInit(out this); + Unsafe.SkipInit( out this ); isTransposed = false; _mat.colum0 = new Vector4( a00, a10, 0, 0 ); _mat.colum1 = new Vector4( a01, a11, 0, 0 ); @@ -105,22 +106,17 @@ namespace StgSharp.Math } } - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static unsafe Matrix22 operator +(Matrix22 left, Matrix22 right) + [MethodImpl( MethodImplOptions.AggressiveInlining )] + public static unsafe Matrix22 operator -( + Matrix22 left, + Matrix22 right ) { Matrix22 ret = new Matrix22(); - InternalIO.Intrinsic.add_mat_2( &left._mat, &right._mat, &ret._mat ); + InternalIO.Intrinsic.sub_mat_2( &left._mat, &right._mat, + &ret._mat ); return ret; } - [MethodImpl( MethodImplOptions.AggressiveInlining )] - public static Matrix22 operator -( Matrix22 left, Matrix22 right ) - { - return new Matrix22( - left._mat.colum0 + right._mat.colum0, - left._mat.colum1 + right._mat.colum1 ); - } - [MethodImpl( MethodImplOptions.AggressiveInlining )] public static Matrix22 operator *( Matrix22 mat, float value ) { @@ -137,7 +133,7 @@ namespace StgSharp.Math Vector4.Dot( left._transpose.colum0, right._mat.colum1 ), Vector4.Dot( left._transpose.colum1, right._mat.colum0 ), - Vector4.Dot( left._transpose.colum1, right._mat.colum1 )); + Vector4.Dot( left._transpose.colum1, right._mat.colum1 ) ); } [MethodImpl( MethodImplOptions.AggressiveInlining )] @@ -167,7 +163,7 @@ namespace StgSharp.Math Vector4.Dot( left._transpose.colum1, right.mat.colum0 ), Vector4.Dot( left._transpose.colum1, right.mat.colum1 ), Vector4.Dot( left._transpose.colum1, right.mat.colum2 ), - Vector4.Dot( left._transpose.colum1, right.mat.colum3 )); + Vector4.Dot( left._transpose.colum1, right.mat.colum3 ) ); } [MethodImpl( MethodImplOptions.AggressiveInlining )] @@ -177,5 +173,16 @@ namespace StgSharp.Math mat._mat.colum0 / value, mat._mat.colum1 / value ); } + [MethodImpl( MethodImplOptions.AggressiveInlining )] + public static unsafe Matrix22 operator +( + Matrix22 left, + Matrix22 right ) + { + Matrix22 ret = new Matrix22(); + InternalIO.Intrinsic.add_mat_2( &left._mat, &right._mat, + &ret._mat ); + return ret; + } + } } diff --git a/StgSharp.Common/Math/Linear/Matrix23.cs b/StgSharp.Common/Math/Linear/Matrix23.cs index d65fb1c7..e41238cf 100644 --- a/StgSharp.Common/Math/Linear/Matrix23.cs +++ b/StgSharp.Common/Math/Linear/Matrix23.cs @@ -38,9 +38,9 @@ using System.Runtime.InteropServices; namespace StgSharp.Math { [StructLayout( - LayoutKind.Explicit, - Size = ( ( 3 + 2 ) * 4 * sizeof( float ) ) + sizeof( bool ), - Pack = 16 )] + LayoutKind.Explicit, + Size = ( ( 3 + 2 ) * 4 * sizeof( float ) ) + sizeof( bool ), + Pack = 16 )] public struct Matrix23 : IMat { @@ -48,12 +48,6 @@ namespace StgSharp.Math [FieldOffset( 3 * 4 * sizeof( float ) )] internal ColumnSet2 _transpose; [FieldOffset( 0 )] internal ColumnSet3 _mat; - public Matrix23() - { - Unsafe.SkipInit( out _mat); - Unsafe.SkipInit(out _transpose); - } - internal Matrix23( Vector4 c0, Vector4 c1, Vector4 c2 ) { _mat.colum0 = c0; @@ -61,13 +55,19 @@ namespace StgSharp.Math _mat.colum2 = c2; } + public Matrix23() + { + Unsafe.SkipInit( out _mat ); + Unsafe.SkipInit( out _transpose ); + } + public Matrix23( - float a00, - float a01, - float a02, - float a10, - float a11, - float a12 ) + float a00, + float a01, + float a02, + float a10, + float a11, + float a12 ) { _mat.colum0 = new Vector4( a00, a10, 0, 0 ); _mat.colum1 = new Vector4( a01, a11, 0, 0 ); @@ -122,12 +122,14 @@ namespace StgSharp.Math } [MethodImpl( MethodImplOptions.AggressiveInlining )] - public static Matrix23 operator -( Matrix23 left, Matrix23 right ) + public static unsafe Matrix23 operator -( + Matrix23 left, + Matrix23 right ) { - return new Matrix23( - left._mat.colum0 - right._mat.colum0, - left._mat.colum1 - right._mat.colum1, - left._mat.colum2 - right._mat.colum2 ); + Matrix23 ret = new Matrix23(); + InternalIO.Intrinsic.sub_mat_3( &left._mat, &right._mat, + &ret._mat ); + return ret; } [MethodImpl( MethodImplOptions.AggressiveInlining )] @@ -189,10 +191,13 @@ namespace StgSharp.Math } [MethodImpl( MethodImplOptions.AggressiveInlining )] - public static unsafe Matrix23 operator +( Matrix23 left, Matrix23 right ) + public static unsafe Matrix23 operator +( + Matrix23 left, + Matrix23 right ) { Matrix23 ret = new Matrix23(); - InternalIO.Intrinsic.add_mat_3(&left._mat, &right._mat, &ret._mat); + InternalIO.Intrinsic.add_mat_3( &left._mat, &right._mat, + &ret._mat ); return ret; } diff --git a/StgSharp.Common/Math/Linear/Matrix24.cs b/StgSharp.Common/Math/Linear/Matrix24.cs index d03d80e2..4c29c648 100644 --- a/StgSharp.Common/Math/Linear/Matrix24.cs +++ b/StgSharp.Common/Math/Linear/Matrix24.cs @@ -38,11 +38,12 @@ using System.Runtime.InteropServices; namespace StgSharp.Math { [StructLayout( - LayoutKind.Explicit, - Size = ( ( 4 + 2 ) * 4 * sizeof( float ) ) + sizeof( bool ), - Pack = 16 )] + LayoutKind.Explicit, + Size = ( ( 4 + 2 ) * 4 * sizeof( float ) ) + sizeof( bool ), + Pack = 16 )] public struct Matrix24 : IMat { + [FieldOffset( 6 * 4 * sizeof( float ) )] internal bool isTransposed; [FieldOffset( 4 * 4 * sizeof( float ) )] internal ColumnSet2 transpose; @@ -53,15 +54,9 @@ namespace StgSharp.Math [FieldOffset( 32 )] public Vec2 Colum2; [FieldOffset( 48 )] public Vec2 Colum3; - public Matrix24() - { - Unsafe.SkipInit(out this); - isTransposed = false; - } - internal Matrix24( Vector4 c0, Vector4 c1, Vector4 c2, Vector4 c3 ) { - Unsafe.SkipInit(out this); + Unsafe.SkipInit( out this ); isTransposed = false; mat.colum0 = c0; mat.colum1 = c1; @@ -69,17 +64,23 @@ namespace StgSharp.Math mat.colum3 = c3; } - public Matrix24( - float a00, - float a01, - float a02, - float a03, - float a10, - float a11, - float a12, - float a13 ) + public Matrix24() { - Unsafe.SkipInit(out this); + Unsafe.SkipInit( out this ); + isTransposed = false; + } + + public Matrix24( + float a00, + float a01, + float a02, + float a03, + float a10, + float a11, + float a12, + float a13 ) + { + Unsafe.SkipInit( out this ); isTransposed = false; mat.colum0 = new Vector4( a00, a10, 0, 0 ); mat.colum1 = new Vector4( a01, a11, 0, 0 ); @@ -141,13 +142,13 @@ namespace StgSharp.Math } [MethodImpl( MethodImplOptions.AggressiveInlining )] - public static Matrix24 operator -( Matrix24 left, Matrix24 right ) + public static unsafe Matrix24 operator -( + Matrix24 left, + Matrix24 right ) { - return new Matrix24( - left.mat.colum0 - right.mat.colum0, - left.mat.colum1 - right.mat.colum1, - left.mat.colum2 - right.mat.colum2, - left.mat.colum3 - right.mat.colum3 ); + Matrix24 ret = new Matrix24(); + InternalIO.Intrinsic.sub_mat_4( &left.mat, &right.mat, &ret.mat ); + return ret; } [MethodImpl( MethodImplOptions.AggressiveInlining )] @@ -209,10 +210,12 @@ namespace StgSharp.Math } [MethodImpl( MethodImplOptions.AggressiveInlining )] - public static unsafe Matrix24 operator +( Matrix24 left, Matrix24 right ) + public static unsafe Matrix24 operator +( + Matrix24 left, + Matrix24 right ) { Matrix24 ret = new Matrix24(); - InternalIO.Intrinsic.add_mat_4(&left.mat,&right.mat,&ret.mat); + InternalIO.Intrinsic.add_mat_4( &left.mat, &right.mat, &ret.mat ); return ret; } diff --git a/StgSharp.Common/Math/Linear/Matrix32.cs b/StgSharp.Common/Math/Linear/Matrix32.cs index b07ce0a7..460a7fdf 100644 --- a/StgSharp.Common/Math/Linear/Matrix32.cs +++ b/StgSharp.Common/Math/Linear/Matrix32.cs @@ -38,9 +38,9 @@ using System.Runtime.InteropServices; namespace StgSharp.Math { [StructLayout( - LayoutKind.Explicit, - Size = ( 5 * 4 * sizeof( float ) ) + sizeof( bool ), - Pack = 16 )] + LayoutKind.Explicit, + Size = ( 5 * 4 * sizeof( float ) ) + sizeof( bool ), + Pack = 16 )] public struct Matrix32 : IMat { @@ -52,29 +52,29 @@ namespace StgSharp.Math [FieldOffset( 0 )] internal Vec3 colum0; [FieldOffset( 4 * 4 )] internal Vec3 colum1; - public Matrix32() - { - Unsafe.SkipInit(out this); - isTransposed = false; - } - internal Matrix32( Vector4 c0, Vector4 c1 ) { - Unsafe.SkipInit(out this); + Unsafe.SkipInit( out this ); isTransposed = false; mat.colum0 = c0; mat.colum1 = c1; } - public unsafe Matrix32( - float a00, - float a01, - float a10, - float a11, - float a20, - float a21 ) + public Matrix32() { - Unsafe.SkipInit(out this); + Unsafe.SkipInit( out this ); + isTransposed = false; + } + + public unsafe Matrix32( + float a00, + float a01, + float a10, + float a11, + float a20, + float a21 ) + { + Unsafe.SkipInit( out this ); isTransposed = false; mat.colum0 = new Vector4( a00, a10, a20, 0 ); mat.colum1 = new Vector4( a01, a11, a21, 0 ); @@ -209,10 +209,12 @@ namespace StgSharp.Math } [MethodImpl( MethodImplOptions.AggressiveInlining )] - public static unsafe Matrix32 operator +( Matrix32 left, Matrix32 right ) + public static unsafe Matrix32 operator +( + Matrix32 left, + Matrix32 right ) { Matrix32 ret = new Matrix32(); - InternalIO.Intrinsic.add_mat_2(&left.mat, &right.mat, &ret.mat); + InternalIO.Intrinsic.add_mat_2( &left.mat, &right.mat, &ret.mat ); return ret; } diff --git a/StgSharp.Common/Math/Linear/Matrix33.cs b/StgSharp.Common/Math/Linear/Matrix33.cs index 5d89b5c6..b7bb3f50 100644 --- a/StgSharp.Common/Math/Linear/Matrix33.cs +++ b/StgSharp.Common/Math/Linear/Matrix33.cs @@ -38,9 +38,9 @@ using System.Runtime.InteropServices; namespace StgSharp.Math { [StructLayout( - LayoutKind.Explicit, - Size = ( 6 * 4 * sizeof( float ) ) + sizeof( bool ), - Pack = 16 )] + LayoutKind.Explicit, + Size = ( 6 * 4 * sizeof( float ) ) + sizeof( bool ), + Pack = 16 )] public struct Matrix33 : IMat { @@ -52,33 +52,33 @@ namespace StgSharp.Math [FieldOffset( 1 * 4 * sizeof( float ) )] public Vec3 Colum1; [FieldOffset( 2 * 4 * sizeof( float ) )] public Vec3 Colum2; - public Matrix33() - { - Unsafe.SkipInit(out this); - isTransposed = false; - } - internal Matrix33( Vector4 c0, Vector4 c1, Vector4 c2 ) { - Unsafe.SkipInit(out this); + Unsafe.SkipInit( out this ); isTransposed = false; mat.colum0 = c0; mat.colum1 = c1; mat.colum2 = c2; } - public Matrix33( - float a00, - float a01, - float a02, - float a10, - float a11, - float a12, - float a20, - float a21, - float a22 ) + public Matrix33() { - Unsafe.SkipInit(out this); + Unsafe.SkipInit( out this ); + isTransposed = false; + } + + public Matrix33( + float a00, + float a01, + float a02, + float a10, + float a11, + float a12, + float a20, + float a21, + float a22 ) + { + Unsafe.SkipInit( out this ); isTransposed = false; mat.colum0 = new Vector4( a00, a10, a20, 0 ); mat.colum1 = new Vector4( a01, a11, a21, 0 ); @@ -140,12 +140,13 @@ namespace StgSharp.Math } [MethodImpl( MethodImplOptions.AggressiveInlining )] - public static Matrix33 operator -( Matrix33 left, Matrix33 right ) + public static unsafe Matrix33 operator -( + Matrix33 left, + Matrix33 right ) { - return new Matrix33( - left.mat.colum0 - right.mat.colum0, - left.mat.colum1 - right.mat.colum1, - left.mat.colum2 + right.mat.colum2 ); + Matrix33 ret = new Matrix33(); + InternalIO.Intrinsic.sub_mat_3( &left.mat, &right.mat, &ret.mat ); + return ret; } [MethodImpl( MethodImplOptions.AggressiveInlining )] @@ -229,10 +230,12 @@ namespace StgSharp.Math } [MethodImpl( MethodImplOptions.AggressiveInlining )] - public static unsafe Matrix33 operator +( Matrix33 left, Matrix33 right ) + public static unsafe Matrix33 operator +( + Matrix33 left, + Matrix33 right ) { Matrix33 ret = new Matrix33(); - InternalIO.Intrinsic.add_mat_3(&left.mat, &right.mat, &ret.mat); + InternalIO.Intrinsic.add_mat_3( &left.mat, &right.mat, &ret.mat ); return ret; } diff --git a/StgSharp.Common/Math/Linear/Matrix34.cs b/StgSharp.Common/Math/Linear/Matrix34.cs index a521e02e..7d5dcaf3 100644 --- a/StgSharp.Common/Math/Linear/Matrix34.cs +++ b/StgSharp.Common/Math/Linear/Matrix34.cs @@ -39,9 +39,9 @@ using System.Runtime.InteropServices; namespace StgSharp.Math { [StructLayout( - LayoutKind.Explicit, - Size = ( 7 * 4 * sizeof( float ) ) + sizeof( bool ), - Pack = 16 )] + LayoutKind.Explicit, + Size = ( 7 * 4 * sizeof( float ) ) + sizeof( bool ), + Pack = 16 )] public struct Matrix34 : IMat { @@ -55,12 +55,6 @@ namespace StgSharp.Math [FieldOffset( 2 * 4 * sizeof( float ) )] public Vec3 Colum2; [FieldOffset( 3 * 4 * sizeof( float ) )] public Vec3 Colum3; - public Matrix34() - { - Unsafe.SkipInit(out this); - isTransposed = false; - } - internal Matrix34( ColumnSet4 mat ) { Unsafe.SkipInit( out this ); @@ -70,7 +64,7 @@ namespace StgSharp.Math internal Matrix34( Vector4 c0, Vector4 c1, Vector4 c2, Vector4 c3 ) { - Unsafe.SkipInit(out this); + Unsafe.SkipInit( out this ); isTransposed = false; mat.colum0 = c0; mat.colum1 = c1; @@ -78,21 +72,27 @@ namespace StgSharp.Math mat.colum3 = c3; } - public Matrix34( - float a00, - float a01, - float a02, - float a03, - float a10, - float a11, - float a12, - float a13, - float a20, - float a21, - float a22, - float a23 ) + public Matrix34() { - Unsafe.SkipInit(out this); + Unsafe.SkipInit( out this ); + isTransposed = false; + } + + public Matrix34( + float a00, + float a01, + float a02, + float a03, + float a10, + float a11, + float a12, + float a13, + float a20, + float a21, + float a22, + float a23 ) + { + Unsafe.SkipInit( out this ); isTransposed = false; mat.colum0 = new Vector4( a00, a10, a20, 0 ); mat.colum0 = new Vector4( a01, a11, a21, 0 ); @@ -147,13 +147,13 @@ namespace StgSharp.Math } [MethodImpl( MethodImplOptions.AggressiveInlining )] - public static Matrix34 operator -( Matrix34 left, Matrix34 right ) + public static unsafe Matrix34 operator -( + Matrix34 left, + Matrix34 right ) { - return new Matrix34( - left.mat.colum0 - right.mat.colum0, - left.mat.colum1 - right.mat.colum1, - left.mat.colum2 - right.mat.colum2, - left.mat.colum3 - right.mat.colum3 ); + Matrix34 ret = new Matrix34(); + InternalIO.Intrinsic.sub_mat_4( &left.mat, &right.mat, &ret.mat ); + return ret; } [MethodImpl( MethodImplOptions.AggressiveInlining )] @@ -227,12 +227,13 @@ namespace StgSharp.Math } [MethodImpl( MethodImplOptions.AggressiveInlining )] - public static unsafe Matrix34 operator +( Matrix34 left, Matrix34 right ) + public static unsafe Matrix34 operator +( + Matrix34 left, + Matrix34 right ) { Matrix34 ret = new Matrix34(); - InternalIO.Intrinsic.add_mat_4(&left.mat,&right.mat,&ret.mat); + InternalIO.Intrinsic.add_mat_4( &left.mat, &right.mat, &ret.mat ); return ret; - } } diff --git a/StgSharp.Common/Math/Linear/Matrix42.cs b/StgSharp.Common/Math/Linear/Matrix42.cs index c4a359b0..fc580a3c 100644 --- a/StgSharp.Common/Math/Linear/Matrix42.cs +++ b/StgSharp.Common/Math/Linear/Matrix42.cs @@ -38,9 +38,9 @@ using System.Runtime.InteropServices; namespace StgSharp.Math { [StructLayout( - LayoutKind.Explicit, - Size = ( ( 16 + 8 ) * sizeof( float ) ) + sizeof( bool ), - Pack = 16 )] + LayoutKind.Explicit, + Size = ( ( 16 + 8 ) * sizeof( float ) ) + sizeof( bool ), + Pack = 16 )] public struct Matrix42 : IMat { @@ -49,38 +49,38 @@ namespace StgSharp.Math [FieldOffset( 0 )] internal ColumnSet2 mat; [FieldOffset( 8 * sizeof( float ) )] internal ColumnSet4 transpose; - public Matrix42() - { - Unsafe.SkipInit(out this); - isTransposed = false; - } - internal Matrix42( ColumnSet2 mat ) { - Unsafe.SkipInit(out this); + Unsafe.SkipInit( out this ); isTransposed = false; this.mat = mat; } internal Matrix42( Vector4 c0, Vector4 c1 ) { - Unsafe.SkipInit(out this); - isTransposed= false; + Unsafe.SkipInit( out this ); + isTransposed = false; mat.colum0 = c0; mat.colum1 = c1; } - public Matrix42( - float a00, - float a01, - float a10, - float a11, - float a20, - float a21, - float a30, - float a31 ) + public Matrix42() { - Unsafe.SkipInit(out this); + Unsafe.SkipInit( out this ); + isTransposed = false; + } + + public Matrix42( + float a00, + float a01, + float a10, + float a11, + float a20, + float a21, + float a30, + float a31 ) + { + Unsafe.SkipInit( out this ); isTransposed = false; mat.colum0 = new Vector4( a00, a10, a20, a30 ); mat.colum1 = new Vector4( a01, a11, a21, a31 ); @@ -141,12 +141,12 @@ namespace StgSharp.Math [MethodImpl( MethodImplOptions.AggressiveInlining )] public static unsafe Matrix42 operator -( - Matrix42 left, - Matrix42 right ) + Matrix42 left, + Matrix42 right ) { - return new Matrix42( - left.mat.colum0 - right.mat.colum0, - left.mat.colum0 - right.mat.colum0 ); + Matrix42 ret = new Matrix42(); + InternalIO.Intrinsic.sub_mat_2( &left.mat, &right.mat, &ret.mat ); + return ret; } [MethodImpl( MethodImplOptions.AggressiveInlining )] @@ -231,12 +231,12 @@ namespace StgSharp.Math [MethodImpl( MethodImplOptions.AggressiveInlining )] public static unsafe Matrix42 operator +( - Matrix42 left, - Matrix42 right ) + Matrix42 left, + Matrix42 right ) { - return new Matrix42( - left.mat.colum0 + right.mat.colum0, - left.mat.colum0 + right.mat.colum0 ); + Matrix42 ret = new Matrix42(); + InternalIO.Intrinsic.add_mat_2( &left.mat, &right.mat, &ret.mat ); + return ret; } } diff --git a/StgSharp.Script/Common/Token.cs b/StgSharp.Script/Common/Token.cs index 94161eb2..06b1b7e2 100644 --- a/StgSharp.Script/Common/Token.cs +++ b/StgSharp.Script/Common/Token.cs @@ -31,6 +31,7 @@ using System; using System.Collections.Generic; using System.Linq; +using System.Runtime.CompilerServices; using System.Text; using System.Threading.Tasks; @@ -60,6 +61,12 @@ namespace StgSharp.Script public static Token Empty => EmptyToken; + [MethodImpl( MethodImplOptions.AggressiveInlining )] + public Token ReLocate( int line, int column ) + { + return new Token( Value, line, column, Flag ); + } + } public enum TokenFlag : int diff --git a/StgSharp.Script/Express/CompileEnv/BuiltinType.cs b/StgSharp.Script/Express/CompileEnv/BuiltinType.cs index dc529652..da90dd1c 100644 --- a/StgSharp.Script/Express/CompileEnv/BuiltinType.cs +++ b/StgSharp.Script/Express/CompileEnv/BuiltinType.cs @@ -51,5 +51,11 @@ namespace StgSharp.Script.Express private set; } + public static ExpTypeSource ExpBool + { + get; + private set; + } + } } diff --git a/StgSharp.Script/Express/CompileEnv/ExpCompile.cs b/StgSharp.Script/Express/CompileEnv/ExpCompile.cs index b3f75002..31d59238 100644 --- a/StgSharp.Script/Express/CompileEnv/ExpCompile.cs +++ b/StgSharp.Script/Express/CompileEnv/ExpCompile.cs @@ -109,6 +109,11 @@ namespace StgSharp.Script.Express PoolString( KeyWord.Real ), out ExpTypeSource? _expReal ); ExpReal = _expReal; + ExpSchema_Nitload.Only + .TryGetType( + PoolString( KeyWord.Bool ), + out ExpTypeSource? _expBool ); + ExpBool = _expBool; } public static bool LetterIsOperator( string str ) diff --git a/StgSharp.Script/Express/CompileEnv/KeyWord.cs b/StgSharp.Script/Express/CompileEnv/KeyWord.cs index aa79bacf..684f7444 100644 --- a/StgSharp.Script/Express/CompileEnv/KeyWord.cs +++ b/StgSharp.Script/Express/CompileEnv/KeyWord.cs @@ -72,6 +72,7 @@ namespace StgSharp.Script.Express MUL = "*", DIV = "/", NOT = "NOT", + NotEqual = "<>", Assignment = ":=", Equal = "=", Mod = "MOD", diff --git a/StgSharp.Script/Express/ExpAstNode/ExpBinaryOperatorNode.cs b/StgSharp.Script/Express/ExpAstNode/ExpBinaryOperatorNode.cs index 794b4ee7..fc43500d 100644 --- a/StgSharp.Script/Express/ExpAstNode/ExpBinaryOperatorNode.cs +++ b/StgSharp.Script/Express/ExpAstNode/ExpBinaryOperatorNode.cs @@ -112,6 +112,41 @@ namespace StgSharp.Script.Express }; } + public static ExpBinaryOperatorNode EqualTo( + Token source, + ExpNode left, + ExpNode right ) + { + if( left.EqualityTypeConvert != right.EqualityTypeConvert ) { + throw new ExpInvalidTypeException( + left.EqualityTypeConvert.Name, + right.EqualityTypeConvert.Name ); + } + return new ExpBinaryOperatorNode( source ) + { + _returnType = ExpCompile.ExpBool, + _nodeFlag = ExpNodeFlag.BuiltinType_Boolean | ExpNodeFlag.Operator_Binary, + CodeConvertTemplate = "{0} == {1}", + }; + } + + public static ExpBinaryOperatorNode GreaterThan( + Token source, + ExpNode left, + ExpNode right ) + { + if( !left.IsNumber && !right.IsNumber ) { + throw new ExpInvalidTypeException( + "Number", left.EqualityTypeConvert.Name ); + } + return new ExpBinaryOperatorNode( source ) + { + _returnType = ExpCompile.ExpBool, + _nodeFlag = ExpNodeFlag.BuiltinType_Boolean | ExpNodeFlag.Operator_Binary, + CodeConvertTemplate = "{0} > {1}", + }; + } + public static ExpBinaryOperatorNode Mul( Token source, ExpNode left, @@ -132,6 +167,41 @@ namespace StgSharp.Script.Express }; } + public static ExpBinaryOperatorNode NotEqualTo( + Token source, + ExpNode left, + ExpNode right ) + { + if( left.EqualityTypeConvert != right.EqualityTypeConvert ) { + throw new ExpInvalidTypeException( + left.EqualityTypeConvert.Name, + right.EqualityTypeConvert.Name ); + } + return new ExpBinaryOperatorNode( source ) + { + _returnType = ExpCompile.ExpBool, + _nodeFlag = ExpNodeFlag.BuiltinType_Boolean | ExpNodeFlag.Operator_Binary, + CodeConvertTemplate = "{0} != {1}", + }; + } + + public static ExpBinaryOperatorNode SmallerThan( + Token source, + ExpNode left, + ExpNode right ) + { + if( !left.IsNumber && !right.IsNumber ) { + throw new ExpInvalidTypeException( + "Number", left.EqualityTypeConvert.Name ); + } + return new ExpBinaryOperatorNode( source ) + { + _returnType = ExpCompile.ExpBool, + _nodeFlag = ExpNodeFlag.BuiltinType_Boolean | ExpNodeFlag.Operator_Binary, + CodeConvertTemplate = "{0} < {1}", + }; + } + public static ExpBinaryOperatorNode Sub( Token source, ExpNode left, diff --git a/StgSharp.Script/Express/ExpAstNode/ExpLiteralNode.cs b/StgSharp.Script/Express/ExpAstNode/ExpLiteralNode.cs new file mode 100644 index 00000000..88c0dadd --- /dev/null +++ b/StgSharp.Script/Express/ExpAstNode/ExpLiteralNode.cs @@ -0,0 +1,157 @@ +//----------------------------------------------------------------------- +//----------------------------------------------------------------------- +// file="ExpLiteralGenericNode.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 StgSharp.Data; + +using System; +using System.Collections; +using System.Collections.Generic; +using System.Text; + +namespace StgSharp.Script.Express +{ + public class ExpIntNode : ExpElementInstanceBase + { + + private int _value; + + public ExpIntNode( Token source, int value ) + : base( source ) + { + _value = value; + _nodeFlag = ExpNodeFlag.BuiltinType_Int | ExpNodeFlag.Element_Type; + } + + public override IExpElementSource EqualityTypeConvert => ExpSchema.BuiltinSchema + .TryGetType( + ExpCompile.KeyWord.Int, out ExpTypeSource? type ) ? + type : throw new ExpCompileNotInitializedException(); + + public int Value => _value; + + public override string TypeName => ExpCompile.KeyWord.Int; + + } + + public class ExpStringNode : ExpElementInstanceBase + { + + private readonly string _value; + + public ExpStringNode( Token source, string value ) + : base( source ) + { + _value = value; + _nodeFlag = ExpNodeFlag.BuiltinType_String | ExpNodeFlag.Element_Type; + } + + public override IExpElementSource EqualityTypeConvert => ExpSchema.BuiltinSchema + .TryGetType( + ExpCompile.KeyWord.String, + out ExpTypeSource? type ) ? + type : throw new ExpCompileNotInitializedException(); + + public override string TypeName => EqualityTypeConvert.Name; + + public string Value => _value; + + } + + public class ExpBoolNode : ExpElementInstanceBase + { + + private readonly bool _value; + + public ExpBoolNode( Token source, bool value ) + : base( source ) + { + _value = value; + _nodeFlag = ExpNodeFlag.BuiltinType_Boolean | ExpNodeFlag.Element_Type; + } + + public bool Value => _value; + + public override IExpElementSource EqualityTypeConvert => ExpSchema.BuiltinSchema + .TryGetType( + ExpCompile.KeyWord.Bool, out ExpTypeSource? type ) ? + type : throw new ExpCompileNotInitializedException(); + + public override string TypeName => EqualityTypeConvert.Name; + + } + + public class ExpRealNumberNode : ExpElementInstanceBase + { + + private readonly float _value; + + public ExpRealNumberNode( Token source, float value ) + : base( source ) + { + _value = value; + _nodeFlag = ExpNodeFlag.BuiltinType_Real | ExpNodeFlag.Element_Type; + } + + public float Value => _value; + + public override IExpElementSource EqualityTypeConvert => ExpSchema.BuiltinSchema + .TryGetType( + ExpCompile.KeyWord.String, + out ExpTypeSource? type ) ? + type : throw new ExpCompileNotInitializedException(); + + public override string TypeName => EqualityTypeConvert.Name; + + } + + public class ExpLogicValueNode : ExpElementInstanceBase + { + + private readonly ExpLogic _value; + + public ExpLogicValueNode( Token source, ExpLogic value ) + : base( source ) + { + _value = value; + _nodeFlag = ExpNodeFlag.BuiltinType_Logic | ExpNodeFlag.Element_Type; + } + + public ExpLogic Value => _value; + + public override IExpElementSource EqualityTypeConvert => ExpSchema.BuiltinSchema + .TryGetType( + ExpCompile.KeyWord.Logic, + out ExpTypeSource? type ) ? + type : throw new ExpCompileNotInitializedException(); + + public override string TypeName => EqualityTypeConvert.Name; + + } +} diff --git a/StgSharp.Script/Express/ExpAstNode/ExpRepeatNode.cs b/StgSharp.Script/Express/ExpAstNode/ExpRepeatNode.cs index 38c41b24..f95a616f 100644 --- a/StgSharp.Script/Express/ExpAstNode/ExpRepeatNode.cs +++ b/StgSharp.Script/Express/ExpAstNode/ExpRepeatNode.cs @@ -62,14 +62,14 @@ namespace StgSharp.Script.Express if( increment == null ) { switch( ( ExpNodeFlag )variable.NodeFlag | ExpNodeFlag.BuiltinType_Any ) { case ExpNodeFlag.BuiltinType_Real: - increment = new ExpLiteralGenericNode( + increment = new ExpRealNumberNode( new Token( ExpCompile.PoolString( "1.0f" ), source.Line, -1, TokenFlag.Number ), 1.0f ); break; case ExpNodeFlag.BuiltinType_Int: - increment = new ExpLiteralGenericNode( + increment = new ExpIntNode( new Token( ExpCompile.PoolString( "1" ), source.Line, -1, TokenFlag.Number ), diff --git a/StgSharp.Script/Express/ExpNodeGenerator.Operator.cs b/StgSharp.Script/Express/ExpNodeGenerator.Operator.cs index de66f4a9..3a57cd34 100644 --- a/StgSharp.Script/Express/ExpNodeGenerator.Operator.cs +++ b/StgSharp.Script/Express/ExpNodeGenerator.Operator.cs @@ -65,6 +65,13 @@ namespace StgSharp.Script.Express case ExpCompile.KeyWord.DIV: node = ExpBinaryOperatorNode.Div( t, left, right ); return true; + case ExpCompile.KeyWord.Equal: + node = ExpBinaryOperatorNode.EqualTo( t, left, right ); + return true; + case ExpCompile.KeyWord.NotEqual: + node = ExpBinaryOperatorNode.NotEqualTo( t, left, right ); + return true; + default: node = ExpNode.Empty; return false; diff --git a/StgSharp.Script/Express/ExpNodeGenerator.cs b/StgSharp.Script/Express/ExpNodeGenerator.cs index 6095f250..8f2dd3f5 100644 --- a/StgSharp.Script/Express/ExpNodeGenerator.cs +++ b/StgSharp.Script/Express/ExpNodeGenerator.cs @@ -76,17 +76,25 @@ namespace StgSharp.Script.Express } _cache.PushOperand( expToken ); break; - case TokenFlag.Number or TokenFlag.String or TokenFlag.Member: + case TokenFlag.Number or TokenFlag.String: _cache.PushOperand( expToken ); break; + case TokenFlag.Member: + if( _context.TryGetFunction( expToken.Value, out _ ) ) { + _cache.PushOperator( expToken ); + } else { } + break; case TokenFlag.Separator_Single: //a , ; found // if operator stack is not empty, convert all operators to node until meet a same separator // or OperandAheadOfSeparator property is less than certain value break; case TokenFlag.Separator_Left: //a ( [ { found + // check if the last token is a function name, loop block or branch + // then increase depth _cache.PushOperator( expToken ); break; case TokenFlag.Separator_Right: //a } ] ) found + //Close current depth and cache call node in this depth as a partial AST break; case TokenFlag.Index_Left: // a [ found break; diff --git a/StgSharp.Script/Express/ExpSchemaSource.Compile.cs b/StgSharp.Script/Express/ExpSchemaSource.Compile.cs new file mode 100644 index 00000000..bbb4549f --- /dev/null +++ b/StgSharp.Script/Express/ExpSchemaSource.Compile.cs @@ -0,0 +1,72 @@ +//----------------------------------------------------------------------- +//----------------------------------------------------------------------- +// file="ExpSchemaSource.Compile.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.Text; +using System.Threading.Tasks; + +namespace StgSharp.Script.Express +{ + public enum ExpressCompileOption + { + + Default = 0, + Translate = 1, + Compile = 2, + + } + + public partial class ExpSchemaSource + { + + public ExpSchema Compile( ExpressCompileOption option ) + { + switch( option ) { + case ExpressCompileOption.Default: + return Compile_Translate( option ); + case ExpressCompileOption.Translate: + return Compile_Translate( option ); + case ExpressCompileOption.Compile: + throw new NotImplementedException(); + default: + throw new ArgumentException(); + } + } + + internal GeneratedExpSchema Compile_Translate( + ExpressCompileOption option ) + { + throw new NotImplementedException(); + } + + } +} 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 5cd18088..0e41da8d 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+6f494f25eff44526a1e002d5ebeab8cf7b86a51d")] +[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+16b813646d8a2326551f05c69f727a292a719222")] [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 9766ff42..45061ece 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/6f494f25eff44526a1e002d5ebeab8cf7b86a51d/*"}} \ No newline at end of file +{"documents":{"D:\\NitloadIndustry\\研究项目\\1-Flagship\\TH2020\\ProjectFile\\内核源代码\\*":"https://raw.githubusercontent.com/Nitload-NSI/CCD_Github/16b813646d8a2326551f05c69f727a292a719222/*"}} \ No newline at end of file diff --git a/StgSharpDebug/Program.cs b/StgSharpDebug/Program.cs index 3622bb12..b0b3bd5d 100644 --- a/StgSharpDebug/Program.cs +++ b/StgSharpDebug/Program.cs @@ -59,45 +59,15 @@ namespace StgSharp try { StgSharp.Init(); - /* + /**/ ExpCompile.InitCompile(); ExpFileSource reader = new ExpFileSource( testExpPath ); ExpSchemaSource schemaSource = new ExpSchemaSource(); schemaSource.ReadSchema( reader ); - ScriptSourceTransmitter st = new ScriptSourceTransmitter( - "end", 0 ); - for( int i = 0; i < 10; i++ ) { - string str = $"rawCode () (\"\") {i}"; - Console.WriteLine( str ); - st.WriteLine( str ); - } - for( int i = 0; i < 10; i++ ) { - string str = $"Code{i} {new string(' ', i + 1)}-- Comment{i}"; - Console.WriteLine( str ); - st.WriteLine( str ); - } - st.WriteLine( "CodeBef (* comment" ); - st.WriteLine( $"comment *) codeAft" ); - Console.WriteLine( "CodeBef (* comment_" ); - Console.WriteLine( $"_comment *) codeAft" ); - for( int i = 0; i < 10; i++ ) { - string str = $" Code{i} (* (* Comment{i} *) *) Code{i}"; - Console.WriteLine( str ); - st.WriteLine( str ); - } - st.WriteLine( "end" ); - ExpSourceReader sr = new ExpSourceReader( st ); - int count = 0; - while( !sr.IsEmpty ) { - count++; - Token str = sr.ReadToken(); - Console.WriteLine( - $"{count}\t{str.Flag}\t\t{str.Value.ToString()}" ); - } - IScriptSourceProvider slice = st.Slice( 5, 2 ); - /**/ + /**/ + /* StgSharp.InitGL( 4, 6 ); StgSharp.GlobalSetting.VSyncActivated = false; @@ -126,8 +96,8 @@ namespace StgSharp return; } - catch( Exception ) { - throw; + catch( Exception ex ) { + Console.WriteLine( ex.Message ); /* StgSharp.WriteLog($"{ex}", LogType.Error); if( true ) { }