diff --git a/BeefLibs/Beefy2D/src/Utils.bf b/BeefLibs/Beefy2D/src/Utils.bf index 4be4bd5d..6319db24 100644 --- a/BeefLibs/Beefy2D/src/Utils.bf +++ b/BeefLibs/Beefy2D/src/Utils.bf @@ -165,7 +165,7 @@ namespace Beefy // Retry for a while if the other side is still writing out the file for (int i = 0; i < 100; i++) { - if (sr.Open(fileName) case .Err(let fileOpenErr)) + if (sr.Open(fileName, .Read, .Read) case .Err(let fileOpenErr)) { bool retry = false; if (autoRetry) diff --git a/BeefLibs/corlib/src/Span.bf b/BeefLibs/corlib/src/Span.bf index 540e388b..091c0bae 100644 --- a/BeefLibs/corlib/src/Span.bf +++ b/BeefLibs/corlib/src/Span.bf @@ -272,5 +272,124 @@ namespace System } } +#if BF_RUNTIME_CHECKS +#define BF_OPTSPAN_LENGTH +#endif + + struct OptSpan + { + protected T* mPtr; +#if BF_OPTSPAN_LENGTH + protected int mLength; +#endif + + public this() + { + mPtr = null; +#if BF_OPTSPAN_LENGTH + mLength = 0; +#endif + } + + public this(T[] array) + { + mPtr = &array.getRef(0); +#if BF_OPTSPAN_LENGTH + mLength = array.[Friend]mLength; +#endif + } + + public this(T[] array, int index) + { + mPtr = &array[index]; +#if BF_OPTSPAN_LENGTH + mLength = array.[Friend]mLength - index; +#endif + } + + public this(T[] array, int index, int length) + { + if (length == 0) + mPtr = null; + else + mPtr = &array[index]; +#if BF_OPTSPAN_LENGTH + mLength = length; +#endif + } + + public this(T* memory, int length) + { + mPtr = memory; +#if BF_OPTSPAN_LENGTH + mLength = length; +#endif + } + + public static implicit operator OptSpan (T[] array) + { + return OptSpan(array); + } + + + [Inline] + public T* Ptr + { + get + { + return mPtr; + } + } + + public ref T this[int index] + { + [Inline, Checked] + get + { +#if BF_OPTSPAN_LENGTH + Debug.Assert((uint)index < (uint)mLength); +#endif + return ref mPtr[index]; + } + + [Inline, Unchecked] + get + { + return ref mPtr[index]; + } + } + + public OptSpan Slice(int index, int length) + { + OptSpan span; + span.mPtr = mPtr + index; +#if BF_OPTSPAN_LENGTH + Debug.Assert((uint)index + (uint)length <= (uint)mLength); + span.mLength = length; +#else + Debug.Assert(index >= 0); +#endif + return span; + } + + public void Adjust(int ofs) mut + { + mPtr += ofs; +#if BF_OPTSPAN_LENGTH + Debug.Assert((uint)ofs <= (uint)mLength); + mLength -= ofs; +#endif + } + + public OptSpan ToRawData() + { +#if BF_OPTSPAN_LENGTH + return OptSpan((uint8*)mPtr, mLength * alignof(T)); +#else + return OptSpan((uint8*)mPtr, 0); +#endif + } + } + //TODO: Make a ReadOnlySpan } diff --git a/IDE/BeefProj.toml b/IDE/BeefProj.toml index 73ad54d9..9f62fbd9 100644 --- a/IDE/BeefProj.toml +++ b/IDE/BeefProj.toml @@ -20,20 +20,18 @@ ProductVersion = "0000000000000000" [Configs.Debug.Win32] TargetName = "" OtherLinkFlags = "" -OptimizationLevel = "O0" [Configs.Debug.Win64] TargetDirectory = "$(WorkspaceDir)/dist" TargetName = "BeefIDE_d" OtherLinkFlags = "$(LinkFlags) Comdlg32.lib kernel32.lib user32.lib advapi32.lib shell32.lib IDEHelper64_d.lib" -DebugCommandArguments = "-workspace=c:\\Beef\\IDE" +DebugCommandArguments = "-proddir=C:\\Beef\\IDE" DebugWorkingDirectory = "c:\\Beef\\IDE\\Tests\\EmptyTest" EnvironmentVars = ["_NO_DEBUG_HEAP=1"] [Configs.Release.Win32] TargetName = "" OtherLinkFlags = "" -OptimizationLevel = "O0" [Configs.Release.Win64] TargetDirectory = "$(WorkspaceDir)/dist" @@ -46,7 +44,6 @@ EnvironmentVars = ["_NO_DEBUG_HEAP=1"] [Configs.Debug2.Win32] TargetName = "" OtherLinkFlags = "" -OptimizationLevel = "O0" [Configs.Debug2.Win64] TargetDirectory = "$(WorkspaceDir)/dist" diff --git a/IDE/mintest/minlib/src/System/Span.bf b/IDE/mintest/minlib/src/System/Span.bf index 478ea661..5494810b 100644 --- a/IDE/mintest/minlib/src/System/Span.bf +++ b/IDE/mintest/minlib/src/System/Span.bf @@ -78,14 +78,21 @@ namespace System } } - [Inline] public ref T this[int index] - { - get + { + [Inline, Checked] + get + { + Debug.Assert((uint)index < (uint)mLength); + return ref mPtr[index]; + } + + [Inline, Unchecked] + get { return ref mPtr[index]; } - } + } public Span Slice(int index) { @@ -214,5 +221,124 @@ namespace System } } +#if BF_RUNTIME_CHECKS +#define BF_OPTSPAN_LENGTH +#endif + + struct OptSpan + { + protected T* mPtr; +#if BF_OPTSPAN_LENGTH + protected int mLength; +#endif + + public this() + { + mPtr = null; +#if BF_OPTSPAN_LENGTH + mLength = 0; +#endif + } + + public this(T[] array) + { + mPtr = &array.getRef(0); +#if BF_OPTSPAN_LENGTH + mLength = array.[Friend]mLength; +#endif + } + + public this(T[] array, int index) + { + mPtr = &array[index]; +#if BF_OPTSPAN_LENGTH + mLength = array.[Friend]mLength - index; +#endif + } + + public this(T[] array, int index, int length) + { + if (length == 0) + mPtr = null; + else + mPtr = &array[index]; +#if BF_OPTSPAN_LENGTH + mLength = length; +#endif + } + + public this(T* memory, int length) + { + mPtr = memory; +#if BF_OPTSPAN_LENGTH + mLength = length; +#endif + } + + public static implicit operator OptSpan (T[] array) + { + return OptSpan(array); + } + + + [Inline] + public T* Ptr + { + get + { + return mPtr; + } + } + + public ref T this[int index] + { + [Inline, Checked] + get + { +#if BF_OPTSPAN_LENGTH + Debug.Assert((uint)index < (uint)mLength); +#endif + return ref mPtr[index]; + } + + [Inline, Unchecked] + get + { + return ref mPtr[index]; + } + } + + public OptSpan Slice(int index, int length) + { + OptSpan span; + span.mPtr = mPtr + index; +#if BF_OPTSPAN_LENGTH + Debug.Assert((uint)index + (uint)length <= (uint)mLength); + span.mLength = length; +#else + Debug.Assert(index >= 0); +#endif + return span; + } + + public void Adjust(int ofs) mut + { + mPtr += ofs; +#if BF_OPTSPAN_LENGTH + Debug.Assert((uint)ofs <= (uint)mLength); + mLength -= ofs; +#endif + } + + public OptSpan ToRawData() + { +#if BF_OPTSPAN_LENGTH + return OptSpan((uint8*)mPtr, mLength * alignof(T)); +#else + return OptSpan((uint8*)mPtr, 0); +#endif + } + } + //TODO: Make a ReadOnlySpan }