daily update on 20250220 by nitload youmu, building AST generator, correct type naming

This commit is contained in:
Nitload
2025-02-21 08:11:26 +08:00
parent ccef0de6f6
commit 83bde12d22
98 changed files with 4182 additions and 1855 deletions
+8
View File
@@ -0,0 +1,8 @@
"args": [
"--target=x86_64-pc-windows-gnu", // 指定目标为GNU环境,避免MSVC模拟
"-fms-compatibility-version=0", // 禁用MSVC兼容性扩展
"-D_MSC_VER=0", // 覆盖_MSC_VER宏为0(可选)
"-ferror-limit=0",
"${file}",
"-o", "${fileDirname}/${fileBasenameNoExtension}.exe"
]
Binary file not shown.
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
Binary file not shown.
+6 -1
View File
@@ -1,3 +1,8 @@
{
"dotnet.defaultSolution": "disable"
"dotnet.defaultSolution": "disable",
"cSpell.words": [
"SSCAPI",
"SSCDECL",
"stbi"
]
}
+1
View File
@@ -0,0 +1 @@
@@ -14,7 +14,7 @@ using System.Reflection;
[assembly: System.Reflection.AssemblyCompanyAttribute("StgSharpTest")]
[assembly: System.Reflection.AssemblyConfigurationAttribute("Debug")]
[assembly: System.Reflection.AssemblyFileVersionAttribute("1.0.0.0")]
[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+4e5a1b0dfb69dd073410d254e2bab596629c4536")]
[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+ccef0de6f686f94da655b0e7d854d0acaf907d04")]
[assembly: System.Reflection.AssemblyProductAttribute("StgSharpTest")]
[assembly: System.Reflection.AssemblyTitleAttribute("StgSharpTest")]
[assembly: System.Reflection.AssemblyVersionAttribute("1.0.0.0")]
@@ -0,0 +1,4 @@
// <autogenerated />
using System;
using System.Reflection;
[assembly: global::System.Runtime.Versioning.TargetFrameworkAttribute(".NETCoreApp,Version=v8.0", FrameworkDisplayName = ".NET 8.0")]
@@ -0,0 +1,22 @@
//------------------------------------------------------------------------------
// <auto-generated>
// This code was generated by a tool.
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------
using System;
using System.Reflection;
[assembly: System.Reflection.AssemblyCompanyAttribute("StgSharp.Generator")]
[assembly: System.Reflection.AssemblyConfigurationAttribute("Debug")]
[assembly: System.Reflection.AssemblyFileVersionAttribute("1.0.0.0")]
[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+ccef0de6f686f94da655b0e7d854d0acaf907d04")]
[assembly: System.Reflection.AssemblyProductAttribute("StgSharp.Generator")]
[assembly: System.Reflection.AssemblyTitleAttribute("StgSharp.Generator")]
[assembly: System.Reflection.AssemblyVersionAttribute("1.0.0.0")]
// 由 MSBuild WriteCodeFragment 类生成。
@@ -14,7 +14,7 @@ using System.Reflection;
[assembly: System.Reflection.AssemblyCompanyAttribute("StgSharp.Generator")]
[assembly: System.Reflection.AssemblyConfigurationAttribute("Debug")]
[assembly: System.Reflection.AssemblyFileVersionAttribute("1.0.0.0")]
[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+ae94c265ae77870ea6498b624b6f71b78fb94e51")]
[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+ccef0de6f686f94da655b0e7d854d0acaf907d04")]
[assembly: System.Reflection.AssemblyProductAttribute("StgSharp.Generator")]
[assembly: System.Reflection.AssemblyTitleAttribute("StgSharp.Generator")]
[assembly: System.Reflection.AssemblyVersionAttribute("1.0.0.0")]
+7 -6
View File
@@ -2,9 +2,10 @@
#include "gl.h"
#include "glfw3.h"
#include <stdio.h>
#include <string.h>
GladGLContext *currentContext;
extern char infolog[512] = { 0 };
extern char infolog[512];
SSCAPI int SSCDECL glCheckShaderStat(GladGLContext *context, uint64_t shaderHandle, int key,
char **logRef)
@@ -30,12 +31,12 @@ SSCAPI GLFWglproc SSCDECL loadGlfuncDefault(char *procName)
{
void *ret = glfwGetProcAddress(procName);
// printf("%llu\n", (uint64_t)ret);
if (ret = NULL) {
*infolog = "Failed to load OpenGL api:";
if (ret == NULL) {
strcpy_s(infolog,30, "Failed to load OpenGL api:");
for (size_t i = 0; i < sizeof(procName); i++) {
infolog[30 + i] = procName[i];
}
printf("%s\n", infolog);
//printf("%s\n", infolog);
}
return (GLFWglproc)ret;
}
@@ -67,8 +68,8 @@ SSCAPI void SSCDECL unloadImageData(Image *out)
free(out->pixelPtr);
}
char *_cdecl readLog()
char *SSCDECL readLog()
{
infolog[511] = '\0';
return &infolog;
return infolog;
}
+1 -1
View File
@@ -1,6 +1,6 @@
#include "StgSharpC.h"
#include "ssc_intrinsic.h"
#include <stdio.h>
#ifdef _MSC_VER
#include <intrin.h>
+4 -5
View File
@@ -1,20 +1,19 @@
#include "StgSharpC.h"
#include "ssc_intrinsic.h"
int index_pair_sse(short const *str, uint32_t target, int length)
{
int index = 0, result = 0, size = length, end = size - 8;
__m128i s_even = { .m128i_u32 = {
__m128i s = {
target,
target,
target,
target,
} };
};
__m128i vec, com;
while (index < end) {
vec = _mm_loadu_epi32(str + index);
com = _mm_cmpeq_epi16(vec, s_even);
com = _mm_cmpeq_epi16(vec, s);
result = _mm_movemask_epi8(com);
if (result) {
for (size_t i = 0; i < 7; i++) {
@@ -29,7 +28,7 @@ int index_pair_sse(short const *str, uint32_t target, int length)
}
index += 1;
vec = _mm_loadu_epi32(str + index);
com = _mm_cmpeq_epi16(vec, s_even);
com = _mm_cmpeq_epi16(vec, s);
result = _mm_movemask_epi8(com);
if (result) {
for (size_t i = 0; i < 7; i++) {
@@ -38,58 +38,26 @@ using System.Text;
namespace StgSharp.Commom.Collections
{
public interface IPoolable
/*
public interface IPoolItem<TSignature>
{
public int ID
{
get;
init;
}
}
public class CacheIndexPool<T> : IEnumerable<T> where T: IPoolable
public class CacheIndexPool<TSignature, TItem> : IEnumerable<TItem>
where TItem: IPoolItem<TSignature>
{
private ConcurrentDictionary<int, T> _cache;
private Func<T> _defaultCreator;
public CacheIndexPool( Func<T> defaultCreator )
{
_cache = new ConcurrentDictionary<int, T>();
_defaultCreator = defaultCreator;
}
public T this[ int index ]
{
get
{
if( _cache.TryGetValue( index, out T? value ) ) {
return value;
}
T newValue = _defaultCreator();
_cache.TryAdd( index, newValue );
return newValue;
}
}
public T CreateObject()
{
T _new = _defaultCreator();
_cache.AddOrUpdate( 1, _new, static( _, origin ) => origin );
throw new NotImplementedException();
return _new;
}
public IEnumerator<T> GetEnumerator()
{
return _cache.Values.GetEnumerator();
}
IEnumerator IEnumerable.GetEnumerator()
{
return GetEnumerator();
}
public CacheIndexPool(
Func<TSignature>
) { }
}
/**/
}
@@ -8,7 +8,6 @@ global using StgSharp.Internal.Intrinsic;
global using StgSharp.Internal.OpenGL;
using System.Diagnostics.CodeAnalysis;
using System.Runtime.InteropServices;
[assembly: SuppressMessage("Design", "CA1008:枚举应具有零值", Justification = "<挂起>", Scope = "type", Target = "~T:StgSharp.Graphics.OpenGL.ShaderStatus")]
[assembly: SuppressMessage("Naming", "CA1715:标识符应具有正确的前缀", Justification = "<挂起>", Scope = "member", Target = "~M:StgSharp.Graphics.OpenGL.ShaderProgram.GetUniform``2(System.String)~StgSharp.Graphics.OpenGL.Uniform{``0,``1}")]
@@ -67,7 +67,7 @@ namespace StgSharp.Graphics.OpenGL
/// <summary>
/// Set _data to current vertex Buffer object
/// </summary>
/// <typeparam _name="T"> Type of bufferData </typeparam>
/// <typeparam _name="TItem"> Type of bufferData </typeparam>
/// <param _name="index"> Index to find certain VBO in this instance </param>
/// <param _name="bufferData"> Data to write in </param>
/// <param _name="usage"> How OpenGL use these _data, defined by <see cref="BufferUsage" /></param>
@@ -84,7 +84,7 @@ namespace StgSharp.Graphics.OpenGL
/// <summary>
/// Set _data to current vertex Buffer object
/// </summary>
/// <typeparam _name="T"> Type of bufferData </typeparam>
/// <typeparam _name="TItem"> Type of bufferData </typeparam>
/// <param _name="index"> Index to find certain VBO in this instance </param>
/// <param _name="bufferArray"> Data to write in </param>
/// <param _name="usage"> How OpenGL use these _data, defined by <see cref="BufferUsage" /></param>
@@ -101,7 +101,7 @@ namespace StgSharp.Graphics.OpenGL
/// <summary>
/// Set _data to current vertex Buffer object
/// </summary>
/// <typeparam _name="T"> Type of bufferData </typeparam>
/// <typeparam _name="TItem"> Type of bufferData </typeparam>
/// <param _name="index"> Index to find certain VBO in this instance </param>
/// <param _name="scalerSpan"> A <see cref="Span{T}" /> of _data to write in </param>
/// <param _name="usage"> How OpenGL use these _data, defined by <see cref="BufferUsage" /></param>
@@ -118,7 +118,7 @@ namespace StgSharp.Graphics.OpenGL
/// <summary>
/// Set _data to current vertex Buffer object
/// </summary>
/// <typeparam _name="T"> Type of bufferData </typeparam>
/// <typeparam _name="TItem"> Type of bufferData </typeparam>
/// <param _name="index"> Index to find certain VBO in this instance </param>
/// <param _name="vectorSpan"> A <see cref="Span{T}" /> of _data to write in </param>
/// <param _name="usage"> How OpenGL use these _data, defined by <see cref="BufferUsage" /></param>
@@ -135,7 +135,7 @@ namespace StgSharp.Graphics.OpenGL
/// <summary>
/// Set _data to current vertex Buffer object
/// </summary>
/// <typeparam _name="T"> Type of bufferData </typeparam>
/// <typeparam _name="TItem"> Type of bufferData </typeparam>
/// <param _name="index"> Index to find certain VBO in this instance </param>
/// <param _name="vectorArray"> A array of _data to write in </param>
/// <param _name="usage"> How OpenGL use these _data, defined by <see cref="BufferUsage" /></param>
@@ -34,6 +34,7 @@ using StgSharp.Internal.OpenGL;
using System;
using System.Collections.Generic;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Text;
@@ -42,12 +43,10 @@ namespace StgSharp.Internal
internal partial class InternalIO
{
[DllImport(
SSC_libName,
EntryPoint = "glCheckShaderStat",
CallingConvention = CallingConvention.Cdecl )]
[LibraryImport( SSC_libName, EntryPoint = "glCheckShaderStat" )]
[UnmanagedCallConv( CallConvs = [typeof( CallConvCdecl )] )]
#pragma warning disable CA5392
internal static extern int glCheckShaderStatus(
internal static partial int glCheckShaderStatus(
ref OpenglContext context,
uint shaderHandle,
int key,
@@ -57,51 +56,42 @@ namespace StgSharp.Internal
#region ssgc api define
[DllImport(
SSC_libName,
EntryPoint = "initGL",
CallingConvention = CallingConvention.Cdecl )]
internal static extern void InternalInitGL(
[LibraryImport( SSC_libName, EntryPoint = "initGL" )]
[UnmanagedCallConv( CallConvs = [typeof( CallConvCdecl )] )]
internal static partial void InternalInitGL(
int majorVersion,
int minorVersion );
[DllImport(
[LibraryImport(
SSC_libName,
EntryPoint = "loadGlfuncDefault",
CallingConvention = CallingConvention.Cdecl,
CharSet = CharSet.Ansi)]
internal static extern IntPtr InternalLoadGlfuncDefault( string name );
StringMarshalling = StringMarshalling.Utf8 )]
[UnmanagedCallConv( CallConvs = [typeof( CallConvCdecl )] )]
internal static partial IntPtr InternalLoadGlfuncDefault( string name );
[DllImport(
SSC_libName,
EntryPoint = "linkShaderProgram",
CallingConvention = CallingConvention.Cdecl )]
internal static extern unsafe uint InternalLinkShaderProgram(
[LibraryImport( SSC_libName, EntryPoint = "linkShaderProgram" )]
[UnmanagedCallConv( CallConvs = [typeof( CallConvCdecl )] )]
internal static unsafe partial uint InternalLinkShaderProgram(
OpenglContext* context,
uint shaderProgram );
[DllImport(
SSC_libName,
EntryPoint = "readLog",
CallingConvention = CallingConvention.Cdecl )]
internal static extern unsafe IntPtr InternalReadSSCLog();
[LibraryImport( SSC_libName, EntryPoint = "readLog" )]
[UnmanagedCallConv( CallConvs = [typeof( CallConvCdecl )] )]
internal static unsafe partial IntPtr InternalReadSSCLog();
[DllImport(
[LibraryImport(
SSC_libName,
EntryPoint = "loadImageData",
CallingConvention = CallingConvention.Cdecl,
CharSet = CharSet.Ansi )]
internal static extern unsafe void InternalLoadImage(
StringMarshalling = StringMarshalling.Utf8 )]
[UnmanagedCallConv( CallConvs = [typeof( CallConvCdecl )] )]
internal static unsafe partial void InternalLoadImage(
string fileName,
ImageInfo* output,
ImageLoader loader );
[DllImport(
SSC_libName,
EntryPoint = "unloadImageData",
CallingConvention = CallingConvention.Cdecl,
CharSet = CharSet.Ansi )]
internal static extern unsafe void InternalUnloadImage(
[LibraryImport( SSC_libName, EntryPoint = "unloadImageData" )]
[UnmanagedCallConv( CallConvs = [typeof( CallConvCdecl )] )]
internal static unsafe partial void InternalUnloadImage(
ImageInfo* output );
#endregion ssgc api define
@@ -94,10 +94,11 @@ namespace StgSharp.Internal
IntPtr procPtr =
#if WINDOWS
IntPtr.Zero;
#elif LINUX
#elif LINUX
#else
#else
IntPtr.Zero;
#endif
return procPtr;
}
@@ -128,8 +129,8 @@ namespace StgSharp.Internal
LogType logType )
{
logSyncSemaphore.Wait();
if( !File.Exists( InternalIO.SS_errorLog ) ) {
FileStream stream = File.Create( InternalIO.SS_errorLog );
if( !File.Exists( SS_errorLog ) ) {
FileStream stream = File.Create( SS_errorLog );
stream.Close();
}
@@ -32,6 +32,7 @@ using StgSharp.Internal.Intrinsic;
using System;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
namespace StgSharp.Internal
@@ -66,11 +67,9 @@ namespace StgSharp.Internal
}
}
[DllImport(
SSC_libName,
CallingConvention = CallingConvention.Cdecl,
EntryPoint = "load_intrinsic_function" )]
private static extern int LoadIntrinsicFunction(
[LibraryImport( SSC_libName, EntryPoint = "load_intrinsic_function" )]
[UnmanagedCallConv( CallConvs = [typeof( CallConvCdecl )] )]
private static partial int LoadIntrinsicFunction(
IntrinsicContext* context );
}
+251 -236
View File
@@ -42,238 +42,242 @@ namespace StgSharp.Internal
#region api call
[DllImport( SSC_libName, EntryPoint = "glfwInit" )]
internal static extern unsafe int glfwInit();
[LibraryImport( SSC_libName, EntryPoint = "glfwInit" )]
internal static unsafe partial int glfwInit();
[DllImport( SSC_libName, EntryPoint = "glfwTerminate" )]
internal static extern unsafe void glfwTerminate();
[LibraryImport( SSC_libName, EntryPoint = "glfwTerminate" )]
internal static unsafe partial void glfwTerminate();
[DllImport( SSC_libName, EntryPoint = "glfwInitHint" )]
internal static extern unsafe void glfwInitHint( int hint, int value );
[LibraryImport( SSC_libName, EntryPoint = "glfwInitHint" )]
internal static unsafe partial void glfwInitHint( int hint, int value );
[DllImport( SSC_libName, EntryPoint = "glfwGetVersion" )]
internal static extern unsafe void glfwGetVersion(
[LibraryImport( SSC_libName, EntryPoint = "glfwGetVersion" )]
internal static unsafe partial void glfwGetVersion(
int* major,
int* minor,
int* rev );
[DllImport( SSC_libName, EntryPoint = "glfwGetVersionString" )]
internal static extern unsafe byte* glfwGetVersionString();
[LibraryImport( SSC_libName, EntryPoint = "glfwGetVersionString" )]
internal static unsafe partial byte* glfwGetVersionString();
[DllImport( SSC_libName, EntryPoint = "glfwGetError" )]
internal static extern unsafe int glfwGetError( byte** description );
[LibraryImport( SSC_libName, EntryPoint = "glfwGetError" )]
internal static unsafe partial int glfwGetError( byte** description );
[DllImport( SSC_libName, EntryPoint = "glfwSetErrorCallback" )]
internal static extern unsafe GLFWerrorfun glfwSetErrorCallback(
[LibraryImport( SSC_libName, EntryPoint = "glfwSetErrorCallback" )]
internal static unsafe partial GLFWerrorfun glfwSetErrorCallback(
GLFWerrorfun callback );
[DllImport( SSC_libName, EntryPoint = "glfwGetMonitors" )]
internal static extern unsafe IntPtr* glfwGetMonitors( int* count );
[LibraryImport( SSC_libName, EntryPoint = "glfwGetMonitors" )]
internal static unsafe partial IntPtr* glfwGetMonitors( int* count );
[DllImport( SSC_libName, EntryPoint = "glfwGetPrimaryMonitor" )]
internal static extern unsafe IntPtr glfwGetPrimaryMonitor();
[LibraryImport( SSC_libName, EntryPoint = "glfwGetPrimaryMonitor" )]
internal static unsafe partial IntPtr glfwGetPrimaryMonitor();
[DllImport( SSC_libName, EntryPoint = "glfwGetMonitorPos" )]
internal static extern unsafe void glfwGetMonitorPos(
[LibraryImport( SSC_libName, EntryPoint = "glfwGetMonitorPos" )]
internal static unsafe partial void glfwGetMonitorPos(
IntPtr monitor,
int* xpos,
int* ypos );
[DllImport( SSC_libName, EntryPoint = "glfwGetMonitorWorkarea" )]
internal static extern unsafe void glfwGetMonitorWorkarea(
[LibraryImport( SSC_libName, EntryPoint = "glfwGetMonitorWorkarea" )]
internal static unsafe partial void glfwGetMonitorWorkarea(
IntPtr monitor,
int* xpos,
int* ypos,
int* width,
int* height );
[DllImport( SSC_libName, EntryPoint = "glfwGetMonitorPhysicalSize" )]
internal static extern unsafe void glfwGetMonitorPhysicalSize(
[LibraryImport( SSC_libName, EntryPoint = "glfwGetMonitorPhysicalSize" )]
internal static unsafe partial void glfwGetMonitorPhysicalSize(
IntPtr monitor,
int* widthMM,
int* heightMM );
[DllImport( SSC_libName, EntryPoint = "glfwGetMonitorContentScale" )]
internal static extern unsafe void glfwGetMonitorContentScale(
[LibraryImport( SSC_libName, EntryPoint = "glfwGetMonitorContentScale" )]
internal static unsafe partial void glfwGetMonitorContentScale(
IntPtr monitor,
float* xscale,
float* yscale );
[DllImport( SSC_libName, EntryPoint = "glfwGetMonitorName" )]
internal static extern unsafe byte* glfwGetMonitorName( IntPtr monitor );
[LibraryImport( SSC_libName, EntryPoint = "glfwGetMonitorName" )]
internal static unsafe partial byte* glfwGetMonitorName(
IntPtr monitor );
[DllImport( SSC_libName, EntryPoint = "glfwSetMonitorUserPointer" )]
internal static extern unsafe void glfwSetMonitorUserPointer(
[LibraryImport( SSC_libName, EntryPoint = "glfwSetMonitorUserPointer" )]
internal static unsafe partial void glfwSetMonitorUserPointer(
IntPtr monitor,
void* pointer );
[DllImport( SSC_libName, EntryPoint = "glfwGetMonitorUserPointer" )]
internal static extern unsafe void* glfwGetMonitorUserPointer(
[LibraryImport( SSC_libName, EntryPoint = "glfwGetMonitorUserPointer" )]
internal static unsafe partial void* glfwGetMonitorUserPointer(
IntPtr monitor );
[DllImport( SSC_libName, EntryPoint = "glfwSetMonitorCallback" )]
internal static extern unsafe GLFWmonitorfun glfwSetMonitorCallback(
[LibraryImport( SSC_libName, EntryPoint = "glfwSetMonitorCallback" )]
internal static unsafe partial GLFWmonitorfun glfwSetMonitorCallback(
GLFWmonitorfun callback );
[DllImport( SSC_libName, EntryPoint = "glfwGetVideoModes" )]
internal static extern unsafe glfwVideomode* glfwGetVideoModes(
[LibraryImport( SSC_libName, EntryPoint = "glfwGetVideoModes" )]
internal static unsafe partial glfwVideomode* glfwGetVideoModes(
IntPtr monitor,
int* count );
[DllImport( SSC_libName, EntryPoint = "glfwGetVideoMode" )]
internal static extern unsafe glfwVideomode* glfwGetVideoMode(
[LibraryImport( SSC_libName, EntryPoint = "glfwGetVideoMode" )]
internal static unsafe partial glfwVideomode* glfwGetVideoMode(
IntPtr monitor );
[DllImport( SSC_libName, EntryPoint = "glfwSetGamma" )]
internal static extern unsafe void glfwSetGamma(
[LibraryImport( SSC_libName, EntryPoint = "glfwSetGamma" )]
internal static unsafe partial void glfwSetGamma(
IntPtr monitor,
float gamma );
[DllImport( SSC_libName, EntryPoint = "glfwGetGammaRamp" )]
internal static extern unsafe glfwGammaramp* glfwGetGammaRamp(
[LibraryImport( SSC_libName, EntryPoint = "glfwGetGammaRamp" )]
internal static unsafe partial glfwGammaramp* glfwGetGammaRamp(
IntPtr monitor );
[DllImport( SSC_libName, EntryPoint = "glfwSetGammaRamp" )]
internal static extern unsafe void glfwSetGammaRamp(
[LibraryImport( SSC_libName, EntryPoint = "glfwSetGammaRamp" )]
internal static unsafe partial void glfwSetGammaRamp(
IntPtr monitor,
glfwGammaramp* ramp );
[DllImport( SSC_libName, EntryPoint = "glfwDefaultWindowHints" )]
internal static extern unsafe void glfwDefaultWindowHints();
[LibraryImport( SSC_libName, EntryPoint = "glfwDefaultWindowHints" )]
internal static unsafe partial void glfwDefaultWindowHints();
[DllImport( SSC_libName, EntryPoint = "glfwWindowHint" )]
internal static extern unsafe void glfwWindowHint( int hint, int value );
[LibraryImport( SSC_libName, EntryPoint = "glfwWindowHint" )]
internal static unsafe partial void glfwWindowHint(
int hint,
int value );
[DllImport( SSC_libName, EntryPoint = "glfwWindowHintString" )]
internal static extern unsafe void glfwWindowHintString(
[LibraryImport( SSC_libName, EntryPoint = "glfwWindowHintString" )]
internal static unsafe partial void glfwWindowHintString(
int hint,
byte* value );
[DllImport( SSC_libName, EntryPoint = "glfwCreateWindow" )]
internal static extern unsafe IntPtr glfwCreateWindow(
[LibraryImport( SSC_libName, EntryPoint = "glfwCreateWindow" )]
internal static unsafe partial IntPtr glfwCreateWindow(
int width,
int height,
byte[] title,
IntPtr monitor,
IntPtr share );
[DllImport( SSC_libName, EntryPoint = "glfwDestroyWindow" )]
internal static extern unsafe void glfwDestroyWindow( IntPtr window );
[LibraryImport( SSC_libName, EntryPoint = "glfwDestroyWindow" )]
internal static unsafe partial void glfwDestroyWindow( IntPtr window );
[DllImport( SSC_libName, EntryPoint = "glfwWindowShouldClose" )]
internal static extern unsafe int glfwWindowShouldClose( IntPtr window );
[LibraryImport( SSC_libName, EntryPoint = "glfwWindowShouldClose" )]
internal static unsafe partial int glfwWindowShouldClose(
IntPtr window );
[DllImport( SSC_libName, EntryPoint = "glfwSetWindowShouldClose" )]
internal static extern unsafe void glfwSetWindowShouldClose(
[LibraryImport( SSC_libName, EntryPoint = "glfwSetWindowShouldClose" )]
internal static unsafe partial void glfwSetWindowShouldClose(
IntPtr window,
int value );
[DllImport( SSC_libName, EntryPoint = "glfwSetWindowTitle" )]
internal static extern unsafe void glfwSetWindowTitle(
[LibraryImport( SSC_libName, EntryPoint = "glfwSetWindowTitle" )]
internal static unsafe partial void glfwSetWindowTitle(
IntPtr window,
byte* title );
[DllImport( SSC_libName, EntryPoint = "glfwSetWindowIcon" )]
internal static extern unsafe void glfwSetWindowIcon(
[LibraryImport( SSC_libName, EntryPoint = "glfwSetWindowIcon" )]
internal static unsafe partial void glfwSetWindowIcon(
IntPtr window,
int count,
GLFWimage* images );
[DllImport( SSC_libName, EntryPoint = "glfwGetWindowPos" )]
internal static extern unsafe void glfwGetWindowPos(
[LibraryImport( SSC_libName, EntryPoint = "glfwGetWindowPos" )]
internal static unsafe partial void glfwGetWindowPos(
IntPtr window,
int* xpos,
int* ypos );
[DllImport( SSC_libName, EntryPoint = "glfwSetWindowPos" )]
internal static extern unsafe void glfwSetWindowPos(
[LibraryImport( SSC_libName, EntryPoint = "glfwSetWindowPos" )]
internal static unsafe partial void glfwSetWindowPos(
IntPtr window,
int xpos,
int ypos );
[DllImport( SSC_libName, EntryPoint = "glfwGetWindowSize" )]
internal static extern unsafe void glfwGetWindowSize(
[LibraryImport( SSC_libName, EntryPoint = "glfwGetWindowSize" )]
internal static unsafe partial void glfwGetWindowSize(
IntPtr window,
int* width,
int* height );
[DllImport( SSC_libName, EntryPoint = "glfwSetWindowSizeLimits" )]
internal static extern unsafe void glfwSetWindowSizeLimits(
[LibraryImport( SSC_libName, EntryPoint = "glfwSetWindowSizeLimits" )]
internal static unsafe partial void glfwSetWindowSizeLimits(
IntPtr window,
int minwidth,
int minheight,
int maxwidth,
int maxheight );
[DllImport( SSC_libName, EntryPoint = "glfwSetWindowAspectRatio" )]
internal static extern unsafe void glfwSetWindowAspectRatio(
[LibraryImport( SSC_libName, EntryPoint = "glfwSetWindowAspectRatio" )]
internal static unsafe partial void glfwSetWindowAspectRatio(
IntPtr window,
int numer,
int denom );
[DllImport( SSC_libName, EntryPoint = "glfwSetWindowSize" )]
internal static extern unsafe void glfwSetWindowSize(
[LibraryImport( SSC_libName, EntryPoint = "glfwSetWindowSize" )]
internal static unsafe partial void glfwSetWindowSize(
IntPtr window,
int width,
int height );
[DllImport( SSC_libName, EntryPoint = "glfwGetFramebufferSize" )]
internal static extern unsafe void glfwGetFramebufferSize(
[LibraryImport( SSC_libName, EntryPoint = "glfwGetFramebufferSize" )]
internal static unsafe partial void glfwGetFramebufferSize(
IntPtr window,
int* width,
int* height );
[DllImport( SSC_libName, EntryPoint = "glfwGetWindowFrameSize" )]
internal static extern unsafe void glfwGetWindowFrameSize(
[LibraryImport( SSC_libName, EntryPoint = "glfwGetWindowFrameSize" )]
internal static unsafe partial void glfwGetWindowFrameSize(
IntPtr window,
int* left,
int* top,
int* right,
int* bottom );
[DllImport( SSC_libName, EntryPoint = "glfwGetWindowContentScale" )]
internal static extern unsafe void glfwGetWindowContentScale(
[LibraryImport( SSC_libName, EntryPoint = "glfwGetWindowContentScale" )]
internal static unsafe partial void glfwGetWindowContentScale(
IntPtr window,
float* xscale,
float* yscale );
[DllImport( SSC_libName, EntryPoint = "glfwGetWindowOpacity" )]
internal static extern unsafe float glfwGetWindowOpacity(
[LibraryImport( SSC_libName, EntryPoint = "glfwGetWindowOpacity" )]
internal static unsafe partial float glfwGetWindowOpacity(
IntPtr window );
[DllImport( SSC_libName, EntryPoint = "glfwSetWindowOpacity" )]
internal static extern unsafe void glfwSetWindowOpacity(
[LibraryImport( SSC_libName, EntryPoint = "glfwSetWindowOpacity" )]
internal static unsafe partial void glfwSetWindowOpacity(
IntPtr window,
float opacity );
[DllImport( SSC_libName, EntryPoint = "glfwIconifyWindow" )]
internal static extern unsafe void glfwIconifyWindow( IntPtr window );
[LibraryImport( SSC_libName, EntryPoint = "glfwIconifyWindow" )]
internal static unsafe partial void glfwIconifyWindow( IntPtr window );
[DllImport( SSC_libName, EntryPoint = "glfwRestoreWindow" )]
internal static extern unsafe void glfwRestoreWindow( IntPtr window );
[LibraryImport( SSC_libName, EntryPoint = "glfwRestoreWindow" )]
internal static unsafe partial void glfwRestoreWindow( IntPtr window );
[DllImport( SSC_libName, EntryPoint = "glfwMaximizeWindow" )]
internal static extern unsafe void glfwMaximizeWindow( IntPtr window );
[LibraryImport( SSC_libName, EntryPoint = "glfwMaximizeWindow" )]
internal static unsafe partial void glfwMaximizeWindow( IntPtr window );
[DllImport( SSC_libName, EntryPoint = "glfwShowWindow" )]
internal static extern unsafe void glfwShowWindow( IntPtr window );
[LibraryImport( SSC_libName, EntryPoint = "glfwShowWindow" )]
internal static unsafe partial void glfwShowWindow( IntPtr window );
[DllImport( SSC_libName, EntryPoint = "glfwHideWindow" )]
internal static extern unsafe void glfwHideWindow( IntPtr window );
[LibraryImport( SSC_libName, EntryPoint = "glfwHideWindow" )]
internal static unsafe partial void glfwHideWindow( IntPtr window );
[DllImport( SSC_libName, EntryPoint = "glfwFocusWindow" )]
internal static extern unsafe void glfwFocusWindow( IntPtr window );
[LibraryImport( SSC_libName, EntryPoint = "glfwFocusWindow" )]
internal static unsafe partial void glfwFocusWindow( IntPtr window );
[DllImport( SSC_libName, EntryPoint = "glfwRequestWindowAttention" )]
internal static extern unsafe void glfwRequestWindowAttention(
[LibraryImport( SSC_libName, EntryPoint = "glfwRequestWindowAttention" )]
internal static unsafe partial void glfwRequestWindowAttention(
IntPtr window );
[DllImport( SSC_libName, EntryPoint = "glfwGetWindowMonitor" )]
internal static extern unsafe IntPtr glfwGetWindowMonitor(
[LibraryImport( SSC_libName, EntryPoint = "glfwGetWindowMonitor" )]
internal static unsafe partial IntPtr glfwGetWindowMonitor(
IntPtr window );
[DllImport( SSC_libName, EntryPoint = "glfwSetWindowMonitor" )]
internal static extern unsafe void glfwSetWindowMonitor(
[LibraryImport( SSC_libName, EntryPoint = "glfwSetWindowMonitor" )]
internal static unsafe partial void glfwSetWindowMonitor(
IntPtr window,
IntPtr monitor,
int xpos,
@@ -282,297 +286,308 @@ namespace StgSharp.Internal
int height,
int refreshRate );
[DllImport( SSC_libName, EntryPoint = "glfwGetWindowAttrib" )]
internal static extern unsafe int glfwGetWindowAttrib(
[LibraryImport( SSC_libName, EntryPoint = "glfwGetWindowAttrib" )]
internal static unsafe partial int glfwGetWindowAttrib(
IntPtr window,
int attrib );
[DllImport( SSC_libName, EntryPoint = "glfwSetWindowAttrib" )]
internal static extern unsafe void glfwSetWindowAttrib(
[LibraryImport( SSC_libName, EntryPoint = "glfwSetWindowAttrib" )]
internal static unsafe partial void glfwSetWindowAttrib(
IntPtr window,
int attrib,
int value );
[DllImport( SSC_libName, EntryPoint = "glfwSetWindowUserPointer" )]
internal static extern unsafe void glfwSetWindowUserPointer(
[LibraryImport( SSC_libName, EntryPoint = "glfwSetWindowUserPointer" )]
internal static unsafe partial void glfwSetWindowUserPointer(
IntPtr window,
void* pointer );
[DllImport( SSC_libName, EntryPoint = "glfwGetWindowUserPointer" )]
internal static extern unsafe void* glfwGetWindowUserPointer(
[LibraryImport( SSC_libName, EntryPoint = "glfwGetWindowUserPointer" )]
internal static unsafe partial void* glfwGetWindowUserPointer(
IntPtr window );
[DllImport( SSC_libName, EntryPoint = "glfwSetWindowPosCallback" )]
internal static extern unsafe GLFWwindowposfun glfwSetWindowPosCallback(
[LibraryImport( SSC_libName, EntryPoint = "glfwSetWindowPosCallback" )]
internal static unsafe partial GLFWwindowposfun glfwSetWindowPosCallback(
IntPtr window,
IntPtr callback );
[DllImport( SSC_libName, EntryPoint = "glfwSetWindowSizeCallback" )]
internal static extern unsafe GLFWwindowsizefun glfwSetWindowSizeCallback(
[LibraryImport( SSC_libName, EntryPoint = "glfwSetWindowSizeCallback" )]
internal static unsafe partial GLFWwindowsizefun glfwSetWindowSizeCallback(
IntPtr window,
GLFWwindowsizefun callback );
[DllImport( SSC_libName, EntryPoint = "glfwSetWindowCloseCallback" )]
internal static extern unsafe GLFWwindowclosefun glfwSetWindowCloseCallback(
[LibraryImport( SSC_libName, EntryPoint = "glfwSetWindowCloseCallback" )]
internal static unsafe partial GLFWwindowclosefun glfwSetWindowCloseCallback(
IntPtr window,
GLFWwindowclosefun callback );
[DllImport( SSC_libName, EntryPoint = "glfwSetWindowRefreshCallback" )]
internal static extern unsafe GLFWwindowrefreshfun glfwSetWindowRefreshCallback(
[LibraryImport(
SSC_libName,
EntryPoint = "glfwSetWindowRefreshCallback" )]
internal static unsafe partial GLFWwindowrefreshfun glfwSetWindowRefreshCallback(
IntPtr window,
GLFWwindowrefreshfun callback );
[DllImport( SSC_libName, EntryPoint = "glfwSetWindowFocusCallback" )]
internal static extern unsafe GLFWwindowfocusfun glfwSetWindowFocusCallback(
[LibraryImport( SSC_libName, EntryPoint = "glfwSetWindowFocusCallback" )]
internal static unsafe partial GLFWwindowfocusfun glfwSetWindowFocusCallback(
IntPtr window,
GLFWwindowfocusfun callback );
[DllImport( SSC_libName, EntryPoint = "glfwSetWindowIconifyCallback" )]
internal static extern unsafe GLFWwindowiconifyfun glfwSetWindowIconifyCallback(
[LibraryImport(
SSC_libName,
EntryPoint = "glfwSetWindowIconifyCallback" )]
internal static unsafe partial GLFWwindowiconifyfun glfwSetWindowIconifyCallback(
IntPtr window,
GLFWwindowiconifyfun callback );
[DllImport( SSC_libName, EntryPoint = "glfwSetWindowMaximizeCallback" )]
internal static extern unsafe GLFWwindowmaximizefun glfwSetWindowMaximizeCallback(
[LibraryImport(
SSC_libName,
EntryPoint = "glfwSetWindowMaximizeCallback" )]
internal static unsafe partial GLFWwindowmaximizefun glfwSetWindowMaximizeCallback(
IntPtr window,
GLFWwindowmaximizefun callback );
[DllImport( SSC_libName, EntryPoint = "glfwSetFramebufferSizeCallback" )]
internal static extern unsafe FrameBufferSizeHandler glfwSetFramebufferSizeCallback(
[LibraryImport(
SSC_libName,
EntryPoint = "glfwSetFramebufferSizeCallback" )]
internal static unsafe partial FrameBufferSizeHandler glfwSetFramebufferSizeCallback(
IntPtr window,
IntPtr callback );
[DllImport(
[LibraryImport(
SSC_libName,
EntryPoint = "glfwSetWindowContentScaleCallback" )]
internal static extern unsafe GLFWwindowcontentscalefun glfwSetWindowContentScaleCallback(
internal static unsafe partial GLFWwindowcontentscalefun glfwSetWindowContentScaleCallback(
IntPtr window,
GLFWwindowcontentscalefun callback );
[DllImport( SSC_libName, EntryPoint = "glfwPollEvents" )]
internal static extern unsafe void glfwPollEvents();
[LibraryImport( SSC_libName, EntryPoint = "glfwPollEvents" )]
internal static unsafe partial void glfwPollEvents();
[DllImport( SSC_libName, EntryPoint = "glfwWaitEvents" )]
internal static extern unsafe void glfwWaitEvents();
[LibraryImport( SSC_libName, EntryPoint = "glfwWaitEvents" )]
internal static unsafe partial void glfwWaitEvents();
[DllImport( SSC_libName, EntryPoint = "glfwWaitEventsTimeout" )]
internal static extern unsafe void glfwWaitEventsTimeout(
[LibraryImport( SSC_libName, EntryPoint = "glfwWaitEventsTimeout" )]
internal static unsafe partial void glfwWaitEventsTimeout(
double timeout );
[DllImport( SSC_libName, EntryPoint = "glfwPostEmptyEvent" )]
internal static extern unsafe void glfwPostEmptyEvent();
[LibraryImport( SSC_libName, EntryPoint = "glfwPostEmptyEvent" )]
internal static unsafe partial void glfwPostEmptyEvent();
[DllImport( SSC_libName, EntryPoint = "glfwGetInputMode" )]
internal static extern unsafe int glfwGetInputMode(
[LibraryImport( SSC_libName, EntryPoint = "glfwGetInputMode" )]
internal static unsafe partial int glfwGetInputMode(
IntPtr window,
int mode );
[DllImport( SSC_libName, EntryPoint = "glfwSetInputMode" )]
internal static extern unsafe void glfwSetInputMode(
[LibraryImport( SSC_libName, EntryPoint = "glfwSetInputMode" )]
internal static unsafe partial void glfwSetInputMode(
IntPtr window,
int mode,
int value );
[DllImport( SSC_libName, EntryPoint = "glfwRawMouseMotionSupported" )]
internal static extern unsafe int glfwRawMouseMotionSupported();
[LibraryImport(
SSC_libName,
EntryPoint = "glfwRawMouseMotionSupported" )]
internal static unsafe partial int glfwRawMouseMotionSupported();
[DllImport( SSC_libName, EntryPoint = "glfwGetKeyName" )]
internal static extern unsafe byte* glfwGetKeyName(
[LibraryImport( SSC_libName, EntryPoint = "glfwGetKeyName" )]
internal static unsafe partial byte* glfwGetKeyName(
int key,
int scancode );
[DllImport( SSC_libName, EntryPoint = "glfwGetKeyScancode" )]
internal static extern unsafe int glfwGetKeyScancode( int key );
[LibraryImport( SSC_libName, EntryPoint = "glfwGetKeyScancode" )]
internal static unsafe partial int glfwGetKeyScancode( int key );
[DllImport( SSC_libName, EntryPoint = "glfwGetKey" )]
internal static extern unsafe KeyStatus glfwGetKey(
[LibraryImport( SSC_libName, EntryPoint = "glfwGetKey" )]
internal static unsafe partial KeyStatus glfwGetKey(
IntPtr window,
int key );
[DllImport( SSC_libName, EntryPoint = "glfwGetMouseButton" )]
internal static extern unsafe int glfwGetMouseButton(
[LibraryImport( SSC_libName, EntryPoint = "glfwGetMouseButton" )]
internal static unsafe partial int glfwGetMouseButton(
IntPtr window,
int button );
[DllImport( SSC_libName, EntryPoint = "glfwGetCursorPos" )]
internal static extern unsafe void glfwGetCursorPos(
[LibraryImport( SSC_libName, EntryPoint = "glfwGetCursorPos" )]
internal static unsafe partial void glfwGetCursorPos(
IntPtr window,
double* xpos,
double* ypos );
[DllImport( SSC_libName, EntryPoint = "glfwSetCursorPos" )]
internal static extern unsafe void glfwSetCursorPos(
[LibraryImport( SSC_libName, EntryPoint = "glfwSetCursorPos" )]
internal static unsafe partial void glfwSetCursorPos(
IntPtr window,
double xpos,
double ypos );
[DllImport( SSC_libName, EntryPoint = "glfwCreateCursor" )]
internal static extern unsafe GLFWcursor* glfwCreateCursor(
[LibraryImport( SSC_libName, EntryPoint = "glfwCreateCursor" )]
internal static unsafe partial GLFWcursor* glfwCreateCursor(
GLFWimage* image,
int xhot,
int yhot );
[DllImport( SSC_libName, EntryPoint = "glfwCreateStandardCursor" )]
internal static extern unsafe GLFWcursor* glfwCreateStandardCursor(
[LibraryImport( SSC_libName, EntryPoint = "glfwCreateStandardCursor" )]
internal static unsafe partial GLFWcursor* glfwCreateStandardCursor(
int shape );
[DllImport( SSC_libName, EntryPoint = "glfwDestroyCursor" )]
internal static extern unsafe void glfwDestroyCursor(
[LibraryImport( SSC_libName, EntryPoint = "glfwDestroyCursor" )]
internal static unsafe partial void glfwDestroyCursor(
GLFWcursor* cursor );
[DllImport( SSC_libName, EntryPoint = "glfwSetCursor" )]
internal static extern unsafe void glfwSetCursor(
[LibraryImport( SSC_libName, EntryPoint = "glfwSetCursor" )]
internal static unsafe partial void glfwSetCursor(
IntPtr window,
GLFWcursor* cursor );
[DllImport( SSC_libName, EntryPoint = "glfwSetKeyCallback" )]
internal static extern unsafe GLFWkeyfun glfwSetKeyCallback(
[LibraryImport( SSC_libName, EntryPoint = "glfwSetKeyCallback" )]
internal static unsafe partial GLFWkeyfun glfwSetKeyCallback(
IntPtr window,
GLFWkeyfun callback );
[DllImport( SSC_libName, EntryPoint = "glfwSetCharCallback" )]
internal static extern unsafe GLFWcharfun glfwSetCharCallback(
[LibraryImport( SSC_libName, EntryPoint = "glfwSetCharCallback" )]
internal static unsafe partial GLFWcharfun glfwSetCharCallback(
IntPtr window,
GLFWcharfun callback );
[DllImport( SSC_libName, EntryPoint = "glfwSetCharModsCallback" )]
internal static extern unsafe GLFWcharmodsfun glfwSetCharModsCallback(
[LibraryImport( SSC_libName, EntryPoint = "glfwSetCharModsCallback" )]
internal static unsafe partial GLFWcharmodsfun glfwSetCharModsCallback(
IntPtr window,
GLFWcharmodsfun callback );
[DllImport( SSC_libName, EntryPoint = "glfwSetMouseButtonCallback" )]
internal static extern unsafe GLFWmousebuttonfun glfwSetMouseButtonCallback(
[LibraryImport( SSC_libName, EntryPoint = "glfwSetMouseButtonCallback" )]
internal static unsafe partial GLFWmousebuttonfun glfwSetMouseButtonCallback(
IntPtr window,
GLFWmousebuttonfun callback );
[DllImport( SSC_libName, EntryPoint = "glfwSetCursorPosCallback" )]
internal static extern unsafe GLFWcursorposfun glfwSetCursorPosCallback(
[LibraryImport( SSC_libName, EntryPoint = "glfwSetCursorPosCallback" )]
internal static unsafe partial GLFWcursorposfun glfwSetCursorPosCallback(
IntPtr window,
GLFWcursorposfun callback );
[DllImport( SSC_libName, EntryPoint = "glfwSetCursorEnterCallback" )]
internal static extern unsafe GLFWcursorenterfun glfwSetCursorEnterCallback(
[LibraryImport( SSC_libName, EntryPoint = "glfwSetCursorEnterCallback" )]
internal static unsafe partial GLFWcursorenterfun glfwSetCursorEnterCallback(
IntPtr window,
GLFWcursorenterfun callback );
[DllImport( SSC_libName, EntryPoint = "glfwSetScrollCallback" )]
internal static extern unsafe GLFWscrollfun glfwSetScrollCallback(
[LibraryImport( SSC_libName, EntryPoint = "glfwSetScrollCallback" )]
internal static unsafe partial GLFWscrollfun glfwSetScrollCallback(
IntPtr window,
GLFWscrollfun callback );
[DllImport( SSC_libName, EntryPoint = "glfwSetDropCallback" )]
internal static extern unsafe GLFWdropfun glfwSetDropCallback(
[LibraryImport( SSC_libName, EntryPoint = "glfwSetDropCallback" )]
internal static unsafe partial GLFWdropfun glfwSetDropCallback(
IntPtr window,
GLFWdropfun callback );
[DllImport( SSC_libName, EntryPoint = "glfwJoystickPresent" )]
internal static extern unsafe int glfwJoystickPresent( int jid );
[LibraryImport( SSC_libName, EntryPoint = "glfwJoystickPresent" )]
internal static unsafe partial int glfwJoystickPresent( int jid );
[DllImport( SSC_libName, EntryPoint = "glfwGetJoystickAxes" )]
internal static extern unsafe float* glfwGetJoystickAxes(
[LibraryImport( SSC_libName, EntryPoint = "glfwGetJoystickAxes" )]
internal static unsafe partial float* glfwGetJoystickAxes(
int jid,
int* count );
[DllImport( SSC_libName, EntryPoint = "glfwGetJoystickButtons" )]
internal static extern unsafe byte* glfwGetJoystickButtons(
[LibraryImport( SSC_libName, EntryPoint = "glfwGetJoystickButtons" )]
internal static unsafe partial byte* glfwGetJoystickButtons(
int jid,
int* count );
[DllImport( SSC_libName, EntryPoint = "glfwGetJoystickHats" )]
internal static extern unsafe byte* glfwGetJoystickHats(
[LibraryImport( SSC_libName, EntryPoint = "glfwGetJoystickHats" )]
internal static unsafe partial byte* glfwGetJoystickHats(
int jid,
int* count );
[DllImport( SSC_libName, EntryPoint = "glfwGetJoystickName" )]
internal static extern unsafe byte* glfwGetJoystickName( int jid );
[LibraryImport( SSC_libName, EntryPoint = "glfwGetJoystickName" )]
internal static unsafe partial byte* glfwGetJoystickName( int jid );
[DllImport( SSC_libName, EntryPoint = "glfwGetJoystickGUID" )]
internal static extern unsafe byte* glfwGetJoystickGUID( int jid );
[LibraryImport( SSC_libName, EntryPoint = "glfwGetJoystickGUID" )]
internal static unsafe partial byte* glfwGetJoystickGUID( int jid );
[DllImport( SSC_libName, EntryPoint = "glfwSetJoystickUserPointer" )]
internal static extern unsafe void glfwSetJoystickUserPointer(
[LibraryImport( SSC_libName, EntryPoint = "glfwSetJoystickUserPointer" )]
internal static unsafe partial void glfwSetJoystickUserPointer(
int jid,
void* pointer );
[DllImport( SSC_libName, EntryPoint = "glfwGetJoystickUserPointer" )]
internal static extern unsafe void* glfwGetJoystickUserPointer(
[LibraryImport( SSC_libName, EntryPoint = "glfwGetJoystickUserPointer" )]
internal static unsafe partial void* glfwGetJoystickUserPointer(
int jid );
[DllImport( SSC_libName, EntryPoint = "glfwJoystickIsGamepad" )]
internal static extern unsafe int glfwJoystickIsGamepad( int jid );
[LibraryImport( SSC_libName, EntryPoint = "glfwJoystickIsGamepad" )]
internal static unsafe partial int glfwJoystickIsGamepad( int jid );
[DllImport( SSC_libName, EntryPoint = "glfwSetJoystickCallback" )]
internal static extern unsafe GLFWjoystickfun glfwSetJoystickCallback(
[LibraryImport( SSC_libName, EntryPoint = "glfwSetJoystickCallback" )]
internal static unsafe partial GLFWjoystickfun glfwSetJoystickCallback(
GLFWjoystickfun callback );
[DllImport( SSC_libName, EntryPoint = "glfwUpdateGamepadMappings" )]
internal static extern unsafe int glfwUpdateGamepadMappings( byte* str );
[LibraryImport( SSC_libName, EntryPoint = "glfwUpdateGamepadMappings" )]
internal static unsafe partial int glfwUpdateGamepadMappings(
byte* str );
[DllImport( SSC_libName, EntryPoint = "glfwGetGamepadName" )]
internal static extern unsafe byte* glfwGetGamepadName( int jid );
[LibraryImport( SSC_libName, EntryPoint = "glfwGetGamepadName" )]
internal static unsafe partial byte* glfwGetGamepadName( int jid );
[DllImport( SSC_libName, EntryPoint = "glfwGetGamepadState" )]
internal static extern unsafe int glfwGetGamepadState(
[LibraryImport( SSC_libName, EntryPoint = "glfwGetGamepadState" )]
internal static unsafe partial int glfwGetGamepadState(
int jid,
GLFWgamepadstate* state );
[DllImport( SSC_libName, EntryPoint = "glfwSetClipboardString" )]
internal static extern unsafe void glfwSetClipboardString(
[LibraryImport( SSC_libName, EntryPoint = "glfwSetClipboardString" )]
internal static unsafe partial void glfwSetClipboardString(
IntPtr window,
byte* str );
[DllImport( SSC_libName, EntryPoint = "glfwGetClipboardString" )]
internal static extern unsafe byte* glfwGetClipboardString(
[LibraryImport( SSC_libName, EntryPoint = "glfwGetClipboardString" )]
internal static unsafe partial byte* glfwGetClipboardString(
IntPtr window );
[DllImport( SSC_libName, EntryPoint = "glfwGetTime" )]
internal static extern unsafe double glfwGetTime();
[LibraryImport( SSC_libName, EntryPoint = "glfwGetTime" )]
internal static unsafe partial double glfwGetTime();
[DllImport( SSC_libName, EntryPoint = "glfwSetTime" )]
internal static extern unsafe void glfwSetTime( double time );
[LibraryImport( SSC_libName, EntryPoint = "glfwSetTime" )]
internal static unsafe partial void glfwSetTime( double time );
[DllImport( SSC_libName, EntryPoint = "glfwGetTimerValue" )]
internal static extern unsafe ulong* glfwGetTimerValue();
[LibraryImport( SSC_libName, EntryPoint = "glfwGetTimerValue" )]
internal static unsafe partial ulong* glfwGetTimerValue();
[DllImport( SSC_libName, EntryPoint = "glfwGetTimerFrequency" )]
internal static extern unsafe ulong* glfwGetTimerFrequency();
[LibraryImport( SSC_libName, EntryPoint = "glfwGetTimerFrequency" )]
internal static unsafe partial ulong* glfwGetTimerFrequency();
[DllImport( SSC_libName, EntryPoint = "glfwMakeContextCurrent" )]
internal static extern unsafe void glfwMakeContextCurrent(
[LibraryImport( SSC_libName, EntryPoint = "glfwMakeContextCurrent" )]
internal static unsafe partial void glfwMakeContextCurrent(
IntPtr window );
[DllImport( SSC_libName, EntryPoint = "glfwGetCurrentContext" )]
internal static extern unsafe IntPtr glfwGetCurrentContext();
[LibraryImport( SSC_libName, EntryPoint = "glfwGetCurrentContext" )]
internal static unsafe partial IntPtr glfwGetCurrentContext();
[DllImport( SSC_libName, EntryPoint = "glfwSwapBuffers" )]
internal static extern unsafe void glfwSwapBuffers( IntPtr window );
[LibraryImport( SSC_libName, EntryPoint = "glfwSwapBuffers" )]
internal static unsafe partial void glfwSwapBuffers( IntPtr window );
[DllImport( SSC_libName, EntryPoint = "glfwSwapInterval" )]
internal static extern unsafe void glfwSwapInterval( int interval );
[LibraryImport( SSC_libName, EntryPoint = "glfwSwapInterval" )]
internal static unsafe partial void glfwSwapInterval( int interval );
[DllImport( SSC_libName, EntryPoint = "glfwExtensionSupported" )]
internal static extern unsafe int glfwExtensionSupported(
[LibraryImport( SSC_libName, EntryPoint = "glfwExtensionSupported" )]
internal static unsafe partial int glfwExtensionSupported(
byte* extension );
[DllImport(
[LibraryImport(
SSC_libName,
EntryPoint = "glfwGetProcAddress",
CharSet = CharSet.Ansi )]
internal static extern unsafe IntPtr glfwGetProcAddress(
StringMarshalling = StringMarshalling.Utf8 )]
internal static unsafe partial IntPtr glfwGetProcAddress(
string procname );
[DllImport( SSC_libName, EntryPoint = "glfwVulkanSupported" )]
internal static extern unsafe int glfwVulkanSupported();
[LibraryImport( SSC_libName, EntryPoint = "glfwVulkanSupported" )]
internal static unsafe partial int glfwVulkanSupported();
[DllImport(
[LibraryImport(
SSC_libName,
EntryPoint = "glfwGetRequiredInstanceExtensions" )]
internal static extern unsafe byte** glfwGetRequiredInstanceExtensions(
internal static unsafe partial byte** glfwGetRequiredInstanceExtensions(
uint* count );
//[DllImport(InternalIO.SSC_libname, EntryPoint = "glfwGetInstanceProcAddress")] internal extern unsafe static GLFWvkproc glfwGetInstanceProcAddress(VkInstance instance, byte* procname);
//[DllImport(InternalIO.SSC_libname, EntryPoint = "glfwGetPhysicalDevicePresentationSupport")] internal extern unsafe static int glfwGetPhysicalDevicePresentationSupport(VkInstance instance, VkPhysicalDevice device, uint* queuefamily);
//[DllImport(InternalIO.SSC_libname, EntryPoint = "glfwCreateWindowSurface")] internal extern unsafe static VkResult glfwCreateWindowSurface(VkInstance instance, glfwWindow* window, VkAllocationCallbacks* allocator, VkSurfaceKHR* surface);
//[LibraryImport(InternalIO.SSC_libname, EntryPoint = "glfwGetInstanceProcAddress")] internal unsafe partial static GLFWvkproc glfwGetInstanceProcAddress(VkInstance instance, byte* procname);
//[LibraryImport(InternalIO.SSC_libname, EntryPoint = "glfwGetPhysicalDevicePresentationSupport")] internal unsafe partial static int glfwGetPhysicalDevicePresentationSupport(VkInstance instance, VkPhysicalDevice device, uint* queuefamily);
//[LibraryImport(InternalIO.SSC_libname, EntryPoint = "glfwCreateWindowSurface")] internal unsafe partial static VkResult glfwCreateWindowSurface(VkInstance instance, glfwWindow* window, VkAllocationCallbacks* allocator, VkSurfaceKHR* surface);
#endregion api call
}
@@ -40,9 +40,9 @@ namespace StgSharp.Math
public interface IVector
{
/*
public static T Create<T>(Vector4 source) where T : IVector
public static TItem Create<TItem>(Vector4 source) where TItem : IVector
{
return T
return TItem
}
/**/
@@ -0,0 +1,4 @@
// <autogenerated />
using System;
using System.Reflection;
[assembly: global::System.Runtime.Versioning.TargetFrameworkAttribute(".NETCoreApp,Version=v8.0", FrameworkDisplayName = ".NET 8.0")]
@@ -0,0 +1,23 @@
//------------------------------------------------------------------------------
// <auto-generated>
// This code was generated by a tool.
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------
using System;
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+ccef0de6f686f94da655b0e7d854d0acaf907d04")]
[assembly: System.Reflection.AssemblyProductAttribute("StgSharp.Common")]
[assembly: System.Reflection.AssemblyTitleAttribute("StgSharp.Common")]
[assembly: System.Reflection.AssemblyVersionAttribute("1.0.0.0")]
[assembly: System.Reflection.AssemblyMetadataAttribute("RepositoryUrl", "https://github.com/Nitload-NSI/StgSharp.git")]
// 由 MSBuild WriteCodeFragment 类生成。
@@ -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+c23b640cae59b9ee7dcfd8f026b8970a084ddbd7")]
[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+ccef0de6f686f94da655b0e7d854d0acaf907d04")]
[assembly: System.Reflection.AssemblyProductAttribute("StgSharp.Common")]
[assembly: System.Reflection.AssemblyTitleAttribute("StgSharp.Common")]
[assembly: System.Reflection.AssemblyVersionAttribute("1.0.0.0")]
@@ -1 +1 @@
{"documents":{"D:\\NitloadIndustry\\研究项目\\1-Flagship\\TH2020\\ProjectFile\\*":"https://raw.githubusercontent.com/Nitload-NSI/CCD_Github/c23b640cae59b9ee7dcfd8f026b8970a084ddbd7/*"}}
{"documents":{"D:\\NitloadIndustry\\研究项目\\1-Flagship\\TH2020\\ProjectFile\\*":"https://raw.githubusercontent.com/Nitload-NSI/CCD_Github/ccef0de6f686f94da655b0e7d854d0acaf907d04/*"}}
@@ -0,0 +1,4 @@
// <autogenerated />
using System;
using System.Reflection;
[assembly: global::System.Runtime.Versioning.TargetFrameworkAttribute(".NETCoreApp,Version=v8.0", FrameworkDisplayName = ".NET 8.0")]
@@ -0,0 +1,22 @@
//------------------------------------------------------------------------------
// <auto-generated>
// This code was generated by a tool.
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------
using System;
using System.Reflection;
[assembly: System.Reflection.AssemblyCompanyAttribute("StgSharp.Model")]
[assembly: System.Reflection.AssemblyConfigurationAttribute("Debug")]
[assembly: System.Reflection.AssemblyFileVersionAttribute("1.0.0.0")]
[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+ccef0de6f686f94da655b0e7d854d0acaf907d04")]
[assembly: System.Reflection.AssemblyProductAttribute("StgSharp.Model")]
[assembly: System.Reflection.AssemblyTitleAttribute("StgSharp.Model")]
[assembly: System.Reflection.AssemblyVersionAttribute("1.0.0.0")]
// 由 MSBuild WriteCodeFragment 类生成。
@@ -37,37 +37,27 @@ using System.Xml.Schema;
namespace StgSharp.Script
{
public class AbstractSyntaxTree<TToken, TType>
where TToken: IExpressionToken<TToken, TType>
public sealed class AbstractSyntaxTree<TNode, TType>
where TNode: IASTNode<TNode, TType>
where TType: ITypeSource<TType>
{
private bool _cacheAvailable;
private HashSet<TToken> _allToken = new();
private TToken _root;
private List<TNode> _allToken = new();
private TNode _root;
public int Count
{
get
{
if( !_cacheAvailable ) {
MakeCache();
}
return _allToken.Count;
}
get { return _allToken.Count; }
}
public TToken Root => _root;
public TNode Root => _root;
public bool Contains( TToken node )
public bool Contains( TNode node )
{
if( !_cacheAvailable ) {
MakeCache();
}
return _allToken.Contains( node );
}
public virtual void MakeCache() { }
public List<List<TNode>> SortByDepth() { }
}
}
@@ -32,7 +32,7 @@ using System;
namespace StgSharp.Script.Express
{
public class ExpBuiltinConstant<T> : ExpLiteralToken<T>
public class ExpBuiltinConstant<T> : ExpLiteralNode<T>
{
internal ExpBuiltinConstant( string name, T value )
@@ -34,7 +34,7 @@ using System.Text;
namespace StgSharp.Script.Express
{
public abstract class ExpCollectionInstanceBase : ExpToken
public abstract class ExpCollectionInstanceBase : ExpBaseNode
{
protected internal (int min, int max) _range;
@@ -53,11 +53,9 @@ namespace StgSharp.Script.Express
get => _memberType;
}
public override ExpToken Left => null!;
public override ExpBaseNode Left => null!;
public override ExpToken Right => null!;
public override ExpToken Next => null!;
public override ExpBaseNode Right => null!;
public int MinCapacity => _range.min;
@@ -78,11 +76,6 @@ namespace StgSharp.Script.Express
public override ExpCollectionBase CollectionValue => _collection;
public override ExpToken Next
{
set => throw new NotImplementedException();
}
public override IExpElementSource EqualityTypeConvert => throw new NotImplementedException(
);
@@ -101,11 +94,6 @@ namespace StgSharp.Script.Express
public override ExpCollectionBase CollectionValue => _collection;
public override ExpToken Next
{
set => throw new NotImplementedException();
}
public override IExpElementSource EqualityTypeConvert => throw new NotImplementedException(
);
@@ -124,11 +112,6 @@ namespace StgSharp.Script.Express
public override ExpCollectionBase CollectionValue => _collection;
public override ExpToken Next
{
set => throw new NotImplementedException();
}
public override IExpElementSource EqualityTypeConvert => throw new NotImplementedException(
);
@@ -150,11 +133,6 @@ namespace StgSharp.Script.Express
public override ExpCollectionBase CollectionValue => _collection;
public override ExpToken Next
{
set => throw new NotImplementedException();
}
public override IExpElementSource EqualityTypeConvert => _collection;
}
@@ -0,0 +1,73 @@
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// file="ExpLogic.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.Text;
namespace StgSharp.Script.Express
{
public enum ExpLogic
{
Unknown = 0,
False = 1,
True = 2,
}
public static class LogicConverter
{
public static bool? AsNullableBool(this ExpLogic l)
{
switch (l)
{
case ExpLogic.Unknown:
return null;
case ExpLogic.False:
return false;
case ExpLogic.True:
return true;
default:
throw new ArgumentException();
}
}
public static ExpLogic AsNullableInt(this bool? b)
{
return b switch
{
null => ExpLogic.Unknown,
true => ExpLogic.True,
false => ExpLogic.False,
};
}
}
}
@@ -0,0 +1,90 @@
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// 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.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;
}
private 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();
}
}
}
@@ -33,6 +33,7 @@ using CommunityToolkit.HighPerformance.Buffers;
using StgSharp.Collections;
using System;
using System.Collections;
using System.Collections.Frozen;
using System.Collections.Generic;
using System.Collections.ObjectModel;
@@ -44,10 +45,11 @@ 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, ExpOperandToken> _operators;
private static FrozenDictionary<string, ExpBinaryOperatorNode> _operators;
private static StringPool _compileStringCache;
public static FrozenDictionary<string, ExpElementInstanceBase> BuiltinConst => _builtinConst;
@@ -82,30 +84,38 @@ namespace StgSharp.Script.Express
_compileStringCache = new StringPool();
_multiplexer = new ConcurrentStringHashMultiplexer();
_builtinType = new Dictionary<string, ExpTypeSource>( _multiplexer ) {
{ PoolString( KeyWord.Int ), new ExpBuiltinType(
KeyWord.Int,
typeof( int ) ) }, { PoolString( KeyWord.Real ), new ExpBuiltinType(
KeyWord.Real,
typeof( float ) ) }, { PoolString(
KeyWord.Bool ), new ExpBuiltinType(
KeyWord.Bool,
typeof( bool ) ) }, { PoolString(
KeyWord.Binary ), new ExpBuiltinType(
KeyWord.Binary,
typeof( bool ) ) }, { PoolString(
KeyWord.String ), new ExpBuiltinType(
KeyWord.String,
typeof( string ) ) }, { PoolString(
KeyWord.Logic ), new ExpBuiltinType(
KeyWord.Logic,
typeof( ExpLogic ) ) }
}.ToFrozenDictionary();
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 ) ) ),
_operators = new Dictionary<string, ExpOperandToken>( _multiplexer )
];
_builtinType = new Dictionary<string, ExpTypeSource>(
builtinTypeSource, _multiplexer ) .ToFrozenDictionary();
_operators = new Dictionary<string, ExpBinaryOperatorNode>(
_multiplexer )
{
{ PoolString( KeyWord.ADD ), new ExpOperandToken( KeyWord.ADD ) },
{ PoolString( KeyWord.SUB ), new ExpOperandToken( KeyWord.SUB ) }
{ PoolString( KeyWord.ADD ), new ExpBinaryOperatorNode(
KeyWord.ADD ) },
{ PoolString( KeyWord.SUB ), new ExpBinaryOperatorNode(
KeyWord.SUB ) }
}.ToFrozenDictionary();
_builtinConst = new Dictionary<string, ExpElementInstanceBase>(
@@ -116,7 +126,28 @@ namespace StgSharp.Script.Express
PoolString( "E" ), MathF.E ) },
}.ToFrozenDictionary();
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 )
@@ -124,6 +155,11 @@ namespace StgSharp.Script.Express
return _compileStringCache.GetOrAdd( str );
}
public static string PoolString( ReadOnlySpan<char> str )
{
return _compileStringCache.GetOrAdd( str );
}
public static void SkipComment( IScriptSourceProvider source ) { }
public static bool TryGetBuiltinConst(
@@ -40,42 +40,67 @@ namespace StgSharp.Script.Express
public static partial class ExpCompile
{
private static FrozenDictionary<string, int> _operatorPrecedence;
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>( "[]", 1 ),
new KeyValuePair<string, int>( ".", 1 ),
new KeyValuePair<string, int>( "\\", 1 ),
new KeyValuePair<string, int>( "unary+", 2 ),
new KeyValuePair<string, int>( "unary-", 2 ),
new KeyValuePair<string, int>( "NOT", 2 ),
new KeyValuePair<string, int>( "**", 3 ),
new KeyValuePair<string, int>( "*", 4 ),
new KeyValuePair<string, int>( "/", 4 ),
new KeyValuePair<string, int>( "AND", 4 ),
new KeyValuePair<string, int>( "MOD", 4 ),
new KeyValuePair<string, int>( "DIV", 4 ),
new KeyValuePair<string, int>( "||", 4 ),
new KeyValuePair<string, int>( "+", 5 ),
new KeyValuePair<string, int>( "-", 5 ),
new KeyValuePair<string, int>( "OR", 5 ),
new KeyValuePair<string, int>( "XOR", 5 ),
new KeyValuePair<string, int>( "=", 6 ),
new KeyValuePair<string, int>( "<>", 6 ),
new KeyValuePair<string, int>( "<=", 6 ),
new KeyValuePair<string, int>( ">=", 6 ),
new KeyValuePair<string, int>( ">", 6 ),
new KeyValuePair<string, int>( "<", 6 ),
new KeyValuePair<string, int>( ":=:", 6 ),
new KeyValuePair<string, int>( ":<>:", 6 ),
new KeyValuePair<string, int>( "IN", 6 ),
new KeyValuePair<string, int>( "LIKE", 6 ),
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
}
}
@@ -31,6 +31,7 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
@@ -39,6 +40,23 @@ 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 ) ) {
string? str =
field.GetValue( null ) as string;
if( str != null ) {
_compileStringCache.GetOrAdd( str );
}
}
} );
while( !result.IsCompleted ) { }
}
public static class KeyWord
{
@@ -56,6 +74,7 @@ namespace StgSharp.Script.Express
SUB = "SUB",
MUL = "MUL",
DIV = "DIV",
NOT = "NOT",
Assignment = ":=",
Equal = "=",
Mod = "MOD",
@@ -66,9 +85,9 @@ namespace StgSharp.Script.Express
Insert = "INSERT",
Remove = "REMOVE",
ANDOR = "ANDOR",
GetIndex = "[]",
UnaryAdd = "unary+",
UnarySub = "unary-",
GetIndex = "[",
UnaryAdd = "+",
UnarySub = "-",
Exp = "**";
}
@@ -68,7 +68,7 @@ namespace StgSharp.Script.Express
throw new NotImplementedException();
}
public override ExpToken MakeReference( params object[] options )
public override ExpBaseNode MakeReference( params object[] options )
{
if( options.Length == 0 || options[ 0 ] is not string str ) {
return null!;
@@ -34,21 +34,15 @@ using System.Text;
namespace StgSharp.Script.Express
{
public class ExpEntity : ExpToken
public class ExpEntity : ExpBaseNode
{
public ExpEntity( string name, ExpSchema context )
: base( name, context ) { }
public override ExpToken Left => throw new NotImplementedException();
public override ExpBaseNode Left => throw new NotImplementedException();
public override ExpToken Right => throw new NotImplementedException();
public override ExpToken Next
{
get => throw new NotImplementedException();
set => throw new NotImplementedException();
}
public override ExpBaseNode Right => throw new NotImplementedException();
public override IExpElementSource EqualityTypeConvert => throw new NotImplementedException(
);
@@ -79,7 +73,7 @@ namespace StgSharp.Script.Express
throw new NotImplementedException();
}
public override ExpToken CreateInstanceToken()
public override ExpBaseNode CreateInstanceToken()
{
throw new NotImplementedException();
}
@@ -34,33 +34,27 @@ using System.Text;
namespace StgSharp.Script.Express
{
public class ExpFunction : ExpToken
public class ExpFunction : ExpBaseNode
{
private ExpFunctionSource _source;
private readonly ExpToken _return;
private readonly List<KeyValuePair<string, ExpToken>> _parameterList
= new List<KeyValuePair<string, ExpToken>>();
private readonly ExpBaseNode _return;
private readonly List<KeyValuePair<string, ExpBaseNode>> _parameterList
= new List<KeyValuePair<string, ExpBaseNode>>();
public ExpFunction( string name, ExpSchema context )
: base( name, context ) { }
public ExpElementType ElementType => ExpElementType.Function;
public override ExpToken Left => throw new NotImplementedException();
public override ExpBaseNode Left => throw new NotImplementedException();
public override ExpToken Next
{
get => throw new NotImplementedException();
set => throw new NotImplementedException();
}
public override ExpToken Right => throw new NotImplementedException();
public override ExpBaseNode Right => throw new NotImplementedException();
public override IExpElementSource EqualityTypeConvert => throw new NotImplementedException(
);
public void CallThisFunction( params ExpToken[] parameters ) { }
public void CallThisFunction( params ExpBaseNode[] parameters ) { }
}
@@ -89,7 +83,7 @@ namespace StgSharp.Script.Express
throw new NotImplementedException();
}
public override ExpToken MakeReference( params object[] options )
public override ExpBaseNode MakeReference( params object[] options )
{
throw new NotImplementedException();
}
@@ -46,15 +46,9 @@ namespace StgSharp.Script.Express
public object? value => throw new NotImplementedException();
public override ExpToken Left => throw new NotImplementedException();
public override ExpBaseNode Left => throw new NotImplementedException();
public override ExpToken Next
{
get => null!;
set { }
}
public override ExpToken Right => throw new NotImplementedException();
public override ExpBaseNode Right => throw new NotImplementedException();
public override IExpElementSource EqualityTypeConvert => throw new NotImplementedException(
);
@@ -86,7 +80,7 @@ namespace StgSharp.Script.Express
throw new NotImplementedException();
}
public override ExpToken MakeReference( params object[] options )
public override ExpBaseNode MakeReference( params object[] options )
{
throw new NotImplementedException();
}
@@ -41,15 +41,9 @@ namespace StgSharp.Script.Express
public ExpType( string name, ExpSchema context )
: base( name, context ) { }
public override ExpToken Left => throw new NotImplementedException();
public override ExpBaseNode Left => throw new NotImplementedException();
public override ExpToken Next
{
get => throw new NotImplementedException();
set => throw new NotImplementedException();
}
public override ExpToken Right => throw new NotImplementedException();
public override ExpBaseNode Right => throw new NotImplementedException();
public override IExpElementSource EqualityTypeConvert => throw new NotImplementedException(
);
@@ -0,0 +1,113 @@
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// file="ExpBaseNode.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 System;
using System.Collections.Generic;
using System.Text;
namespace StgSharp.Script.Express
{
public abstract class ExpBaseNode : IASTNode<ExpBaseNode, IExpElementSource>
{
protected internal ExpNodeFlag _tokenType;
protected internal string _name;
protected ExpBaseNode( string name, ExpSchema context )
{
_name = name;
NameSpace = context;
Next = this;
Previous = this;
}
public abstract ExpBaseNode Left
{
get;
}
public ExpBaseNode Next
{
get;
set;
}
public abstract ExpBaseNode Right
{
get;
}
public ExpBaseNode Previous
{
get;
set;
}
public ExpSchema NameSpace
{
get;
private set;
}
public abstract IExpElementSource EqualityTypeConvert
{
get;
}
public long TokenTypeCode => ( long )_tokenType;
public string Name => _name;
public virtual void AppendNode( ExpBaseNode nextToken )
{
Next.Previous = nextToken;
nextToken.Next = Next;
Next = nextToken;
Next.Previous = this;
}
public ExpNodeNextEnumerator GetEnumerator()
{
return new ExpNodeNextEnumerator( this );
}
protected void AssertSchemaInclude( ExpBaseNode expressionRoot )
{
if( expressionRoot.NameSpace != NameSpace && NameSpace.HasSchemaInclude(
expressionRoot.NameSpace ) ) {
throw new ExpInvalidSchemaIncludeException(
NameSpace, expressionRoot.NameSpace );
}
}
}
}
@@ -0,0 +1,79 @@
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// file="ExpBinaryOperatorNode.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 class ExpBinaryOperatorNode : ExpBaseNode
{
private ExpBaseNode _left;
private ExpBaseNode _right;
private ExpTypeSource _returnType;
public ExpBinaryOperatorNode( string name ) : base( name, null! ) { }
public ExpBinaryOperatorNode(
string source,
ExpSchema context,
ExpBaseNode left,
ExpBaseNode right )
: base( source, context )
{
if( !left.EqualityTypeConvert
.IsConvertable( right.EqualityTypeConvert ) ) {
throw new InvalidCastException(
$"Cannot convert element {left.EqualityTypeConvert} to {right.EqualityTypeConvert}" );
}
_left = left;
_right = right;
}
public override ExpBaseNode Left => _left;
public override ExpBaseNode Right => _right;
public override IExpElementSource EqualityTypeConvert => _returnType;
public static ExpBinaryOperatorNode Add(
ExpBaseNode left,
ExpBaseNode right )
{
if( left.EqualityTypeConvert
.IsConvertable( ExpBuiltinConstant<int> ) ) { }
}
}
}
@@ -0,0 +1,78 @@
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// file="ExpIfNode.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.Script.Express;
using System;
using System.Collections.Generic;
using System.Text;
namespace StgSharp.Script.Express
{
public sealed class ExpIfNode : ExpBaseNode
{
private ExpBaseNode _falseOpBegin;
private ExpBaseNode _rule;
private ExpBaseNode _trueOpBegin ;
public ExpIfNode(
string name,
ExpSchema context,
ExpBaseNode rule,
ExpBaseNode rootOperationIfTrue,
ExpBaseNode rootOperationIfFalse )
: base( name, context )
{
_rule = rule;
_trueOpBegin = rootOperationIfFalse;
_falseOpBegin = rootOperationIfFalse;
}
public override ExpBaseNode Left => _trueOpBegin;
public override ExpBaseNode Right => _falseOpBegin;
public override IExpElementSource EqualityTypeConvert => null!;
public void AppendFalseOperation( ExpBaseNode expressionRoot )
{
AssertSchemaInclude( expressionRoot );
_falseOpBegin.AppendNode( expressionRoot );
}
public void AppendTrueOperation( ExpBaseNode expressionRoot )
{
AssertSchemaInclude( expressionRoot );
_trueOpBegin.AppendNode( expressionRoot );
}
}
}
@@ -0,0 +1,63 @@
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// file="ExpIndexOfNode.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 class ExpIndexOfNode : ExpBaseNode
{
private ExpCollectionInstanceBase _collection;
private ExpBaseNode _indexExpression;
public ExpIndexOfNode(
ExpSchema context,
ExpCollectionInstanceBase instance,
ExpBaseNode indexExpression )
: base( ExpCompile.PoolString( "[" ), context )
{
_collection = instance;
_indexExpression = indexExpression;
}
public override ExpBaseNode Left => _collection;
public override ExpBaseNode Right => throw new NotImplementedException();
public override IExpElementSource EqualityTypeConvert => throw new NotImplementedException(
);
}
}
@@ -0,0 +1,96 @@
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// file="ExpLiteralNode.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.Generic;
using System.Text;
namespace StgSharp.Script.Express
{
public class ExpLiteralNode<T> : ExpElementInstanceBase
{
private readonly ExpBuiltinType _type;
private readonly T _value;
public ExpLiteralNode( string name, ExpSchema context, T value )
: base( name, context )
{
_value = value;
switch( value ) {
case float f:
ExpCompile.TryGetBuiltinType(
ExpCompile.KeyWord.Real, out ExpTypeSource? type );
_type = ( type as ExpBuiltinType )!;
_tokenType = ExpNodeFlag.BuiltinType_Float | ExpNodeFlag.Element_Const;
break;
case int i:
ExpCompile.TryGetBuiltinType(
ExpCompile.KeyWord.Int, out type );
_type = ( type as ExpBuiltinType )!;
_tokenType = ExpNodeFlag.BuiltinType_Int | ExpNodeFlag.Element_Const;
break;
case BitArray b:
ExpCompile.TryGetBuiltinType(
ExpCompile.KeyWord.Binary, out type );
_type = ( type as ExpBuiltinType )!;
_tokenType = ExpNodeFlag.BuiltinType_Binary | ExpNodeFlag.Element_Const;
break;
case string s:
ExpCompile.TryGetBuiltinType(
ExpCompile.KeyWord.String, out type );
_type = ( type as ExpBuiltinType )!;
_tokenType = ExpNodeFlag.BuiltinType_Int | ExpNodeFlag.Element_Const;
break;
case ExpLogic l:
ExpCompile.TryGetBuiltinType(
ExpCompile.KeyWord.Logic, out type );
_type = ( type as ExpBuiltinType )!;
_tokenType = ExpNodeFlag.BuiltinType_Int | ExpNodeFlag.Element_Const;
break;
default:
throw new ExpInvalidTypeException(
"Builtin Type", value!.GetType().Name );
}
}
public override ExpBaseNode Left => throw new NotImplementedException();
public override ExpBaseNode Right => throw new NotImplementedException();
public override IExpElementSource EqualityTypeConvert => _type;
public override string TypeName => _type.Name;
public T value => _value;
}
}
@@ -0,0 +1,95 @@
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// file="ExpRepeatNode.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.Runtime.Serialization;
using System.Text;
namespace StgSharp.Script.Express
{
public class ExpRepeatToken : ExpBaseNode
{
private ExpElementInstanceBase _variable, _begin, _end, _increment;
private ExpBaseNode _operationBegin;
public ExpRepeatToken(
string name,
ExpSchema context,
ExpBaseNode operationBegin,
ExpElementInstanceBase variable,
ExpElementInstanceBase begin,
ExpElementInstanceBase end,
ExpElementInstanceBase increment )
: base( name, context )
{
if( variable.TokenTypeCode != begin.TokenTypeCode || begin.TokenTypeCode !=
end.TokenTypeCode || ( increment != null && end.TokenTypeCode !=
increment.TokenTypeCode ) ) {
throw new InvalidCastException();
}
if( increment == null ) {
switch( ( ExpNodeFlag )variable.TokenTypeCode | ExpNodeFlag.BuiltinType_Any ) {
case ExpNodeFlag.BuiltinType_Float:
increment = new ExpLiteralNode<float>(
$"{name}_defaultIncrement", context, 1.0f );
break;
case ExpNodeFlag.BuiltinType_Int:
increment = new ExpLiteralNode<int>(
$"{name}_defaultIncrement", context, 1 );
break;
default:
throw new ExpInvalidTypeException(
"Int or Real", "otherwise" );
}
}
_begin = begin;
_variable = variable;
_end = end;
_increment = increment;
_tokenType = ExpNodeFlag.Branch_Repeat;
_operationBegin = operationBegin;
}
public override ExpBaseNode Left => throw new NotImplementedException();
public override ExpBaseNode Right => _operationBegin;
public override IExpElementSource EqualityTypeConvert => null!;
public void AppendRepeatedOperation( ExpBaseNode node )
{
_operationBegin.AppendNode( node );
}
}
}
@@ -0,0 +1,113 @@
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// file="ExpSwitchNode.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.Text;
namespace StgSharp.Script.Express
{
public class ExpSwitchNode : ExpBaseNode
{
private Dictionary<ExpBaseNode, ExpBaseNode> _cases;
private ExpBaseNode _default;
private ExpBaseNode _target;
public ExpSwitchNode(
string name,
ExpSchema context,
ExpBaseNode target,
ExpBaseNode defaultCase,
params (ExpBaseNode label, ExpBaseNode op)[] cases )
: base( name, context )
{
_target = target;
_default = defaultCase;
_cases = new Dictionary<ExpBaseNode, ExpBaseNode>();
foreach( (ExpBaseNode label, ExpBaseNode op ) item in cases ) {
if( item.op == null ) {
_cases.Add( item.label, null! );
} else {
_cases.Add( item.label, item.op );
}
}
}
public ExpBaseNode this[ ExpBaseNode index ]
{
get
{
if( _cases.TryGetValue( index, out ExpBaseNode? ret ) ) {
return ret;
}
return _default;
}
}
public override ExpBaseNode Left => throw new NotImplementedException();
public override ExpBaseNode Right => throw new NotImplementedException();
public override IExpElementSource EqualityTypeConvert => null!;
public void AddOperationToDefault( ExpBaseNode expressionRoot )
{
if( expressionRoot != null ) {
_default.AppendNode( expressionRoot );
}
}
/// <summary>
/// Adds an expression to certain <see langword="case" />. The added expression will be run
/// at last.
/// </summary>
/// <param name="label"> Label of case to add operation </param>
/// <param name="expressionRoot"> Root token of the expression to be added. </param>
/// <exception cref="ExpCaseNotFoundException"> Cannot fine the case label in current witch expression. </exception>
public void AppendOperationToCase(
ExpBaseNode label,
ExpBaseNode expressionRoot )
{
AssertSchemaInclude( expressionRoot );
if( _cases.TryGetValue( label, out ExpBaseNode? op ) ) {
op.AppendNode( expressionRoot );
} else {
throw new ExpCaseNotFoundException( this, label );
}
}
public bool ContainsCase( ExpBaseNode token )
{
return _cases.ContainsKey( token );
}
}
}
@@ -0,0 +1,60 @@
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// file="ExpUnaryOperatorNode.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 class ExpUnaryOperatorNode : ExpBaseNode
{
private ExpBaseNode _operand;
public ExpUnaryOperatorNode(
string name,
ExpBaseNode operand,
ExpSchema context )
: base( name, context )
{
_operand = operand;
}
public override ExpBaseNode Left => null!;
public override ExpBaseNode Right => _operand;
public override IExpElementSource EqualityTypeConvert => _operand.EqualityTypeConvert;
}
}
@@ -52,7 +52,7 @@ namespace StgSharp.Script.Express
}
public abstract class ExpElementInstanceBase : ExpToken
public abstract class ExpElementInstanceBase : ExpBaseNode
{
protected ExpElementInstanceBase( string name, ExpSchema context )
@@ -78,7 +78,7 @@ namespace StgSharp.Script.Express
public abstract void Analyse();
public abstract ExpToken CreateInstanceToken();
public abstract ExpBaseNode CreateInstanceToken();
public abstract bool IsConvertable( IExpElementSource targetType );
@@ -109,7 +109,7 @@ namespace StgSharp.Script.Express
return false;
}
public abstract ExpToken MakeReference( params object[] options );
public abstract ExpBaseNode MakeReference( params object[] options );
}
}
@@ -0,0 +1,135 @@
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// file="ExpExceptions.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.IO;
using System.Text;
namespace StgSharp.Script.Express
{
public class ExpCompileNotInitializedException : InvalidOperationException
{
public ExpCompileNotInitializedException()
: base(
"Attempt to compile an EXPRESS script before the init of compiler." ) { }
}
public class ExpInvalidCharException : Exception
{
public ExpInvalidCharException( char c )
: base( $"An unknown char {c} occurred." ) { }
}
public class ExpInvalidTokenException : Exception
{
public ExpInvalidTokenException( int index )
: base( $"Cannot read a token from line at {index}" ) { }
}
public class ExpInvalidTypeDeclareEndingExceptions : Exception
{
public ExpInvalidTypeDeclareEndingExceptions(
string declaredName,
string endedName )
: base(
$"The datatype is declared with name {declaredName} but ended with {endedName}" ) { }
}
public class ExpInvalidElementNameException : Exception
{
public ExpInvalidElementNameException(
string elementName,
ExpSchema schema )
: base(
$"Cannot find any element named {elementName} in {schema.Name}" ) { }
}
public class ExpInvalidTypeException : InvalidCastException
{
public ExpInvalidTypeException( string required, string provided )
: base(
$"Type {required} is required at position, but a {provided} instance is provided." ) { }
}
public class ExpInvalidCollectionMemberTypeException : InvalidCastException
{
public ExpInvalidCollectionMemberTypeException(
ExpElementInstanceBase elementInstance,
ExpCollectionBase collection )
: base(
$"Attempt to add or remove an element of type: {elementInstance.ElementType} from a collection collects {collection.MemberType}" ) { }
}
public class ExpInvalidSchemaIncludeException : InvalidOperationException
{
public ExpInvalidSchemaIncludeException(
ExpSchema context,
ExpSchema source )
: base(
$"Attempted to reference an EXPRESS language expression in the current schema context '{context.Name}', " + $"but this expression comes from another schema '{source.Name}' that has not been included." ) { }
}
public class ExpCaseNotFoundException : ArgumentOutOfRangeException
{
public ExpCaseNotFoundException(
ExpSwitchNode token,
ExpBaseNode label )
: base(
$"Attempt to read or write the label {label.Name} not exist in SWITCH expression {token.Name}" ) { }
}
public class ExpTypeNotFoundException : Exception
{
public ExpTypeNotFoundException( string typeName, ExpSchema context )
: base(
$"Cannot find the type {typeName} in schema {context.Name} and its included schemas" ) { }
}
}
@@ -34,10 +34,10 @@ using System.Text;
namespace StgSharp.Script.Express
{
public class ExpExpressionTree : AbstractSyntaxTree<ExpToken, IExpElementSource>
public class ExpExpressionTree : AbstractSyntaxTree<ExpBaseNode, IExpElementSource>
{
public ExpToken RootToken
public ExpBaseNode RootToken
{
get;
private set;
@@ -33,36 +33,20 @@ using CommunityToolkit.HighPerformance.Helpers;
using StgSharp.Collections;
using System;
using System.Collections.Frozen;
using System.Collections.Generic;
using System.Text;
namespace StgSharp.Script.Express
{
public class ExpSchema
public class ExpSchema : ExpSchemaBase
{
private readonly ConcurrentStringHashMultiplexer _multiplexer = ExpCompile.Multiplexer;
private Dictionary<string, ExpConstantCollectionSource> _constDict;
private Dictionary<string, ExpEntitySource> _entityDict;
private Dictionary<string, ExpFunctionSource> _functionDict;
private Dictionary<string, ExpRuleSource> _ruleDict;
private Dictionary<string, ExpSchema> _schemaInclude;
private Dictionary<string, ExpTypeSource> _typeDict;
public ExpSchema() { }
public ExpSchema()
public static ExpSchema DefaultSchema
{
_constDict = new Dictionary<string, ExpConstantCollectionSource>(
ExpCompile.Multiplexer );
_entityDict = new Dictionary<string, ExpEntitySource>(
ExpCompile.Multiplexer );
_functionDict = new Dictionary<string, ExpFunctionSource>(
ExpCompile.Multiplexer );
_ruleDict = new Dictionary<string, ExpRuleSource>(
ExpCompile.Multiplexer );
_schemaInclude = new Dictionary<string, ExpSchema>(
ExpCompile.Multiplexer );
_typeDict = new Dictionary<string, ExpTypeSource>(
ExpCompile.Multiplexer );
get => ExpSchema_Nitload.Only;
}
public string Name
@@ -77,11 +61,11 @@ namespace StgSharp.Script.Express
out ExpTypeSource? ret ) ) {
return ret;
}
if( _typeDict.TryGetValue( typeName, out ret ) ) {
if( TypeDict.TryGetValue( typeName, out ret ) ) {
return ret;
}
foreach( ExpSchema item in _schemaInclude.Values ) {
if( item._typeDict.TryGetValue( typeName, out ret ) ) {
foreach( ExpSchema item in SchemaInclude.Values ) {
if( item.TypeDict.TryGetValue( typeName, out ret ) ) {
return ret;
}
}
@@ -90,7 +74,7 @@ namespace StgSharp.Script.Express
public bool HasSchemaInclude( ExpSchema schema )
{
return _schemaInclude.ContainsKey( schema.Name );
return SchemaInclude.ContainsKey( schema.Name );
}
public bool TryGetConstant(
@@ -101,7 +85,7 @@ namespace StgSharp.Script.Express
out constInstance ) ) {
return true;
}
foreach( ExpConstantCollectionSource item in _constDict.Values ) {
foreach( ExpConstantCollectionSource item in ConstDict.Values ) {
if( item.TryGetConstant( name, out constInstance ) ) {
return true;
}
@@ -0,0 +1,109 @@
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// file="ExpSchemaBase.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.Collections;
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 abstract class ExpSchemaBase
{
public void LoadFromSource( ExpSchemaSource source )
{
ConstDict = source.
}
public abstract bool TryGetConst( string name, out ExpBaseNode c );
public abstract bool TryGetEntity( string name, out ExpEntitySource e );
public abstract bool TryGetFunction(
string name,
out ExpFunctionSource f );
public abstract bool TryGetRule( string name, out ExpRuleSource r );
public abstract bool TryGetSchemaInclude(
string name,
out ExpSchema include );
public abstract bool TryGetType(
string name,
out ExpTypeSource element );
#pragma warning disable CS8618
protected FrozenDictionary<string, ExpConstantCollectionSource> ConstDict
{
get;
set;
}
protected FrozenDictionary<string, ExpEntitySource> EntityDict
{
get;
set;
}
protected FrozenDictionary<string, ExpFunctionSource> FunctionDict
{
get;
set;
}
protected ConcurrentStringHashMultiplexer Multiplexer => ExpCompile.Multiplexer;
protected FrozenDictionary<string, ExpRuleSource> RuleDict
{
get;
set;
}
protected FrozenDictionary<string, ExpSchema> SchemaInclude
{
get;
set;
}
protected FrozenDictionary<string, ExpTypeSource> TypeDict
{
get;
set;
}
#pragma warning restore CS8618
}
}
@@ -44,10 +44,32 @@ namespace StgSharp.Script.Express
public partial class ExpSchemaSource
{
private Dictionary<string, IExpElementSource> _sourceCache = new();
private static Regex
_constDefineBegin = GetConstDefineBegin(),
_constDefineEnd = GetConstDefineEnd(),
_schemaBegin = GetSchemaBegin(),
_schemaEnd = GetSchemaEnd(),
_entityDefineBegin = GetEntityDefineBegin(),
_entityDefineEnd = GetEntityDefineEnd(),
_typeDefineBegin = GetTypeDefineBegin(),
_typeDefineEnd = new Regex(
@"\s*END_TYPE\s*;\s*--\s*(?<TypeName>[a-zA-Z0-9_]+)",
RegexOptions.Compiled ),
_functionDefineBegin = new Regex(
@"\s*FUNCTION\s*\s*(?<FunctionName>[a-zA-Z0-9_]+)\s*(?<Remaining>.*)",
RegexOptions.Compiled ),
_functionDefineEnd = new Regex(
@"\s*END_FUNCTION\s*;\s*--\s*(?<FunctionName>[a-zA-Z0-9_]+)",
RegexOptions.Compiled ),
_ruleDefineBegin = new Regex(
@"\s*RULE\s*(?<RuleName>[a-zA-Z0-9_]+)\s*FOR\s*\((?<Target>[a-zA-Z0-9_]*(\s*\)\s*;)?)",
RegexOptions.Compiled ),
_ruleDefineEnd = GetRuleDefineEnd();
private readonly ExpSchema _compileResult = new ExpSchema();
private List<IExpElementSource> _sourceCache = new();
private string name;
public ExpSchemaSource() { }
@@ -69,15 +91,15 @@ namespace StgSharp.Script.Express
while( !_schemaEnd.IsMatch( line ) ) {
if( TryReadConst( line, reader,
out IExpElementSource source ) ) {
_sourceCache.Add( source.Name, source );
_sourceCache.Add( source );
} else if( TryReadType( line, reader, out source ) ) {
_sourceCache.Add( source.Name, source );
_sourceCache.Add( source );
} else if( TryReadEntity( line, reader, out source ) ) {
_sourceCache.Add( source.Name, source );
_sourceCache.Add( source );
} else if( TryReadRule( line, reader, out source ) ) {
_sourceCache.Add( source.Name, source );
_sourceCache.Add( source );
} else if( TryReadFunction( line, reader, out source ) ) {
_sourceCache.Add( source.Name, source );
_sourceCache.Add( source );
}
line = reader.ReadLine();
}
@@ -99,24 +121,19 @@ namespace StgSharp.Script.Express
if( _source.TryReadConst(
firstLine, reader,
out IExpElementSource _elementSource ) ) {
_source._sourceCache
.Add( _elementSource.Name, _elementSource );
_source._sourceCache.Add( _elementSource );
} else if( _source.TryReadType(
firstLine, reader, out _elementSource ) ) {
_source._sourceCache
.Add( _elementSource.Name, _elementSource );
_source._sourceCache.Add( _elementSource );
} else if( _source.TryReadEntity(
firstLine, reader, out _elementSource ) ) {
_source._sourceCache
.Add( _elementSource.Name, _elementSource );
_source._sourceCache.Add( _elementSource );
} else if( _source.TryReadRule(
firstLine, reader, out _elementSource ) ) {
_source._sourceCache
.Add( _elementSource.Name, _elementSource );
_source._sourceCache.Add( _elementSource );
} else if( _source.TryReadFunction(
firstLine, reader, out _elementSource ) ) {
_source._sourceCache
.Add( _elementSource.Name, _elementSource );
_source._sourceCache.Add( _elementSource );
}
firstLine = reader.ReadLine();
}
@@ -130,9 +147,34 @@ namespace StgSharp.Script.Express
[GeneratedRegex( @"\s*END_CONSTANT;" )]
private static partial Regex GetConstDefineEnd();
[GeneratedRegex(
@"\s*ENTITY\s*(?<TypeName>[A-Za-z0-9_]+)\s*",
RegexOptions.Compiled )]
private static partial Regex GetEntityDefineBegin();
[GeneratedRegex(
@"\s*END_ENTITY;\s*--\s*(?<TypeName>[A-Za-z0-9_]+)\s*",
RegexOptions.Compiled )]
private static partial Regex GetEntityDefineEnd();
[GeneratedRegex(
@"\s*END_RULE\s*;\s*--\s*(?<RuleName>[A-Za-z0-9_]+)",
RegexOptions.Compiled )]
private static partial Regex GetRuleDefineEnd();
[GeneratedRegex( @"\s*SCHEMA\s*(?<namespace>[A-Za-z0-9_]+)\s?;" )]
private static partial Regex GetSchemaBegin();
[GeneratedRegex(
@"END_SCHEMA;\s*--\s*(?<namespace>[A-Za-z0-9_]+)",
RegexOptions.Compiled )]
private static partial Regex GetSchemaEnd();
[GeneratedRegex(
@"\s*TYPE\s+(?<TypeName>[A-Za-z0-9_]+)\s*=\s*(?<Remaining>[A-Z]+)",
RegexOptions.Compiled )]
private static partial Regex GetTypeDefineBegin();
private bool TryReadConst(
string firstLine,
ExpFileSource reader,
@@ -287,37 +329,5 @@ namespace StgSharp.Script.Express
return false;
}
private static Regex
_constDefineBegin = GetConstDefineBegin(),
_constDefineEnd = GetConstDefineEnd(),
_schemaBegin = GetSchemaBegin(),
_schemaEnd = new Regex(
@"END_SCHEMA;\s*--\s*(?<namespace>[A-Za-z0-9_]+)",
RegexOptions.Compiled ),
_entityDefineBegin = new Regex(
@"\s*ENTITY\s*(?<TypeName>[A-Za-z0-9_]+)\s*",
RegexOptions.Compiled ),
_entityDefineEnd = new Regex(
@"\s*END_ENTITY;\s*--\s*(?<TypeName>[A-Za-z0-9_]+)\s*",
RegexOptions.Compiled ),
_typeDefineBegin = new Regex(
@"\s*TYPE\s+(?<TypeName>[A-Za-z0-9_]+)\s*=\s*(?<Remaining>[A-Z]+)",
RegexOptions.Compiled ),
_typeDefineEnd = new Regex(
@"\s*END_TYPE\s*;\s*--\s*(?<TypeName>[a-zA-Z0-9_]+)",
RegexOptions.Compiled ),
_functionDefineBegin = new Regex(
@"\s*FUNCTION\s*\s*(?<FunctionName>[a-zA-Z0-9_]+)\s*(?<Remaining>.*)",
RegexOptions.Compiled ),
_functionDefineEnd = new Regex(
@"\s*END_FUNCTION\s*;\s*--\s*(?<FunctionName>[a-zA-Z0-9_]+)",
RegexOptions.Compiled ),
_ruleDefineBegin = new Regex(
@"\s*RULE\s*(?<RuleName>[a-zA-Z0-9_]+)\s*FOR\s*\((?<Target>[a-zA-Z0-9_]*(\s*\)\s*;)?)",
RegexOptions.Compiled ),
_ruleDefineEnd = new Regex(
@"\s*END_RULE\s*;\s*--\s*(?<RuleName>[A-Za-z0-9_]+)",
RegexOptions.Compiled );
}
}
@@ -53,7 +53,13 @@ namespace StgSharp.Script.Express
private bool _isReadingMultiLineComment;
private int _current, _lineNum;
private IScriptSourceProvider _provider;
private Regex _nextWordTokenPattern = GetNextWordTokenPattern(),
_nextStringLiteralPattern = GetStringLiteralPattern(),
_nextNumberLiteralPattern = GetNumberLiteralPattern(),
_skipBlankPattern = GetSkipBlankPattern();
private string _lineCache;
private Token _last;
public ExpSourceReader( IScriptSourceProvider provider )
{
@@ -75,10 +81,10 @@ namespace StgSharp.Script.Express
}
/// <summary>
/// <para> Read code until end of a line. Lines in multi-line comment will be ignored. Line
/// <para>Read code until end of a line. Lines in multi-line comment will be ignored. Line
/// begins with part of multi-line comment will automatically remove the comment part, but
/// beginning with a full multi-line comment will not causing removing. </para> <para>(*Just
/// Like The Comment Here*) Will Not Be Removed</para>
/// beginning with a full multi-line comment will not causing removing.</para> <para> (*Just
/// Like The Comment Here*) Will Not Be Removed </para>
/// </summary>
/// <returns></returns>
public unsafe ReadOnlySpan<char> ReadLine()
@@ -111,7 +117,7 @@ namespace StgSharp.Script.Express
return _lineCache.AsSpan().Slice( _current );
}
public unsafe TokenSource ReadToken()
public unsafe Token ReadToken()
{
int begin, end, rest;
readLine:
@@ -126,9 +132,10 @@ namespace StgSharp.Script.Express
end = match.Groups[ End ].Index;
rest = match.Groups[ Rest ].Index;
_current = rest;
return new(
source[ .. ( end - begin ) ], _lineNum, begin,
PreprocessingMask.Names );
_last = new(
ExpCompile.PoolString( source[ .. ( end - begin ) ] ),
_lineNum, begin, TokenFlag.Member );
return _last;
} else {
throw new ExpInvalidTokenException( _current );
}
@@ -141,8 +148,8 @@ namespace StgSharp.Script.Express
begin = _current;
_current += 2;
return new(
ReadOnlySpan<char>.Empty, _lineNum, begin,
PreprocessingMask.String );
string.Empty, _lineNum, begin,
TokenFlag.String );
}
Match match = _nextStringLiteralPattern.Match(
_lineCache, _current );
@@ -151,9 +158,11 @@ namespace StgSharp.Script.Express
end = match.Groups[ "end" ].Index;
rest = match.Groups[ "rest" ].Index;
_current = rest;
return new(
source[ 1..( end - begin ) ], _lineNum, begin,
PreprocessingMask.String );
_last = new(
ExpCompile.PoolString(
source[ 1..( end - begin ) ] ),
_lineNum, begin, TokenFlag.String );
return _last;
} else {
throw new ExpInvalidCharException( '\"' );
}
@@ -166,15 +175,24 @@ namespace StgSharp.Script.Express
} else {
begin = _current;
_current++;
return new(
source[ ..1 ], _lineNum, begin,
PreprocessingMask.Symbol );
_last = new(
ExpCompile.PoolString( source[ ..1 ] ),
_lineNum, begin, TokenFlag.Separator_Left );
return _last;
}
case ')' or '}':
begin = _current;
_current++;
_last = new Token(
ExpCompile.PoolString( ")" ), _lineNum, begin,
TokenFlag.Separator_Right );
return _last;
case '-':
// 1. -number
// 2. -- comment
// 3. - number type param
// 3. - number type param(UNARY)
// 4. param - param(BINARY)
cNext = source[ 1 ];
if( char.IsNumber( cNext ) ) {
match = _nextNumberLiteralPattern.Match(
@@ -185,8 +203,9 @@ namespace StgSharp.Script.Express
rest = match.Groups[ Rest ].Index;
_current = rest;
return new(
source[ ..( end - begin ) ], _lineNum,
begin, PreprocessingMask.Number );
ExpCompile.PoolString(
source[ ..( end - begin ) ] ),
_lineNum, begin, TokenFlag.Number );
} else {
throw new ExpInvalidTokenException( _current );
}
@@ -197,17 +216,47 @@ namespace StgSharp.Script.Express
} else {
begin = _current;
_current++;
return new(
source[ ..1 ], _lineNum, begin,
PreprocessingMask.Symbol );
if( _last.Flag != TokenFlag.Member ) {
_last = new(
ExpCompile.PoolString( source[ ..1 ] ),
_lineNum, begin, TokenFlag.Symbol_Unary );
} else {
_last = new(
ExpCompile.PoolString( source[ ..1 ] ),
_lineNum, begin, TokenFlag.Symbol_Binary );
}
case ')' or '[' or ']' or '{' or '}' or ':' or ';' or
'+' or '/' or '\\' or '*' or '.' or ',':
return _last;
}
case '{':
begin = _current;
_current++;
return new Token(
ExpCompile.PoolString( "{" ), _lineNum, begin,
TokenFlag.Separator_Left );
case '[':
begin = _current;
_current++;
return new Token(
ExpCompile.PoolString( "[" ), _lineNum, begin,
TokenFlag.Index_Left );
case ']':
begin = _current;
_current++;
return new Token(
ExpCompile.PoolString( "]" ), _lineNum, begin,
TokenFlag.Index_Right );
case ';' or ',':
begin = _current;
_current++;
return new Token(
ExpCompile.PoolString( source[ ..1 ] ), _lineNum,
begin, TokenFlag.Separator_Single );
case ':' or '+' or '/' or '\\' or '*' or '.':
begin = _current;
_current++;
return new(
source[ ..1 ], _lineNum, begin,
PreprocessingMask.Symbol );
ExpCompile.PoolString( source[ ..1 ] ), _lineNum,
begin, TokenFlag.Symbol_Binary );
default:
throw new ExpInvalidCharException( c );
}
@@ -219,9 +268,16 @@ namespace StgSharp.Script.Express
end = match.Groups[ End ].Index;
rest = match.Groups[ Rest ].Index;
_current = rest;
return new(
source[ ..( end - begin ) ], _lineNum, begin,
PreprocessingMask.Number );
string str = ExpCompile.PoolString(
source[ ..( end - begin ) ] );
TokenFlag flag;
if( ReferenceEquals( str, ExpCompile.KeyWord.NOT ) ) {
flag = TokenFlag.Symbol_Unary;
} else {
flag = ExpCompile.LetterIsOperator( str ) ?
TokenFlag.Symbol_Binary : TokenFlag.Member;
}
return new( str, _lineNum, begin, flag );
} else {
throw new ExpInvalidTokenException( _current );
}
@@ -257,10 +313,5 @@ namespace StgSharp.Script.Express
RegexOptions.Singleline )]
private static partial Regex GetStringLiteralPattern();
private Regex _nextWordTokenPattern = GetNextWordTokenPattern(),
_nextStringLiteralPattern = GetStringLiteralPattern(),
_nextNumberLiteralPattern = GetNumberLiteralPattern(),
_skipBlankPattern = GetSkipBlankPattern();
}
}
@@ -0,0 +1,55 @@
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// file="ExpErrorThrow.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 partial class ExpNodeGenerator
{
public void ThrowCompileException( int errorCode )
{
switch( errorCode ) {
case 0 or 1:
return;
case TokenTypeNotMatch:
throw new Exception();
default:
break;
}
}
}
}
@@ -0,0 +1,155 @@
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// file="ExpNodeGenerator.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.Threading;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace StgSharp.Script.Express
{
public partial class ExpNodeGenerator
{
private const int EndLine = 1;
private const int TokenGenerated = 0;
private const int TokenTypeNotMatch = -1;
private ExpBaseNode _lastStatement;
private ExpSchema _context;
private IExpElementSource _local;
private List<ExpBaseNode> _cache;
private Stack<ExpBaseNode> _operandsNode;
private Stack<Token> _operandsToken;
private Stack<Token> _operators;
public ExpNodeGenerator()
{
_operators = new Stack<Token>();
_operandsToken = new Stack<Token>();
}
/// <summary>
/// Append a token to top of cache. This method will automatically convert token to node if
/// meets separators or operators.
/// </summary>
/// <param name="expToken"></param>
public void AppendToken( Token expToken )
{
switch( expToken.Flag ) {
case TokenFlag.Symbol_Unary or TokenFlag.Symbol_Binary:
_operandsToken.Push( expToken );
break;
case TokenFlag.Number or TokenFlag.String or TokenFlag.Member:
break;
case TokenFlag.Separator_Single:
break;
case TokenFlag.Separator_Left:
break;
case TokenFlag.Separator_Right:
break;
case TokenFlag.Index_Left:
break;
case TokenFlag.Index_Right:
break;
default:
break;
}
}
public void CacheNextOperandNode( ExpBaseNode node )
{
_operandsNode.Push( node );
}
public AbstractSyntaxTree<ExpBaseNode, IExpElementSource> CloseAndDispose(
)
{
if( _operandsToken.Count != 0 ) {
// convert rest to AST
}
return new AbstractSyntaxTree<ExpBaseNode, IExpElementSource>();
}
public ExpBaseNode GenerateNode( Token t )
{
switch( t.Flag ) {
case TokenFlag.Symbol_Unary:
break;
case TokenFlag.Symbol_Binary:
break;
case TokenFlag.Number:
break;
case TokenFlag.String:
break;
case TokenFlag.Member:
break;
case TokenFlag.Separator_Single:
break;
case TokenFlag.Separator_Left:
break;
case TokenFlag.Separator_Right:
break;
case TokenFlag.Index_Left:
break;
case TokenFlag.Index_Right:
break;
default:
break;
}
}
public int GetNextOperandCache(
out Token? token,
out ExpBaseNode? node )
{
if( _operandsNode.Count != 0 ) {
node = _operandsNode.Pop();
token = null!;
return 2;
}
if( _operandsToken.Count != 0 ) {
token = _operandsToken.Pop();
node = null!;
return 1;
}
token = null;
node = null!;
return 0;
}
}
}
@@ -0,0 +1,57 @@
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// file="GenerateUnaryToken.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 partial class ExpNodeGenerator
{
public ExpBaseNode GenerateUnaryToken( Token t )
{
switch( t.Value ) {
case ExpCompile.KeyWord.UnaryAdd:
break;
case ExpCompile.KeyWord.UnarySub:
break;
case ExpCompile.KeyWord.NOT:
break;
default:
break;
}
}
}
}
@@ -0,0 +1,67 @@
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// file="LeftSperatorProcess.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.Runtime.CompilerServices;
using System.Security.Cryptography.X509Certificates;
using System.Text;
using System.Threading.Tasks;
namespace StgSharp.Script.Express
{
public partial class ExpNodeGenerator
{
private int _lbToken = 0; // [ count
private int _lcbCount = 0; // { count
private int _lpCount = 0; // ( count
private void ProcessLeftSeparator( Token t )
{
switch( t.Value ) {
case "[":
_lbToken++;
break;
case "{":
_lcbCount++;
break;
case "(":
_lpCount++;
break;
default:
break;
}
}
}
}
@@ -0,0 +1,97 @@
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// file="ExpNodeFlag.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
{
[Flags]
public enum ExpNodeFlag : long
{
//string as name of non-builtin variables
None = 0,
Name_Element = 1,
Name_Param = 2,
Name_Block = 4,
Name_Keyword = 8,
Name_Operator = 16,
Name_Any = Name_Block | Name_Element | Name_Keyword | Name_Param | Name_Operator,
//any type of collections, also has NAME flag
Collection_Set = 32,
Collection_Bag = 64,
Collection_Array = 128,
Collection_List = 256,
Collection_Any = Collection_Set | Collection_Bag | Collection_Array | Collection_List,
//the variable is type of element, both builtin and non-builtin has this flag
Element_Const = 512,
Element_Entity = 1024,
Element_Type = 2048,
Element_Rule = 4096,
Element_Function = 8192,
Element_Any = Element_Entity | Element_Const | Element_Function | Element_Rule | Element_Type,
//variable is one of these builtin type
BuiltinType_Int = 16384,
BuiltinType_Float = 32768,
BuiltinType_String = 65536,
BuiltinType_Boolean = 0x2000,
BuiltinType_Binary = 0x4000,
BuiltinType_Logic = 0x8000,
BuiltinType_Number = BuiltinType_Float | BuiltinType_Int,
BuiltinType_Any = BuiltinType_Int | BuiltinType_Float | BuiltinType_String | BuiltinType_Boolean | BuiltinType_Binary | BuiltinType_Logic,
//the token is root of a branch
Branch_If = 0x1_000,
Branch_Switch = 0x2_0000,
Branch_Repeat = 0x4_0000,
Branch_Any = Branch_If | Branch_Repeat | Branch_Switch,
//the token is one of separators
Separator_Inline = 0x8_0000, //, or sth else
Separator_Line = 0x10_0000, //; or eth else
Separator_Block = 0x20_0000, //{}or sth else
Separator_Range = 0x40_0000, //()or sth else
Separator_Any = Separator_Inline | Separator_Line | Separator_Block | Separator_Range,
//the token is a kind of operator
Operator_Unary = 0x40_0000,
Operator_Binary = 0x80_0000,
Operator_SuperType = 0x100_0000,
Operator_Any = Operator_Unary | Operator_Binary | Operator_SuperType,
}
}
@@ -0,0 +1,78 @@
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// file="ExpNodeNextEnumerator.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.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace StgSharp.Script.Express
{
public class ExpNodeNextEnumerator : IEnumerator<ExpBaseNode>
{
private ExpBaseNode _begin;
private ExpBaseNode _current;
public ExpNodeNextEnumerator( ExpBaseNode token )
{
_begin = token;
_current = token;
}
void IDisposable.Dispose()
{
return;
}
bool IEnumerator.MoveNext()
{
ExpBaseNode next = _current.Next;
if( ReferenceEquals( next, _begin ) || next == null ) {
return false;
}
_current = next;
return true;
}
void IEnumerator.Reset()
{
_current = _begin;
}
object IEnumerator.Current => throw new NotImplementedException();
ExpBaseNode IEnumerator<ExpBaseNode>.Current => throw new NotImplementedException(
);
}
}
@@ -0,0 +1,85 @@
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// file="IASTNode.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.Collections;
using StgSharp.Script.Express;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;
namespace StgSharp.Script
{
public interface IASTNode<TNode, TType> where TNode: IASTNode<TNode, TType>
where TType: ITypeSource<TType>
{
long TokenTypeCode
{
get;
}
string Name
{
get;
}
TNode Previous
{
get;
set;
}
TNode Next
{
get;
set;
}
TNode Left
{
get;
}
TNode Right
{
get;
}
TType EqualityTypeConvert
{
get;
}
void AppendNode( TNode nextToken );
}
}
@@ -50,13 +50,15 @@ namespace StgSharp.Script
void EndWriting();
string ReadLine();
string ReadLine(out int position);
string ReadLine( out int position );
/// <summary>
/// Return part of current provider.
/// </summary>
/// <param name="count">Count of lines to be sliced</param>
/// <param name="count"> Count of lines to be sliced </param>
/// <returns></returns>
public IScriptSourceProvider Slice(int location, int count);
public IScriptSourceProvider Slice( int location, int count );
}
}
@@ -40,7 +40,6 @@ namespace StgSharp.Script
where TConvert: ITypeSource<TConvert>
{
bool IsConvertable( TConvert targetType );
}
+76
View File
@@ -0,0 +1,76 @@
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
// file="Token.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
{
public readonly struct Token
{
public readonly int Column;
public readonly int Line;
public readonly string Value;
public readonly TokenFlag Flag;
public Token(
string chars,
int lineNumber,
int columnNumber,
TokenFlag flag )
{
Value = chars;
Line = lineNumber;
Column = columnNumber;
Flag = flag;
}
}
public enum TokenFlag : int
{
Symbol_Unary = 1,
Symbol_Binary = 2,
Number = 3,
String = 4,
Member = 5,
Separator_Single = 6,
Separator_Left = 7,
Separator_Right = 8,
Index_Left = 9,
Index_Right = 10,
}
}
@@ -0,0 +1,4 @@
// <autogenerated />
using System;
using System.Reflection;
[assembly: global::System.Runtime.Versioning.TargetFrameworkAttribute(".NETCoreApp,Version=v8.0", FrameworkDisplayName = ".NET 8.0")]
@@ -0,0 +1,22 @@
//------------------------------------------------------------------------------
// <auto-generated>
// This code was generated by a tool.
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------
using System;
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+ccef0de6f686f94da655b0e7d854d0acaf907d04")]
[assembly: System.Reflection.AssemblyProductAttribute("StgSharp.Script")]
[assembly: System.Reflection.AssemblyTitleAttribute("StgSharp.Script")]
[assembly: System.Reflection.AssemblyVersionAttribute("1.0.0.0")]
// 由 MSBuild WriteCodeFragment 类生成。
@@ -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+c23b640cae59b9ee7dcfd8f026b8970a084ddbd7")]
[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+ccef0de6f686f94da655b0e7d854d0acaf907d04")]
[assembly: System.Reflection.AssemblyProductAttribute("StgSharp.Script")]
[assembly: System.Reflection.AssemblyTitleAttribute("StgSharp.Script")]
[assembly: System.Reflection.AssemblyVersionAttribute("1.0.0.0")]
@@ -1 +1 @@
{"documents":{"D:\\NitloadIndustry\\研究项目\\1-Flagship\\TH2020\\ProjectFile\\*":"https://raw.githubusercontent.com/Nitload-NSI/CCD_Github/c23b640cae59b9ee7dcfd8f026b8970a084ddbd7/*"}}
{"documents":{"D:\\NitloadIndustry\\研究项目\\1-Flagship\\TH2020\\ProjectFile\\*":"https://raw.githubusercontent.com/Nitload-NSI/CCD_Github/ccef0de6f686f94da655b0e7d854d0acaf907d04/*"}}
@@ -1,10 +1,9 @@
//------------------------------------------------------------------------------
// <auto-generated>
// 此代码由工具生成。
// 运行时版本:4.0.30319.42000
// This code was generated by a tool.
//
// 对此文件的更改可能会导致不正确的行为,并且如果
// 重新生成代码,这些更改将会丢失。
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------
@@ -14,7 +13,7 @@ using System.Reflection;
[assembly: System.Reflection.AssemblyCompanyAttribute("StgSharp.TerminalDialogue")]
[assembly: System.Reflection.AssemblyConfigurationAttribute("Debug")]
[assembly: System.Reflection.AssemblyFileVersionAttribute("1.0.0.0")]
[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+e687473132786f419a48170313782d6779890c3d")]
[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+ccef0de6f686f94da655b0e7d854d0acaf907d04")]
[assembly: System.Reflection.AssemblyProductAttribute("StgSharp.TerminalDialogue")]
[assembly: System.Reflection.AssemblyTitleAttribute("StgSharp.TerminalDialogue")]
[assembly: System.Reflection.AssemblyVersionAttribute("1.0.0.0")]
@@ -14,7 +14,7 @@ using System.Reflection;
[assembly: System.Reflection.AssemblyCompanyAttribute("StgSharp.TerminalDialogue")]
[assembly: System.Reflection.AssemblyConfigurationAttribute("Debug")]
[assembly: System.Reflection.AssemblyFileVersionAttribute("1.0.0.0")]
[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+ae94c265ae77870ea6498b624b6f71b78fb94e51")]
[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+ccef0de6f686f94da655b0e7d854d0acaf907d04")]
[assembly: System.Reflection.AssemblyProductAttribute("StgSharp.TerminalDialogue")]
[assembly: System.Reflection.AssemblyTitleAttribute("StgSharp.TerminalDialogue")]
[assembly: System.Reflection.AssemblyVersionAttribute("1.0.0.0")]
+31 -38
View File
@@ -52,55 +52,50 @@ namespace StgSharp
internal static class Program
{
static string testExpPath = @"D:\Programmer\stepcode\data\ap203\ap203.exp";
private static string testExpPath = @"D:\Programmer\stepcode\data\ap203\ap203.exp";
internal static unsafe void Main( string[] args )
{
try
{
try {
StgSharp.Init();
ExpCompile.InitCompile();
ExpFileSource reader = new ExpFileSource(testExpPath);
ExpFileSource reader = new ExpFileSource( testExpPath );
ExpSchemaSource schemaSource = new ExpSchemaSource();
schemaSource.ReadSchema(reader);
schemaSource.ReadSchema( reader );
ScriptSourceTransmitter st = new ScriptSourceTransmitter("end", 0);
for (int i = 0; i < 10; i++)
{
ScriptSourceTransmitter st = new ScriptSourceTransmitter(
"end", 0 );
for( int i = 0; i < 10; i++ ) {
string str = $"rawCode () (\"\") {i}";
Console.WriteLine(str);
st.WriteLine(str);
Console.WriteLine( str );
st.WriteLine( str );
}
for (int i = 0; i < 10; i++)
{
for( int i = 0; i < 10; i++ ) {
string str = $"Code{i} {new string(' ', i + 1)}-- Comment{i}";
Console.WriteLine(str);
st.WriteLine(str);
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++)
{
var str = $" Code{i} (* (* Comment{i} *) *) Code{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);
st.WriteLine( "end" );
ExpSourceReader sr = new ExpSourceReader( st );
int count = 0;
while (!sr.IsEmpty)
{
while( !sr.IsEmpty ) {
count++;
var str = sr.ReadToken();
Console.WriteLine($"{count}\t{str.Mask}\t\t{str.Value.ToString()}");
Token str = sr.ReadToken();
Console.WriteLine(
$"{count}\t{str.Flag}\t\t{str.Value.ToString()}" );
}
var slice = st.Slice(5, 2);
IScriptSourceProvider slice = st.Slice( 5, 2 );
/*
@@ -130,20 +125,18 @@ namespace StgSharp
return;
}
catch (Exception ex)
{
catch( Exception ) {
throw;
/*
StgSharp.WriteLog($"{ex}", LogType.Error);
if( true ) { }
Dialogue.PostError( ex );
/**/
Environment.Exit(-1);
Environment.Exit( -1 );
/**/
}
finally
{
}
finally { }
}
}
}
@@ -0,0 +1,4 @@
// <autogenerated />
using System;
using System.Reflection;
[assembly: global::System.Runtime.Versioning.TargetFrameworkAttribute(".NETCoreApp,Version=v8.0", FrameworkDisplayName = ".NET 8.0")]
@@ -0,0 +1,22 @@
//------------------------------------------------------------------------------
// <auto-generated>
// This code was generated by a tool.
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------
using System;
using System.Reflection;
[assembly: System.Reflection.AssemblyCompanyAttribute("StgSharpDebug")]
[assembly: System.Reflection.AssemblyConfigurationAttribute("Debug")]
[assembly: System.Reflection.AssemblyFileVersionAttribute("1.0.0.0")]
[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+ccef0de6f686f94da655b0e7d854d0acaf907d04")]
[assembly: System.Reflection.AssemblyProductAttribute("StgSharpDebug")]
[assembly: System.Reflection.AssemblyTitleAttribute("StgSharpDebug")]
[assembly: System.Reflection.AssemblyVersionAttribute("1.0.0.0")]
// 由 MSBuild WriteCodeFragment 类生成。
@@ -0,0 +1,8 @@
// <auto-generated/>
global using global::System;
global using global::System.Collections.Generic;
global using global::System.IO;
global using global::System.Linq;
global using global::System.Net.Http;
global using global::System.Threading;
global using global::System.Threading.Tasks;
@@ -14,7 +14,7 @@ using System.Reflection;
[assembly: System.Reflection.AssemblyCompanyAttribute("StgSharpDebug")]
[assembly: System.Reflection.AssemblyConfigurationAttribute("Debug")]
[assembly: System.Reflection.AssemblyFileVersionAttribute("1.0.0.0")]
[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+c23b640cae59b9ee7dcfd8f026b8970a084ddbd7")]
[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+ccef0de6f686f94da655b0e7d854d0acaf907d04")]
[assembly: System.Reflection.AssemblyProductAttribute("StgSharpDebug")]
[assembly: System.Reflection.AssemblyTitleAttribute("StgSharpDebug")]
[assembly: System.Reflection.AssemblyVersionAttribute("1.0.0.0")]