mirror of
https://github.com/beefytech/Beef.git
synced 2025-06-11 12:54:15 +02:00
Corlib additions
This commit is contained in:
parent
b756fe50eb
commit
788351e178
4 changed files with 251 additions and 9 deletions
|
@ -165,7 +165,7 @@ namespace Beefy
|
||||||
// Retry for a while if the other side is still writing out the file
|
// Retry for a while if the other side is still writing out the file
|
||||||
for (int i = 0; i < 100; i++)
|
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;
|
bool retry = false;
|
||||||
if (autoRetry)
|
if (autoRetry)
|
||||||
|
|
|
@ -272,5 +272,124 @@ namespace System
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if BF_RUNTIME_CHECKS
|
||||||
|
#define BF_OPTSPAN_LENGTH
|
||||||
|
#endif
|
||||||
|
|
||||||
|
struct OptSpan<T>
|
||||||
|
{
|
||||||
|
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> (T[] array)
|
||||||
|
{
|
||||||
|
return OptSpan<T>(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<T> Slice(int index, int length)
|
||||||
|
{
|
||||||
|
OptSpan<T> 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<uint8> ToRawData()
|
||||||
|
{
|
||||||
|
#if BF_OPTSPAN_LENGTH
|
||||||
|
return OptSpan<uint8>((uint8*)mPtr, mLength * alignof(T));
|
||||||
|
#else
|
||||||
|
return OptSpan<uint8>((uint8*)mPtr, 0);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
//TODO: Make a ReadOnlySpan
|
//TODO: Make a ReadOnlySpan
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,20 +20,18 @@ ProductVersion = "0000000000000000"
|
||||||
[Configs.Debug.Win32]
|
[Configs.Debug.Win32]
|
||||||
TargetName = ""
|
TargetName = ""
|
||||||
OtherLinkFlags = ""
|
OtherLinkFlags = ""
|
||||||
OptimizationLevel = "O0"
|
|
||||||
|
|
||||||
[Configs.Debug.Win64]
|
[Configs.Debug.Win64]
|
||||||
TargetDirectory = "$(WorkspaceDir)/dist"
|
TargetDirectory = "$(WorkspaceDir)/dist"
|
||||||
TargetName = "BeefIDE_d"
|
TargetName = "BeefIDE_d"
|
||||||
OtherLinkFlags = "$(LinkFlags) Comdlg32.lib kernel32.lib user32.lib advapi32.lib shell32.lib IDEHelper64_d.lib"
|
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"
|
DebugWorkingDirectory = "c:\\Beef\\IDE\\Tests\\EmptyTest"
|
||||||
EnvironmentVars = ["_NO_DEBUG_HEAP=1"]
|
EnvironmentVars = ["_NO_DEBUG_HEAP=1"]
|
||||||
|
|
||||||
[Configs.Release.Win32]
|
[Configs.Release.Win32]
|
||||||
TargetName = ""
|
TargetName = ""
|
||||||
OtherLinkFlags = ""
|
OtherLinkFlags = ""
|
||||||
OptimizationLevel = "O0"
|
|
||||||
|
|
||||||
[Configs.Release.Win64]
|
[Configs.Release.Win64]
|
||||||
TargetDirectory = "$(WorkspaceDir)/dist"
|
TargetDirectory = "$(WorkspaceDir)/dist"
|
||||||
|
@ -46,7 +44,6 @@ EnvironmentVars = ["_NO_DEBUG_HEAP=1"]
|
||||||
[Configs.Debug2.Win32]
|
[Configs.Debug2.Win32]
|
||||||
TargetName = ""
|
TargetName = ""
|
||||||
OtherLinkFlags = ""
|
OtherLinkFlags = ""
|
||||||
OptimizationLevel = "O0"
|
|
||||||
|
|
||||||
[Configs.Debug2.Win64]
|
[Configs.Debug2.Win64]
|
||||||
TargetDirectory = "$(WorkspaceDir)/dist"
|
TargetDirectory = "$(WorkspaceDir)/dist"
|
||||||
|
|
|
@ -78,14 +78,21 @@ namespace System
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
[Inline]
|
|
||||||
public ref T this[int index]
|
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];
|
return ref mPtr[index];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public Span<T> Slice(int index)
|
public Span<T> Slice(int index)
|
||||||
{
|
{
|
||||||
|
@ -214,5 +221,124 @@ namespace System
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if BF_RUNTIME_CHECKS
|
||||||
|
#define BF_OPTSPAN_LENGTH
|
||||||
|
#endif
|
||||||
|
|
||||||
|
struct OptSpan<T>
|
||||||
|
{
|
||||||
|
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> (T[] array)
|
||||||
|
{
|
||||||
|
return OptSpan<T>(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<T> Slice(int index, int length)
|
||||||
|
{
|
||||||
|
OptSpan<T> 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<uint8> ToRawData()
|
||||||
|
{
|
||||||
|
#if BF_OPTSPAN_LENGTH
|
||||||
|
return OptSpan<uint8>((uint8*)mPtr, mLength * alignof(T));
|
||||||
|
#else
|
||||||
|
return OptSpan<uint8>((uint8*)mPtr, 0);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
//TODO: Make a ReadOnlySpan
|
//TODO: Make a ReadOnlySpan
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue