From 38f4b349f24ad917317b1de03a7e6527dc84b4c5 Mon Sep 17 00:00:00 2001 From: EinBurgbauer Date: Mon, 17 May 2021 14:22:26 +0200 Subject: [PATCH 1/9] collection item dispose mixins, string specific list --- BeefLibs/corlib/src/Collections/List.bf | 53 +++++++++++++++++++++++++ BeefLibs/corlib/src/System.bf | 20 ++++++++++ 2 files changed, 73 insertions(+) diff --git a/BeefLibs/corlib/src/Collections/List.bf b/BeefLibs/corlib/src/Collections/List.bf index 605cb723..90423812 100644 --- a/BeefLibs/corlib/src/Collections/List.bf +++ b/BeefLibs/corlib/src/Collections/List.bf @@ -930,6 +930,59 @@ namespace System.Collections } } + extension List where T : String + { + public bool Contains(T item, StringComparison comparison) + { + if (item == null) + { + for (int i = 0; i < mSize; i++) + if (mItems[i] == null) + return true; + return false; + } + else + { + for (int i = 0; i < mSize; i++) + if (mItems[i].Equals(item, comparison)) + return true; + return false; + } + } + + public int IndexOf(T item, StringComparison comparison) + { + for (int i = 0; i < mSize; i++) + if (mItems[i].Equals(item, comparison)) + return i; + return -1; + } + + public int IndexOf(T item, int index, StringComparison comparison) + { + for (int i = index; i < mSize; i++) + if (mItems[i].Equals(item, comparison)) + return i; + return -1; + } + + public int IndexOf(T item, int index, int count, StringComparison comparison) + { + for (int i = index; i < index + count; i++) + if (mItems[i].Equals(item, comparison)) + return i; + return -1; + } + + public int LastIndexOf(T item, StringComparison comparison) + { + for (int i = mSize - 1; i >= 0; i--) + if (mItems[i].Equals(item, comparison)) + return i; + return -1; + } + } + class ListWithAlloc : List { IRawAllocator mAlloc; diff --git a/BeefLibs/corlib/src/System.bf b/BeefLibs/corlib/src/System.bf index def9c456..9289da0a 100644 --- a/BeefLibs/corlib/src/System.bf +++ b/BeefLibs/corlib/src/System.bf @@ -227,6 +227,26 @@ static } } + public static mixin DeleteContainerAndDisposeItems(var container) + { + if (container != null) + { + for (var value in container) + value.Dispose(); + delete container; + } + } + + public static mixin ClearAndDisposeItems(var container) + { + if (container != null) + { + for (var value in container) + value.Dispose(); + container.Clear(); + } + } + public static mixin DeleteAndNullify(var val) { delete val; From f98b9dc99ab8ab7836991bc79e9b4c8b60150e62 Mon Sep 17 00:00:00 2001 From: EinBurgbauer Date: Mon, 17 May 2021 14:35:14 +0200 Subject: [PATCH 2/9] comptime get generic arg fix --- BeefLibs/corlib/src/Type.bf | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/BeefLibs/corlib/src/Type.bf b/BeefLibs/corlib/src/Type.bf index 73d6acf1..d8b60c6c 100644 --- a/BeefLibs/corlib/src/Type.bf +++ b/BeefLibs/corlib/src/Type.bf @@ -683,13 +683,7 @@ namespace System namespace System.Reflection { - public struct TypeId : int32 - { - public Type ToType() - { - return Type.[Friend]sTypes[(int32)this]; - } - } + public struct TypeId : int32 {} [Ordered, AlwaysInclude(AssumeInstantiated=true)] public class TypeInstance : Type @@ -1137,7 +1131,7 @@ namespace System.Reflection public Type GetGenericArg(int argIdx) { - return mResolvedTypeRefs[argIdx].ToType(); + return Type.GetType(mResolvedTypeRefs[argIdx]); } public override void GetFullName(String strBuffer) From 46b5bfce1e100ed4b3cf93e1c5c14a7c1644e6ce Mon Sep 17 00:00:00 2001 From: EinBurgbauer Date: Mon, 17 May 2021 15:01:49 +0200 Subject: [PATCH 3/9] made static only stuff a static class --- BeefLibs/corlib/src/Diagnostics/Check.bf | 2 +- BeefLibs/corlib/src/Diagnostics/Contracts/Contracts.bf | 2 +- BeefLibs/corlib/src/Diagnostics/Debug.bf | 2 +- BeefLibs/corlib/src/IO/File.bf | 2 +- BeefLibs/corlib/src/Runtime.bf | 2 +- BeefLibs/corlib/src/Text/UTF16.bf | 2 +- BeefLibs/corlib/src/Text/UTF8.bf | 2 +- 7 files changed, 7 insertions(+), 7 deletions(-) diff --git a/BeefLibs/corlib/src/Diagnostics/Check.bf b/BeefLibs/corlib/src/Diagnostics/Check.bf index 0b26b71c..b041f6fb 100644 --- a/BeefLibs/corlib/src/Diagnostics/Check.bf +++ b/BeefLibs/corlib/src/Diagnostics/Check.bf @@ -1,6 +1,6 @@ namespace System.Diagnostics { - class Check + static class Check { [Unchecked, SkipCall] diff --git a/BeefLibs/corlib/src/Diagnostics/Contracts/Contracts.bf b/BeefLibs/corlib/src/Diagnostics/Contracts/Contracts.bf index e14d5a0c..e5f7d80c 100644 --- a/BeefLibs/corlib/src/Diagnostics/Contracts/Contracts.bf +++ b/BeefLibs/corlib/src/Diagnostics/Contracts/Contracts.bf @@ -1,6 +1,6 @@ namespace System.Diagnostics.Contracts { - class Contract + static class Contract { public enum ContractFailureKind { diff --git a/BeefLibs/corlib/src/Diagnostics/Debug.bf b/BeefLibs/corlib/src/Diagnostics/Debug.bf index d4df7bd4..fe45865b 100644 --- a/BeefLibs/corlib/src/Diagnostics/Debug.bf +++ b/BeefLibs/corlib/src/Diagnostics/Debug.bf @@ -1,6 +1,6 @@ namespace System.Diagnostics { - class Debug + static class Debug { #if !DEBUG [SkipCall] diff --git a/BeefLibs/corlib/src/IO/File.bf b/BeefLibs/corlib/src/IO/File.bf index a3ae6cf2..06d6abd7 100644 --- a/BeefLibs/corlib/src/IO/File.bf +++ b/BeefLibs/corlib/src/IO/File.bf @@ -23,7 +23,7 @@ namespace System.IO case FileReadError(FileReadError); } - class File + static class File { public static Result ReadAll(StringView path, List outData) { diff --git a/BeefLibs/corlib/src/Runtime.bf b/BeefLibs/corlib/src/Runtime.bf index 96ae54fc..564b032c 100644 --- a/BeefLibs/corlib/src/Runtime.bf +++ b/BeefLibs/corlib/src/Runtime.bf @@ -6,7 +6,7 @@ using System.Threading; namespace System { [StaticInitPriority(100)] - class Runtime + static class Runtime { const int32 cVersion = 8; diff --git a/BeefLibs/corlib/src/Text/UTF16.bf b/BeefLibs/corlib/src/Text/UTF16.bf index 4a4953f2..5ab1fc6d 100644 --- a/BeefLibs/corlib/src/Text/UTF16.bf +++ b/BeefLibs/corlib/src/Text/UTF16.bf @@ -1,7 +1,7 @@ using System.Diagnostics; namespace System.Text { - public class UTF16 + public static class UTF16 { public enum EncodeError { diff --git a/BeefLibs/corlib/src/Text/UTF8.bf b/BeefLibs/corlib/src/Text/UTF8.bf index 4df4c7f9..0dce24ae 100644 --- a/BeefLibs/corlib/src/Text/UTF8.bf +++ b/BeefLibs/corlib/src/Text/UTF8.bf @@ -1,7 +1,7 @@ using System.Diagnostics; namespace System.Text { - class UTF8 + static class UTF8 { public const int8[256] sTrailingBytesForUTF8 = .( From 5a199816065ad31a000a766f5aa93698c09e0115 Mon Sep 17 00:00:00 2001 From: EinBurgbauer Date: Mon, 17 May 2021 16:23:18 +0200 Subject: [PATCH 4/9] basic Dictionary ContainsValue functionality --- BeefLibs/corlib/src/Collections/Dictionary.bf | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/BeefLibs/corlib/src/Collections/Dictionary.bf b/BeefLibs/corlib/src/Collections/Dictionary.bf index 32fca56a..9789c46d 100644 --- a/BeefLibs/corlib/src/Collections/Dictionary.bf +++ b/BeefLibs/corlib/src/Collections/Dictionary.bf @@ -267,7 +267,11 @@ namespace System.Collections } else { - //TODO: IMPORTANT! + for (int_cosize i = 0; i < mCount; i++) + { + if (mEntries[i].mHashCode >= 0 && mEntries[i].mValue == value) return true; + } + //TODO: comparison /*EqualityComparer c = EqualityComparer.Default; for (int i = 0; i < count; i++) { From d5347b65064705f0a8c07b1ee45d4286ab81dd0f Mon Sep 17 00:00:00 2001 From: EinBurgbauer Date: Tue, 18 May 2021 11:57:38 +0200 Subject: [PATCH 5/9] fix source content readonly edit --- IDE/src/ui/SourceEditWidgetContent.bf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/IDE/src/ui/SourceEditWidgetContent.bf b/IDE/src/ui/SourceEditWidgetContent.bf index cbef21bb..784a2484 100644 --- a/IDE/src/ui/SourceEditWidgetContent.bf +++ b/IDE/src/ui/SourceEditWidgetContent.bf @@ -2758,7 +2758,7 @@ namespace IDE.ui return; } - if (mIsReadOnly) + if (CheckReadOnly()) { base.KeyChar(keyChar); return; From 4fb7a0f53f5a9017f140484dafd6c97c7ad708fe Mon Sep 17 00:00:00 2001 From: EinBurgbauer Date: Tue, 18 May 2021 19:42:28 +0200 Subject: [PATCH 6/9] fix explicit thiscall crash --- IDEHelper/Compiler/BfResolvedTypeUtils.cpp | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/IDEHelper/Compiler/BfResolvedTypeUtils.cpp b/IDEHelper/Compiler/BfResolvedTypeUtils.cpp index b8253306..f97a86b7 100644 --- a/IDEHelper/Compiler/BfResolvedTypeUtils.cpp +++ b/IDEHelper/Compiler/BfResolvedTypeUtils.cpp @@ -1208,7 +1208,8 @@ void BfMethodInstance::GetIRFunctionInfo(BfModule* module, BfIRType& returnType, { returnType = module->mBfIRBuilder->MapType(mReturnType); } - + + bool hasExplicitThis = false; for (int paramIdx = -1; paramIdx < GetParamCount(); paramIdx++) { BfType* checkType = NULL; @@ -1223,13 +1224,23 @@ void BfMethodInstance::GetIRFunctionInfo(BfModule* module, BfIRType& returnType, else { if (HasExplicitThis()) + { checkType = GetParamType(0); + hasExplicitThis = true; + } else checkType = GetOwner(); } } else { + if (hasExplicitThis) + { + // We already looked at this + hasExplicitThis = false; + continue; + } + checkType = GetParamType(paramIdx); } From d08b45018c093458f683ee93ea5f972e57886aa9 Mon Sep 17 00:00:00 2001 From: Brian Fiete Date: Thu, 20 May 2021 06:33:07 -0400 Subject: [PATCH 7/9] Simpler ContainsValue --- BeefLibs/corlib/src/Collections/Dictionary.bf | 20 ++----------------- 1 file changed, 2 insertions(+), 18 deletions(-) diff --git a/BeefLibs/corlib/src/Collections/Dictionary.bf b/BeefLibs/corlib/src/Collections/Dictionary.bf index 9789c46d..7313d931 100644 --- a/BeefLibs/corlib/src/Collections/Dictionary.bf +++ b/BeefLibs/corlib/src/Collections/Dictionary.bf @@ -258,25 +258,9 @@ namespace System.Collections public bool ContainsValue(TValue value) { - if (value == null) + for (int_cosize i = 0; i < mCount; i++) { - for (int_cosize i = 0; i < mCount; i++) - { - if (mEntries[i].mHashCode >= 0 && mEntries[i].mValue == null) return true; - } - } - else - { - for (int_cosize i = 0; i < mCount; i++) - { - if (mEntries[i].mHashCode >= 0 && mEntries[i].mValue == value) return true; - } - //TODO: comparison - /*EqualityComparer c = EqualityComparer.Default; - for (int i = 0; i < count; i++) - { - if (entries[i].hashCode >= 0 && c.Equals(entries[i].value, value)) return true; - }*/ + if (mEntries[i].mHashCode >= 0 && mEntries[i].mValue == null) return true; } return false; } From 351d94e0e87efb44102d6979519737ba0bb48f31 Mon Sep 17 00:00:00 2001 From: Brian Fiete Date: Thu, 20 May 2021 06:33:28 -0400 Subject: [PATCH 8/9] ReadStrSized32 --- BeefLibs/corlib/src/IO/Stream.bf | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/BeefLibs/corlib/src/IO/Stream.bf b/BeefLibs/corlib/src/IO/Stream.bf index 6798c4aa..00e8bab5 100644 --- a/BeefLibs/corlib/src/IO/Stream.bf +++ b/BeefLibs/corlib/src/IO/Stream.bf @@ -97,10 +97,10 @@ namespace System.IO } } - //Read sized string from stream - public Result ReadStrSized32(int64 size, String output) + /// Read sized string from stream + public Result ReadStrSized32(int size, String output) { - if (size <= 0) + if (size < 0) return .Err; for (int64 i = 0; i < size; i++) @@ -115,7 +115,13 @@ namespace System.IO return .Ok; } - //Reads null terminated ASCII string from the stream. Null terminator is read from stream but isn't appended to output string + public Result ReadStrSized32(String output) + { + int size = Try!(Read()); + return ReadStrSized32(size, output); + } + + /// Reads null terminated ASCII string from the stream. Null terminator is read from stream but isn't appended to output string public Result ReadStrC(String output) { Result char0; From 8975b30e0f85512809100420dbffe7a2097d6e9b Mon Sep 17 00:00:00 2001 From: Brian Fiete Date: Thu, 20 May 2021 08:55:06 -0400 Subject: [PATCH 9/9] Disable broken https://github.com/beefytech/Beef/pull/1015 --- IDEHelper/Compiler/BfResolvedTypeUtils.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/IDEHelper/Compiler/BfResolvedTypeUtils.cpp b/IDEHelper/Compiler/BfResolvedTypeUtils.cpp index f97a86b7..c38c5c8f 100644 --- a/IDEHelper/Compiler/BfResolvedTypeUtils.cpp +++ b/IDEHelper/Compiler/BfResolvedTypeUtils.cpp @@ -1226,7 +1226,9 @@ void BfMethodInstance::GetIRFunctionInfo(BfModule* module, BfIRType& returnType, if (HasExplicitThis()) { checkType = GetParamType(0); - hasExplicitThis = true; + + //TODO(BCF): Breaks tests + //hasExplicitThis = true; } else checkType = GetOwner();