diff --git a/BaseTypes b/BaseTypes new file mode 100644 index 0000000..64949d5 --- /dev/null +++ b/BaseTypes @@ -0,0 +1,7 @@ +Null +Real +Complex +Int +Bit +R2 +C2 \ No newline at end of file diff --git a/Nocturnis.csproj b/Nocturnis.csproj index a8d5f6b..6147dca 100644 --- a/Nocturnis.csproj +++ b/Nocturnis.csproj @@ -3,7 +3,7 @@ net6.0 enable - enable + disable @@ -11,6 +11,7 @@ + @@ -18,5 +19,7 @@ - + + + diff --git a/src/Communicators/IBaseCommunicator.cs b/src/Communicators/IBaseCommunicator.cs index 1a75691..b9e1fbe 100644 --- a/src/Communicators/IBaseCommunicator.cs +++ b/src/Communicators/IBaseCommunicator.cs @@ -1,5 +1,7 @@ using Godot; using Nocturnis.DataStructures; +using Nocturnis.DataStructures.Data; +using Nocturnis.DataStructures.DataTypes; using Nocturnis.Enigmos.Modules; namespace Nocturnis.Communicators; @@ -7,8 +9,8 @@ namespace Nocturnis.Communicators; public interface IBaseCommunicator { ICommunicateModule PairedModule { get; set; } - IData DataBuffer { get; set; } - StringName CommunicationDataType { get; } + DataVariable DataBuffer { get; set; } + DataType CommunicationDataType { get; } StringName CommunicationDirection { get; } Texture2D IconTexture { get; } string CustomName { get; set; } diff --git a/src/DataStructures/Data/DataVariable.cs b/src/DataStructures/Data/DataVariable.cs new file mode 100644 index 0000000..a7c8386 --- /dev/null +++ b/src/DataStructures/Data/DataVariable.cs @@ -0,0 +1,89 @@ +using System.Numerics; +using Godot; +using Nocturnis.DataStructures.DataTypes; +using Nocturnis.GlobalManagement.Constants; +using Skeleton.Algebra; +using Skeleton.Algebra.DimensionProviders; + +namespace Nocturnis.DataStructures.Data; +using R2 = CategoryOf.OnField.FVector; +using C2 = CategoryOf.OnField.FVector; + +public class DataVariable +{ + public DataVariable() + { + Data = null; + Type = new DataType(); + Type.Assign(DataTypeConstant.BaseDataTypes.Null); + } + + public void Assign(DataVariable oth) + { + Data = oth.Data; + Type.Assign(oth.Type); + } + + public void Assign(object v, DataType t) + { + Data = v; + Type.Assign(t); + } + + public object Data { get; set; } + public DataType Type { get; set; } + //StringName? Type { get; set; } + int Int + { + get => (int)Data; + set => Data = value; + } + + public double Real + { + get => (double)Data; + set => Data = value; + } + + public Complex Complex + { + get => (Complex)Data; + set => Data = value; + } + + public DataVariable[] Array + { + get => Data as DataVariable[]; + set => Data = value; + } + + public R2 R2 + { + get => Data as R2; + set => Data = value; + } + + public C2 C2 + { + get => Data as C2; + set => Data = value; + } + + public bool Bit + { + get => (bool)Data; + set => Data = value; + } + + public string String + { + get => Data as string; + set => Data = value; + } + + public Dictionary Struct + { + get => Data as Dictionary; + set => Data = value; + } +} \ No newline at end of file diff --git a/src/DataStructures/DataCache.cs b/src/DataStructures/DataCache.cs index 34606a3..851f01a 100644 --- a/src/DataStructures/DataCache.cs +++ b/src/DataStructures/DataCache.cs @@ -1,30 +1,33 @@ using Godot; +using Nocturnis.DataStructures.Data; +using Nocturnis.DataStructures.DataTypes; +using Nocturnis.GlobalManagement.Constants; using Nocturnis.GlobalManagement.Providers; using Skeleton.DataStructure; namespace Nocturnis.DataStructures; -public class DataCache : CacheItem +public class DataCache : CacheItem { - public new static DataCache Null => new DataCache(x => (0, "")); - public DataCache(Func rec) : base(rec) => throw new Exception("CONSTRUCTION NOT ALLOWED"); + public new static DataCache Null => new (x => (0, GlobalProvider.DataStructureProvider!.NullDataType)); + public DataCache(Func rec) : base(rec) => throw new Exception("CONSTRUCTION NOT ALLOWED"); - public DataCache(Func rec) + public DataCache(Func rec) { - Value = GlobalProvider.DataStructureProvider!.NewData(0, ""); + Value = GlobalProvider.DataStructureProvider!.NewData(0, DataTypeConstant.BaseDataTypes.Null); ProxyCalculator = rec; } - private new Func ProxyCalculator { get; set; } + private new Func ProxyCalculator { get; set; } - public override IData? Get + public override DataVariable Get { get { if (Expired) { - (object val, StringName type) = ProxyCalculator(this); - Value!.Type = type; + (object val, DataType type) = ProxyCalculator(this); + Value!.Type.Assign(type); Value.Data = val; } @@ -32,7 +35,7 @@ public class DataCache : CacheItem } } - public void UpdateCalculation(Func rec) + public void UpdateCalculation(Func rec) { Expire(); foreach (CacheItem item in Dependencies) diff --git a/src/DataStructures/DataPortGroups/IDataPortGroup.cs b/src/DataStructures/DataPortGroups/IDataPortGroup.cs index 9ec6730..17dd336 100644 --- a/src/DataStructures/DataPortGroups/IDataPortGroup.cs +++ b/src/DataStructures/DataPortGroups/IDataPortGroup.cs @@ -1,11 +1,13 @@ using Godot; +using Nocturnis.DataStructures.DataTypes; namespace Nocturnis.DataStructures.DataPortGroups; public interface IDataPortGroup { - StringName SelectedType { get; set; } - StringName[] TypeOptions { get; set; } + DataType SelectedType { get; set; } + DataType[] TypeOptions { get; set; } + void Inference(); string Description { get; set; } } \ No newline at end of file diff --git a/src/DataStructures/DataTypeOptions/DataTypeOption.cs b/src/DataStructures/DataTypeOptions/DataTypeOption.cs new file mode 100644 index 0000000..127bb4b --- /dev/null +++ b/src/DataStructures/DataTypeOptions/DataTypeOption.cs @@ -0,0 +1,46 @@ +using Nocturnis.DataStructures.DataTypes; +using Nocturnis.GlobalManagement.Constants; +using Nocturnis.GlobalManagement.Providers; + +namespace Nocturnis.DataStructures.DataTypeOptions; + +public class DataTypeOption : HashSet +{ + public DataTypeOption(params DataType[] options) : base(options) + { + } + + public DataTypeOption() + { + } + + public new bool Contains(DataType type) + { + if (Count == 0) + return true; + DataType t = this.First(); + if ( + Count == 1 && + t == DataType.ArrayDataType(DataTypeConstant.BaseDataTypes.Null) && + type.Type == DataTypeConstant.NestedDataTypeNames.Array + ) + return true; + if ( + Count == 1 && + t == DataType.StructDataType(null) && + type.Type == DataTypeConstant.NestedDataTypeNames.Struct + ) + return true; + return base.Contains(type); + } + + public DataTypeOption Union(DataTypeOption oth) + { + DataTypeOption res = new(); + foreach (DataType t in this) + res.Add(t); + foreach (DataType t in oth) + res.Add(t); + return res; + } +} diff --git a/src/DataStructures/DataTypes/DataType.cs b/src/DataStructures/DataTypes/DataType.cs new file mode 100644 index 0000000..2e622d5 --- /dev/null +++ b/src/DataStructures/DataTypes/DataType.cs @@ -0,0 +1,108 @@ +using Godot; +using Nocturnis.GlobalManagement.Constants; + +namespace Nocturnis.DataStructures.DataTypes; + +public class DataType +{ + public static DataType ArrayDataType(DataType elementType) => new() + { + Type = DataTypeConstant.NestedDataTypeNames.Array, + ElementType = new DataType(elementType) + }; + + + public static DataType StructDataType(StringName structName) => new() + { + Type = DataTypeConstant.NestedDataTypeNames.Struct, + StructName = structName + }; + + public static DataType BaseDataType(StringName baseType) => new() + { + Type = baseType + }; + + public static DataType AutoDataType() => new() + { + Type = DataTypeConstant.BaseDataTypeNames.Null, + Auto = true + }; + + public static DataType AutoArrayType() => new() + { + Type = DataTypeConstant.NestedDataTypeNames.Array, + ElementType = AutoDataType() + }; + + public static DataType AutoStructType() => new() + { + Type = DataTypeConstant.NestedDataTypeNames.Struct, + Auto = true, + StructName = null + }; + + public bool Equals(DataType other) + { + return this == other; + } + + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + if (ReferenceEquals(this, obj)) return true; + if (obj.GetType() != this.GetType()) return false; + return Equals((DataType)obj); + } + + public override int GetHashCode() => Signature.GetHashCode(); + public DataType(StringName baseType, bool auto = false) + { + Type = baseType; + ElementType = DataTypeConstant.BaseDataTypes.Null; + } + + public DataType(DataType oth) + { + Type = oth.Type; + if (Type == DataTypeConstant.NestedDataTypeNames.Array) + ElementType = new DataType(oth.ElementType); + else + ElementType = null; + if (Type == DataTypeConstant.NestedDataTypeNames.Struct) + StructName = oth.StructName; + } + + public DataType() + { + } + + public StringName Type { get; set; } + public StringName StructName { get; set; } + public DataType ElementType { get; set; } + public bool Auto { get; set; } = false; + + public string Signature + { + get + { + if (Type == DataTypeConstant.NestedDataTypeNames.Array) + return Type + $"<{ElementType!.Signature}>"; + if (Type == DataTypeConstant.NestedDataTypeNames.Struct) + return Type + $"[{StructName}]"; + return Type; + } + } + + public static bool operator ==(DataType a, DataType b) => a.Signature == b.Signature; + + public static bool operator !=(DataType a, DataType b) => a.Signature != b.Signature; + + public void Assign(DataType oth) + { + Type = oth.Type; + ElementType.Assign(oth.ElementType); + StructName = oth.StructName; + } + +} diff --git a/src/DataStructures/IData.cs b/src/DataStructures/IData.cs deleted file mode 100644 index 365eeae..0000000 --- a/src/DataStructures/IData.cs +++ /dev/null @@ -1,25 +0,0 @@ -using Godot; -using System.Numerics; -using Skeleton.Algebra; -using Skeleton.Algebra.DimensionProviders; - -namespace Nocturnis.DataStructures; -using R2 = CategoryOf.OnField.FVector; -using C2 = CategoryOf.OnField.FVector; - -public interface IData -{ - public void Assign(IData oth); - public void Assign(object v, StringName t); - object? Data { get; set; } - StringName? Type { get; set; } - int Int { get; set; } - double Double { get; set; } - Complex Complex { get; set; } - IData[] Array { get; set; } - R2 R2 { get; set; } - C2 C2 { get; set; } - bool Bit { get; set; } - StringName String { get; set; } - IStruct Struct { get; set; } -} diff --git a/src/DataStructures/IStruct.cs b/src/DataStructures/IStruct.cs deleted file mode 100644 index 067b8e2..0000000 --- a/src/DataStructures/IStruct.cs +++ /dev/null @@ -1,9 +0,0 @@ -using Godot; - -namespace Nocturnis.DataStructures; - -public interface IStruct : IData -{ - StringName TypeName { get; set; } - Dictionary Properties { get; set; } -} diff --git a/src/Enigmos/Modules/ComputationalModules/EBinaryComputationalModule.cs b/src/Enigmos/Modules/ComputationalModules/EBinaryComputationalModule.cs index 19b39d9..09b1019 100644 --- a/src/Enigmos/Modules/ComputationalModules/EBinaryComputationalModule.cs +++ b/src/Enigmos/Modules/ComputationalModules/EBinaryComputationalModule.cs @@ -1,4 +1,5 @@ using Nocturnis.DataStructures; +using Nocturnis.DataStructures.Data; using Nocturnis.Enigmos.Ports.DataPorts.Directions; using Skeleton.DataStructure; @@ -6,8 +7,8 @@ namespace Nocturnis.Enigmos.Modules.ComputationalModules; public static class EBinaryComputationalModule { - public static IData X(this IBinaryComputationalModule p, CacheItem x) => p.DataInPorts[0].GetData.GetFrom(x)!; - public static IData Y(this IBinaryComputationalModule p, CacheItem x) => p.DataInPorts[1].GetData.GetFrom(x)!; + public static DataVariable X(this IBinaryComputationalModule p, CacheItem x) => p.DataInPorts[0].GetData.GetFrom(x)!; + public static DataVariable Y(this IBinaryComputationalModule p, CacheItem x) => p.DataInPorts[1].GetData.GetFrom(x)!; public static void BinaryInit(this IBinaryComputationalModule p) { diff --git a/src/Enigmos/Modules/ComputationalModules/EDuplicateOutputModule.cs b/src/Enigmos/Modules/ComputationalModules/EDuplicateOutputModule.cs index b6c5ddc..847a466 100644 --- a/src/Enigmos/Modules/ComputationalModules/EDuplicateOutputModule.cs +++ b/src/Enigmos/Modules/ComputationalModules/EDuplicateOutputModule.cs @@ -1,4 +1,5 @@ using Godot; +using Nocturnis.DataStructures.DataTypes; using Nocturnis.Enigmos.Ports.DataPorts.Directions; using Skeleton.DataStructure; @@ -6,13 +7,13 @@ namespace Nocturnis.Enigmos.Modules.ComputationalModules; public static class EDuplicateOutputModule { - public static void Define(this IDuplicateOutputModule m, Func define) + public static void Define(this IDuplicateOutputModule m, Func define) { foreach (IDataOutPort op in m.DataOutPorts) op.OutData.UpdateCalculation(define); } - public static void SetOutputType(this IDuplicateOutputModule m, StringName type) + public static void SetOutputType(this IDuplicateOutputModule m, DataType type) { foreach (IDataOutPort op in m.DataOutPorts) op.SetDataType(type); diff --git a/src/Enigmos/Modules/ComputationalModules/ELogicModule.cs b/src/Enigmos/Modules/ComputationalModules/ELogicModule.cs index 24dc95c..ce0fb40 100644 --- a/src/Enigmos/Modules/ComputationalModules/ELogicModule.cs +++ b/src/Enigmos/Modules/ComputationalModules/ELogicModule.cs @@ -7,9 +7,9 @@ public static class ELogicModule { public static void LogicModuleInit(this ILogicModule lm) { - foreach (IDataOutPort op in lm.DataOutPorts) - op.SetDataType(EnigmosConstant.DataPortTypes.Bit); - foreach (IDataInPort ip in lm.DataInPorts) - ip.SetDataType(EnigmosConstant.DataPortTypes.Bit); + //foreach (IDataOutPort op in lm.DataOutPorts) + // op.SetDataType(DataTypeConstant.BaseDataTypes.Bit); + //foreach (IDataInPort ip in lm.DataInPorts) + // ip.SetDataType(DataTypeConstant.BaseDataTypes.Bit); } } \ No newline at end of file diff --git a/src/Enigmos/Modules/ComputationalModules/EOperationModule.cs b/src/Enigmos/Modules/ComputationalModules/EOperationModule.cs index 5012874..980db37 100644 --- a/src/Enigmos/Modules/ComputationalModules/EOperationModule.cs +++ b/src/Enigmos/Modules/ComputationalModules/EOperationModule.cs @@ -1,11 +1,12 @@ using Godot; +using Nocturnis.DataStructures.DataTypes; using Nocturnis.Enigmos.Ports.DataPorts.Directions; namespace Nocturnis.Enigmos.Modules.ComputationalModules; public static class EOperationModule { - public static void SetInputType(this IOperationModule m, StringName type) + public static void SetInputType(this IOperationModule m, DataType type) { foreach (IDataInPort ip in m.DataInPorts) ip.SetDataType(type); diff --git a/src/Enigmos/Modules/ComputationalModules/ETernaryComputationalModule.cs b/src/Enigmos/Modules/ComputationalModules/ETernaryComputationalModule.cs index ad7b698..471c3a1 100644 --- a/src/Enigmos/Modules/ComputationalModules/ETernaryComputationalModule.cs +++ b/src/Enigmos/Modules/ComputationalModules/ETernaryComputationalModule.cs @@ -1,14 +1,15 @@ using Nocturnis.DataStructures; +using Nocturnis.DataStructures.Data; using Skeleton.DataStructure; namespace Nocturnis.Enigmos.Modules.ComputationalModules; public static class ETernaryComputationalModule { - public static IData X(this ITernaryComputationalModule m, CacheItem cache) => + public static DataVariable X(this ITernaryComputationalModule m, CacheItem cache) => m.DataOutPorts[0].OutData.GetFrom(cache)!; - public static IData Y(this ITernaryComputationalModule m, CacheItem cache) => + public static DataVariable Y(this ITernaryComputationalModule m, CacheItem cache) => m.DataOutPorts[1].OutData.GetFrom(cache)!; - public static IData Z(this ITernaryComputationalModule m, CacheItem cache) => + public static DataVariable Z(this ITernaryComputationalModule m, CacheItem cache) => m.DataOutPorts[2].OutData.GetFrom(cache)!; } \ No newline at end of file diff --git a/src/Enigmos/Modules/ComputationalModules/EUnaryComputationalModule.cs b/src/Enigmos/Modules/ComputationalModules/EUnaryComputationalModule.cs index 26b41b6..37ec931 100644 --- a/src/Enigmos/Modules/ComputationalModules/EUnaryComputationalModule.cs +++ b/src/Enigmos/Modules/ComputationalModules/EUnaryComputationalModule.cs @@ -1,10 +1,11 @@ using Nocturnis.DataStructures; +using Nocturnis.DataStructures.Data; using Skeleton.DataStructure; namespace Nocturnis.Enigmos.Modules.ComputationalModules; public static class EUnaryComputationalModule { - public static IData X(this IUnaryComputationalModule m, CacheItem cache) => + public static DataVariable X(this IUnaryComputationalModule m, CacheItem cache) => m.DataOutPorts[0].OutData.GetFrom(cache)!; } \ No newline at end of file diff --git a/src/Enigmos/Modules/ICommunicateModule.cs b/src/Enigmos/Modules/ICommunicateModule.cs index 086233d..3123079 100644 --- a/src/Enigmos/Modules/ICommunicateModule.cs +++ b/src/Enigmos/Modules/ICommunicateModule.cs @@ -1,13 +1,15 @@ using Godot; using Nocturnis.Communicators; using Nocturnis.DataStructures; +using Nocturnis.DataStructures.Data; +using Nocturnis.DataStructures.DataTypes; namespace Nocturnis.Enigmos.Modules; public interface ICommunicateModule : IBaseModule { IBaseCommunicator? PairedCommunicator { get; set; } - StringName CommunicationDataType { get; } + DataType CommunicationDataType { get; } StringName CommunicationDirection { get; } - IData DataBuffer { get; set; } + DataVariable DataBuffer { get; set; } } \ No newline at end of file diff --git a/src/Enigmos/Modules/IEnumerableProcessingModule.cs b/src/Enigmos/Modules/IEnumerableProcessingModule.cs index a59a4e9..2f3d8c0 100644 --- a/src/Enigmos/Modules/IEnumerableProcessingModule.cs +++ b/src/Enigmos/Modules/IEnumerableProcessingModule.cs @@ -1,9 +1,10 @@ using Nocturnis.DataStructures; +using Nocturnis.DataStructures.Data; namespace Nocturnis.Enigmos.Modules; public interface IEnumerableProcessingModule : ICompositeModule { - IData[] CachedInputArray { get; set; } + DataVariable[] CachedInputArray { get; set; } int ProcessingIndex { get; set; } } diff --git a/src/Enigmos/Modules/IFilterModule.cs b/src/Enigmos/Modules/IFilterModule.cs index 43d65a3..748915d 100644 --- a/src/Enigmos/Modules/IFilterModule.cs +++ b/src/Enigmos/Modules/IFilterModule.cs @@ -1,12 +1,13 @@ using Nocturnis.DataStructures; +using Nocturnis.DataStructures.Data; namespace Nocturnis.Enigmos.Modules; public interface IFilterModule : IProgrammableModule { void Filter(); - IData[] CachedInputArray { get; set; } - IData[] CachedResult { get; set; } + DataVariable[] CachedInputArray { get; set; } + DataVariable[] CachedResult { get; set; } int ProcessingIndex { get; set; } bool FilterFinished { get; set; } bool FilterStarted { get; set; } diff --git a/src/Enigmos/Modules/IInternalComputationalModule.cs b/src/Enigmos/Modules/IInternalComputationalModule.cs index b93e793..b7ae4fa 100644 --- a/src/Enigmos/Modules/IInternalComputationalModule.cs +++ b/src/Enigmos/Modules/IInternalComputationalModule.cs @@ -1,10 +1,11 @@ using Nocturnis.DataStructures; +using Nocturnis.DataStructures.Data; namespace Nocturnis.Enigmos.Modules; public interface IInternalComputationalModule : ICompositeModule { - IData? CachedResult { get; set; } + DataVariable? CachedResult { get; set; } void Compute(); bool ComputationFinished { get; set; } bool ComputationStarted { get; set; } diff --git a/src/Enigmos/Modules/IOptimizationModule.cs b/src/Enigmos/Modules/IOptimizationModule.cs index 15f1d9c..be5387a 100644 --- a/src/Enigmos/Modules/IOptimizationModule.cs +++ b/src/Enigmos/Modules/IOptimizationModule.cs @@ -1,10 +1,11 @@ using Nocturnis.DataStructures; +using Nocturnis.DataStructures.Data; namespace Nocturnis.Enigmos.Modules; public interface IOptimizationModule : IProgrammableModule { - IData CachedResult { get; set; } + DataVariable CachedResult { get; set; } bool ComputationStarted { get; set; } bool ComputationFinished { get; set; } void Optimize(); diff --git a/src/Enigmos/Ports/DataPorts/IDataPort.cs b/src/Enigmos/Ports/DataPorts/IDataPort.cs index 45831c0..e6f9793 100644 --- a/src/Enigmos/Ports/DataPorts/IDataPort.cs +++ b/src/Enigmos/Ports/DataPorts/IDataPort.cs @@ -1,10 +1,11 @@ using Godot; +using Nocturnis.DataStructures.DataTypes; namespace Nocturnis.Enigmos.Ports.DataPorts; public interface IDataPort : IBasePort { new IDataPort? ConnectedPort { get; set; } - StringName? DataType { get; set; } - void SetDataType(StringName type); + DataType DataType { get; set; } + void SetDataType(DataType type); } diff --git a/src/GlobalManagement/Constants/DataTypeConstant.cs b/src/GlobalManagement/Constants/DataTypeConstant.cs new file mode 100644 index 0000000..e1a5f88 --- /dev/null +++ b/src/GlobalManagement/Constants/DataTypeConstant.cs @@ -0,0 +1,33 @@ +using Godot; +using Nocturnis.DataStructures.DataTypeOptions; +using Nocturnis.DataStructures.DataTypes; +using Nocturnis.GlobalManagement.Providers; + +namespace Nocturnis.GlobalManagement.Constants; + +public static partial class DataTypeConstant +{ + public static class NestedDataTypeNames + { + public static readonly StringName Array = "Array"; + public static readonly StringName Struct = "Struct"; + public static readonly StringName Auto = "Auto"; + } + + public static class AutoDataTypes + { + public static readonly DataType Auto = DataType.AutoDataType(); + public static readonly DataType AutoArray = DataType.AutoArrayType(); + public static readonly DataType AutoStruct = DataType.AutoStructType(); + } + + public static partial class DataTypeOptions + { + public static readonly DataTypeOption ScalarTypes = new(BaseDataTypes.Real, BaseDataTypes.Complex); + public static readonly DataTypeOption VectorTypes = new(BaseDataTypes.R2, BaseDataTypes.C2); + public static readonly DataTypeOption TensorTypes = ScalarTypes.Union(VectorTypes); + public static readonly DataTypeOption AnyType = new(); + public static readonly DataTypeOption AnyArray = new(DataType.ArrayDataType(BaseDataTypes.Null)); + public static readonly DataTypeOption AnyStruct = new(DataType.StructDataType(null)); + } +} diff --git a/src/GlobalManagement/Constants/EnigmosConstant.cs b/src/GlobalManagement/Constants/EnigmosConstant.cs index 6b64b87..84d4502 100644 --- a/src/GlobalManagement/Constants/EnigmosConstant.cs +++ b/src/GlobalManagement/Constants/EnigmosConstant.cs @@ -4,23 +4,7 @@ namespace Nocturnis.GlobalManagement.Constants; public static class EnigmosConstant { - public static class DataPortTypes - { - public static readonly StringName Null = "Null"; - public static readonly StringName Bit = "Bit"; - public static readonly StringName Real = "Real"; - public static readonly StringName Complex = "Complex"; - public static readonly StringName R2 = "R2"; - public static readonly StringName C2 = "C2"; - public static readonly StringName RealArray = "RealArray"; - public static readonly StringName AnyArrayType = "AnyArrayType"; - public static readonly StringName[] NumericTypes = new[] { Real, Complex }; - public static readonly StringName[] AnyTensor = new[] { Real, Complex, R2, C2 }; - public static readonly StringName[] AnyType = new[] { Real, Complex, R2, C2 }; - public static readonly StringName[] VectorTypes = new[] { R2, C2 }; - public static readonly StringName[] AnyArray = Array.Empty(); - - } + public static class CommunicationDirections { public static readonly StringName Send = "Send"; diff --git a/src/GlobalManagement/Providers/GlobalProvider.cs b/src/GlobalManagement/Providers/GlobalProvider.cs index 658f2ed..9a82f72 100644 --- a/src/GlobalManagement/Providers/GlobalProvider.cs +++ b/src/GlobalManagement/Providers/GlobalProvider.cs @@ -1,4 +1,6 @@ using Godot; +using Nocturnis.DataStructures.Data; +using Nocturnis.DataStructures.DataTypes; using Nocturnis.Enigmos.Modules; using Nocturnis.Inventories.Items; @@ -33,4 +35,15 @@ public static class GlobalProvider public static readonly Dictionary SceneNameMapper = new(); public static Font? Font { get; set; } + + public static class DataTypes + { + public static DataType Null { get; set; } + public static DataType Bit { get; set; } + public static DataType Real { get; set; } + public static DataType Complex { get; set; } + public static DataType R2 { get; set; } + public static DataType C2 { get; set; } + public static DataType Int { get; set; } + } } diff --git a/src/GlobalManagement/Providers/IDataStructureProvider.cs b/src/GlobalManagement/Providers/IDataStructureProvider.cs index 0f01791..e4d0c48 100644 --- a/src/GlobalManagement/Providers/IDataStructureProvider.cs +++ b/src/GlobalManagement/Providers/IDataStructureProvider.cs @@ -1,7 +1,10 @@ using Godot; using Nocturnis.DataStructures; using Nocturnis.DataStructures.ConfigurableParameters; +using Nocturnis.DataStructures.Data; using Nocturnis.DataStructures.DataPortGroups; +using Nocturnis.DataStructures.DataTypeOptions; +using Nocturnis.DataStructures.DataTypes; using Nocturnis.Enigmos.Modules; using Nocturnis.Enigmos.Ports.DataPorts; using Nocturnis.Enigmos.Ports.DataPorts.Directions; @@ -10,20 +13,21 @@ namespace Nocturnis.GlobalManagement.Providers; public interface IDataStructureProvider { + DataType NullDataType { get; } Variant NewVariantWithType(string type, Variant a); IBoolParameter NewBoolParameter(string d, string t, string f, bool def); - IDataPortGroup NewDataPortGroup(IBaseModule m, IDataPort[] pts, string desc, StringName defType, StringName[] typeOpts); + IDataPortGroup NewDataPortGroup(IBaseModule m, IDataPort[] pts, string desc, DataType defType, DataTypeOption typeOpts); - IDataInGroup NewDataInGroup(IBaseModule m, IDataInPort[] pts, string desc, StringName defType, StringName[] typeOpts); + IDataInGroup NewDataInGroup(IBaseModule m, IDataInPort[] pts, string desc, DataType defType, DataTypeOption typeOpts); - IDataOutGroup NewDataOutGroup(IBaseModule m, IDataOutPort[] pts, string desc, StringName defType, StringName[] typeOpts); + IDataOutGroup NewDataOutGroup(IBaseModule m, IDataOutPort[] pts, string desc, DataType defType, DataTypeOption typeOpts); - IData NewData(object data, StringName type); + DataVariable NewData(object data, DataType type); IDoubleParameter NewDoubleParameter(string name, double min, double max, double def); IKeyParameter NewKeyParameter(string a, string b); - IData NullData { get; } - IData DefaultData { get; } + DataVariable NullData { get; } + DataVariable DefaultData { get; } StringName ArrayToElement(StringName arrayType); } \ No newline at end of file diff --git a/src/GlobalManagement/Providers/IDataTypeProvider.cs b/src/GlobalManagement/Providers/IDataTypeProvider.cs index c56c6a3..ebfc664 100644 --- a/src/GlobalManagement/Providers/IDataTypeProvider.cs +++ b/src/GlobalManagement/Providers/IDataTypeProvider.cs @@ -1,13 +1,14 @@ using Godot; +using Nocturnis.DataStructures.DataTypes; namespace Nocturnis.GlobalManagement.Providers; public interface IDataTypeProvider { - bool IsComplexTensorType(StringName type); - StringName ComplexVersionOf(StringName type); - StringName BuildType(StringName nType, int i, int j); - StringName GetBaseField(StringName type); - bool DataPortTypeCompatible(StringName inType, StringName outType); - StringName ToElement(StringName arrayType); + bool IsComplexTensorType(DataType type); + DataType ComplexVersionOf(DataType type); + DataType BuildType(DataType nType, int i, int j); + DataType GetBaseField(DataType type); + bool DataPortTypeCompatible(DataType inType, DataType outType); + DataType ToElement(DataType arrayType); } diff --git a/src/GlobalManagement/Providers/IEnigmosProvider.cs b/src/GlobalManagement/Providers/IEnigmosProvider.cs index 58a14bf..5df6c92 100644 --- a/src/GlobalManagement/Providers/IEnigmosProvider.cs +++ b/src/GlobalManagement/Providers/IEnigmosProvider.cs @@ -1,4 +1,5 @@ using Godot; +using Nocturnis.DataStructures.DataTypes; namespace Nocturnis.GlobalManagement.Providers; @@ -14,7 +15,7 @@ public interface IEnigmosProvider PackedScene SignalCableScene { get; set; } PackedScene DataCableScene { get; set; } - Dictionary DataPortTypeMap { get; set; } + Dictionary DataPortTypeMap { get; set; } bool CommunicationDirectionCompatible(StringName moduleDir, StringName communicatorDir); diff --git a/src/GlobalManagement/Providers/IPolymorphismProvider.cs b/src/GlobalManagement/Providers/IPolymorphismProvider.cs index 83c1ee0..7dab3a1 100644 --- a/src/GlobalManagement/Providers/IPolymorphismProvider.cs +++ b/src/GlobalManagement/Providers/IPolymorphismProvider.cs @@ -1,18 +1,20 @@ using Godot; using Nocturnis.DataStructures; +using Nocturnis.DataStructures.Data; +using Nocturnis.DataStructures.DataTypes; namespace Nocturnis.GlobalManagement.Providers; public interface IPolymorphismProvider { - (object, StringName) Square(IData a); - (object, StringName) Neg(IData a); - (object, StringName) Add(IData a, IData b); - (object, StringName) Sub(IData a, IData b); - (object, StringName) Div(IData a, IData b); - (object, StringName) Dot(IData a, IData b); - (object, StringName) Mul(IData a, IData b); - (object, StringName) Pow(IData a, IData b); - (object, StringName) ScalarDiv(IData a, IData b); - (object, StringName) ScalarMul(IData a, IData b); + (object, DataType) Square(DataVariable a); + (object, DataType) Neg(DataVariable a); + (object, DataType) Add(DataVariable a, DataVariable b); + (object, DataType) Sub(DataVariable a, DataVariable b); + (object, DataType) Div(DataVariable a, DataVariable b); + (object, DataType) Dot(DataVariable a, DataVariable b); + (object, DataType) Mul(DataVariable a, DataVariable b); + (object, DataType) Pow(DataVariable a, DataVariable b); + (object, DataType) ScalarDiv(DataVariable a, DataVariable b); + (object, DataType) ScalarMul(DataVariable a, DataVariable b); }