1
0
Fork 0
mirror of https://github.com/beefytech/Beef.git synced 2025-06-10 20:42:21 +02:00

Extensive runtime refactor to reduce generated executable sizes

This commit is contained in:
Brian Fiete 2024-03-16 07:23:29 -04:00
parent 4e750a7e1a
commit ddd9b1b218
74 changed files with 2514 additions and 717 deletions

View file

@ -15,12 +15,8 @@ namespace FMOD
*/
public class VERSION
{
public const int32 number = 0x00010803;
#if BF_64_BIT
public const String dll = "fmod64.dll";
#else
public const String dll = "fmod.dll";
#endif
public const int32 number = 0x00020220;
public const String dll = "fmod.dll";
}
public class CONSTANTS
@ -1385,7 +1381,7 @@ namespace FMOD
public int fileuserdata; /* [w] Optional. Specify 0 to ignore. User data to be passed into the file callbacks. */
public int32 filebuffersize; /* [w] Optional. Specify 0 to ignore. Buffer size for reading the file, -1 to disable buffering, or 0 for system default. */
public CHANNELORDER channelorder; /* [w] Optional. Specify 0 to ignore. Use this to differ the way fmod maps multichannel sounds to speakers. See FMOD_CHANNELORDER for more. */
public CHANNELMASK channelmask; /* [w] Optional. Specify 0 to ignore. Use this to differ the way fmod maps multichannel sounds to speakers. See FMOD_CHANNELMASK for more. */
//public CHANNELMASK channelmask; /* [w] Optional. Specify 0 to ignore. Use this to differ the way fmod maps multichannel sounds to speakers. See FMOD_CHANNELMASK for more. */
public int initialsoundgroup; /* [w] Optional. Specify 0 to ignore. Specify a sound group if required, to put sound in as it is created. */
public uint32 initialseekposition; /* [w] Optional. Specify 0 to ignore. For streams. Specify an initial position to seek the stream to. */
public TIMEUNIT initialseekpostype; /* [w] Optional. Specify 0 to ignore. For streams. Specify the time unit for the position set in initialseekposition. */
@ -1587,7 +1583,7 @@ namespace FMOD
RESULT result = RESULT.OK;
int rawPtr = 0;
result = FMOD_System_Create(out rawPtr);
result = FMOD_System_Create(out rawPtr, VERSION.number);
if (result != RESULT.OK)
{
return result;
@ -1602,7 +1598,7 @@ namespace FMOD
#region importfunctions
[Import(VERSION.dll), CLink, CallingConvention(.Stdcall)]
private static extern RESULT FMOD_System_Create (out int system);
private static extern RESULT FMOD_System_Create (out int system, uint headerversion);
#endregion
}
@ -2008,6 +2004,7 @@ namespace FMOD
stringData = name.CStr();
exinfo.cbsize = (int32)sizeof(CREATESOUNDEXINFO);
//int offset = offsetof(CREATESOUNDEXINFO, channelmask);
int soundraw;
RESULT result = FMOD_System_CreateSound(rawPtr, stringData, mode, ref exinfo, out soundraw);

View file

@ -172,6 +172,12 @@ namespace System
}
[AttributeUsage(.MemberAccess)]
public struct NoStaticCtorAttribute : Attribute
{
}
[AttributeUsage(.Block)]
public struct ConstSkipAttribute : Attribute

View file

@ -13,8 +13,38 @@ namespace System
CtrlBreak
}
static Encoding InputEncoding = Encoding.ASCII;
static Encoding OutputEncoding = Encoding.ASCII;
public struct CancelInfo
{
public static Event<delegate void (CancelKind cancelKind, ref bool terminate)> sOnCancel ~ _.Dispose();
public static bool sCancelEventRegistered;
}
static Encoding sInputEncoding;
static Encoding sOutputEncoding;
static Encoding InputEncoding
{
get
{
return sInputEncoding ?? Encoding.ASCII;
}
set
{
sInputEncoding = value;
}
}
static Encoding OutputEncoding
{
get
{
return sOutputEncoding ?? Encoding.ASCII;
}
set
{
SetupOutStringEx();
sOutputEncoding = value;
}
}
static ConsoleColor sForegroundColor = .White;
static ConsoleColor sBackgroundColor = .Black;
@ -22,9 +52,6 @@ namespace System
static readonly ConsoleColor sOriginalForegroundColor = sForegroundColor;
static readonly ConsoleColor sOriginalBackgroundColor = sBackgroundColor;
static Event<delegate void (CancelKind cancelKind, ref bool terminate)> sOnCancel ~ _.Dispose();
static bool sCancelEventRegistered;
public static ConsoleColor ForegroundColor
{
get { return sForegroundColor; }
@ -56,18 +83,39 @@ namespace System
{
}
static void SetupOutStringEx()
{
OutString = => OutString_Ex;
}
static function void(StringView str) OutString = => OutString_Simple;
[CLink, CallingConvention(.Cdecl)]
static extern void putchar(char8 c);
static void OutString_Simple(StringView str)
{
for (var c in str.RawChars)
putchar(c);
}
static void OutString_Ex(StringView str)
{
Out.Write(str).IgnoreError();
}
public static ref Event<delegate void (CancelKind cancelKind, ref bool terminate)> OnCancel
{
get
{
if (!sCancelEventRegistered)
if (!CancelInfo.sCancelEventRegistered)
{
sCancelEventRegistered = true;
CancelInfo.sCancelEventRegistered = true;
#if BF_PLATFORM_WINDOWS
SetConsoleCtrlHandler(=> ConsoleCtrlHandler, true);
#endif
}
return ref sOnCancel;
return ref CancelInfo.sOnCancel;
}
}
@ -77,7 +125,7 @@ namespace System
{
bool terminate = true;
if ((ctrlType == 0) || (ctrlType == 1))
sOnCancel((.)ctrlType, ref terminate);
CancelInfo.sOnCancel((.)ctrlType, ref terminate);
return terminate ? false : true;
}
@ -286,7 +334,7 @@ namespace System
public static void Write(StringView line)
{
Out.Write(line).IgnoreError();
OutString(line);
}
public static void Write(StringView fmt, params Object[] args)
@ -308,12 +356,13 @@ namespace System
public static void WriteLine()
{
Out.Write("\n").IgnoreError();
OutString("\n");
}
public static void WriteLine(StringView line)
{
Out.WriteLine(line).IgnoreError();
OutString(line);
OutString("\n");
}
public static void WriteLine(StringView fmt, params Object[] args)

View file

@ -13,8 +13,15 @@ namespace System.Diagnostics.Contracts
Assert,
Assume,
}
#if !BF_RUNTIME_DISABLE
static extern void ReportFailure(ContractFailureKind failureKind, char8* userMessage, int32 userMessageLen, char8* conditionText, int32 conditionTextLen);
#else
static void ReportFailure(ContractFailureKind failureKind, char8* userMessage, int32 userMessageLen, char8* conditionText, int32 conditionTextLen)
{
Internal.FatalError("Contract.ReportFailure");
}
#endif
/// <summary>
/// This method is used internally to trigger a failure indicating to the "programmer" that he is using the interface incorrectly.

View file

@ -9,10 +9,16 @@ namespace System.Diagnostics
{
if (!condition)
{
if (Runtime.CheckErrorHandlers(scope Runtime.AssertError(.Debug, error, filePath, line)) == .Ignore)
if ((Runtime.CheckAssertError != null) && (Runtime.CheckAssertError(.Debug, error, filePath, line) == .Ignore))
return;
String failStr = scope .()..AppendF("Assert failed: {} at line {} in {}", error, line, filePath);
#if !BF_RUNTIME_REDUCED
String failStr = scope .()..Append("Assert failed: ", error, " at line ");
line.ToString(failStr);
failStr.Append(" in ", filePath);
Internal.FatalError(failStr, 1);
#else
Internal.FatalError("Assert failed", 1);
#endif
}
}
@ -21,7 +27,9 @@ namespace System.Diagnostics
#endif
public static void FatalError(String msg = "Fatal error encountered", String filePath = Compiler.CallerFilePath, int line = Compiler.CallerLineNum)
{
String failStr = scope .()..AppendF("{} at line {} in {}", msg, line, filePath);
String failStr = scope .()..Append(msg, " at line ");
line.ToString(failStr);
failStr.Append(" in ", filePath);
Internal.FatalError(failStr, 1);
}
@ -87,7 +95,7 @@ namespace System.Diagnostics
}
static bool gIsDebuggerPresent = IsDebuggerPresent;
[LinkName("IsDebuggerPresent"), CallingConvention(.Stdcall)]
[LinkName("IsDebuggerPresent"), CallingConvention(.Stdcall), Import("kernel32.lib")]
static extern int32 Internal_IsDebuggerPresent();
public static bool IsDebuggerPresent

View file

@ -199,7 +199,11 @@ namespace System
[CallingConvention(.Stdcall), CLink]
static extern int32 ftoa(float val, char8* str);
#if !BF_RUNTIME_DISABLE
static extern int32 ToString(double val, char8* str, bool roundTrip);
#else
static int32 ToString(double val, char8* str, bool roundTrip) => Runtime.NotImplemented();
#endif
public override void ToString(String strBuffer)
{

View file

@ -1,6 +1,7 @@
using System.IO;
using System.Collections;
using System.Text;
using System.Threading;
namespace System
{
@ -12,7 +13,23 @@ namespace System
public static readonly String NewLine = "\n";
#endif // BF_PLATFORM_WINDOWS
public static OperatingSystem OSVersion = new OperatingSystem() ~ delete _;
static OperatingSystem sOSVersion ~ delete _;
public static OperatingSystem OSVersion
{
get
{
var osVersion = new OperatingSystem();
let prevValue = Interlocked.CompareExchange(ref sOSVersion, null, osVersion);
if (prevValue != null)
{
// This was already set - race condition
delete osVersion;
return prevValue;
}
return osVersion;
}
}
public static void* ModuleHandle => Internal.[Friend]sModuleHandle;

View file

@ -147,7 +147,11 @@ namespace System
[CallingConvention(.Stdcall), CLink]
static extern int32 ftoa(float val, char8* str);
#if !BF_RUNTIME_DISABLE
static extern int32 ToString(float val, char8* str, bool roundTrip);
#else
static int32 ToString(float val, char8* str, bool roundTrip) => Runtime.FatalError();
#endif
public override void ToString(String strBuffer)
{

View file

@ -91,7 +91,7 @@ namespace System
#endif
}
#if BF_ENABLE_REALTIME_LEAK_CHECK || BF_DEBUG_ALLOC
#if (BF_ENABLE_REALTIME_LEAK_CHECK || BF_DEBUG_ALLOC) && !BF_RUNTIME_DISABLE
[CallingConvention(.Cdecl)]
public extern static void Report();
[CallingConvention(.Cdecl)]

View file

@ -13,6 +13,14 @@ namespace System
case InvalidChar(int partialResult);
}
public struct Simple : int
{
public override void ToString(String strBuffer)
{
((int)this).ToString(strBuffer);
}
}
public const int MaxValue = (sizeof(int) == 8) ? 0x7FFFFFFFFFFFFFFFL : 0x7FFFFFFF;
public const int MinValue = (sizeof(int) == 8) ? -0x8000000000000000L : -0x80000000;

View file

@ -63,11 +63,6 @@ namespace System
}
}
//static char8[] sHexUpperChars = new char8[]{'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F'} ~ delete _;
//static char8[] sHexLowerChars = new char8[]{'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f'} ~ delete _;
static String sHexUpperChars = "0123456789ABCDEF";
static String sHexLowerChars = "0123456789abcdef";
public void ToString(String outString, String format, IFormatProvider formatProvider)
{
if(format == null || format.IsEmpty)

View file

@ -81,12 +81,6 @@ namespace System
public static extern Object UnsafeCastToObject(void* ptr);
[Intrinsic("cast")]
public static extern void* UnsafeCastToPtr(Object obj);
[CallingConvention(.Cdecl), NoReturn]
public static extern void ThrowIndexOutOfRange(int stackOffset = 0);
[CallingConvention(.Cdecl), NoReturn]
public static extern void ThrowObjectNotInitialized(int stackOffset = 0);
[CallingConvention(.Cdecl), NoReturn]
public static extern void FatalError(String error, int stackOffset = 0);
[Intrinsic("memcpy")]
public static extern void MemCpy(void* dest, void* src, int length, int32 align = 1, bool isVolatile = false);
[Intrinsic("memmove")]
@ -103,6 +97,32 @@ namespace System
public static extern void StdFree(void* ptr);
[Intrinsic("returnaddress")]
public static extern void* GetReturnAddress(int32 level = 0);
[CallingConvention(.Cdecl)]
static extern void Test_Init(char8* testData);
[CallingConvention(.Cdecl)]
static extern void Test_Error(char8* error);
[CallingConvention(.Cdecl)]
static extern void Test_Write(char8* str);
[CallingConvention(.Cdecl)]
static extern int32 Test_Query();
[CallingConvention(.Cdecl)]
static extern void Test_Finish();
static void* sModuleHandle;
[AlwaysInclude]
static void SetModuleHandle(void* handle)
{
sModuleHandle = handle;
}
#if !BF_RUNTIME_DISABLE
[CallingConvention(.Cdecl), NoReturn]
public static extern void ThrowIndexOutOfRange(int stackOffset = 0);
[CallingConvention(.Cdecl), NoReturn]
public static extern void ThrowObjectNotInitialized(int stackOffset = 0);
[CallingConvention(.Cdecl), NoReturn]
public static extern void FatalError(String error, int stackOffset = 0);
[CallingConvention(.Cdecl)]
public static extern void* VirtualAlloc(int size, bool canExecute, bool canWrite);
[CallingConvention(.Cdecl)]
@ -160,25 +180,236 @@ namespace System
[CallingConvention(.Cdecl)]
public static extern void Dbg_RawFree(void* ptr);
[CallingConvention(.Cdecl), AlwaysInclude]
static extern void Shutdown();
[CallingConvention(.Cdecl)]
static extern void Test_Init(char8* testData);
[CallingConvention(.Cdecl)]
static extern void Test_Error(char8* error);
[CallingConvention(.Cdecl)]
static extern void Test_Write(char8* str);
[CallingConvention(.Cdecl)]
static extern int32 Test_Query();
[CallingConvention(.Cdecl)]
static extern void Test_Finish();
static extern void Shutdown_Internal();
static void* sModuleHandle;
[AlwaysInclude]
static void SetModuleHandle(void* handle)
[CallingConvention(.Cdecl), AlwaysInclude]
static void Shutdown()
{
sModuleHandle = handle;
Shutdown_Internal();
Runtime.Shutdown();
}
#else
enum BfObjectFlags : uint8
{
None = 0,
Mark1 = 0x01,
Mark2 = 0x02,
Mark3 = 0x03,
Allocated = 0x04,
StackAlloc = 0x08,
AppendAlloc = 0x10,
AllocInfo = 0x20,
AllocInfo_Short = 0x40,
Deleted = 0x80
};
[NoReturn]
static void Crash()
{
char8* ptr = null;
*ptr = 'A';
}
[AlwaysInclude, NoReturn]
public static void ThrowIndexOutOfRange(int stackOffset = 0)
{
Crash();
}
[AlwaysInclude, NoReturn]
public static void ThrowObjectNotInitialized(int stackOffset = 0)
{
Crash();
}
[AlwaysInclude, NoReturn]
public static void FatalError(String error, int stackOffset = 0)
{
Crash();
}
[AlwaysInclude]
public static void* VirtualAlloc(int size, bool canExecute, bool canWrite)
{
return null;
}
public static int32 CStrLen(char8* charPtr)
{
int32 len = 0;
while (charPtr[len] != 0)
len++;
return len;
}
public static int64 GetTickCountMicro()
{
return 0;
}
[AlwaysInclude]
public static void BfDelegateTargetCheck(void* target)
{
}
[AlwaysInclude]
public static void* LoadSharedLibrary(char8* filePath)
{
return null;
}
[AlwaysInclude]
public static void LoadSharedLibraryInto(char8* filePath, void** libDest)
{
}
[AlwaysInclude]
public static void* GetSharedProcAddress(void* libHandle, char8* procName)
{
return null;
}
[AlwaysInclude]
public static void GetSharedProcAddressInto(void* libHandle, char8* procName, void** procDest)
{
}
[AlwaysInclude]
public static char8* GetCommandLineArgs()
{
return "";
}
public static void ProfilerCmd(char8* str)
{
}
public static void ReportMemory()
{
}
public static void ObjectDynCheck(Object obj, int32 typeId, bool allowNull)
{
}
public static void ObjectDynCheckFailed(Object obj, int32 typeId)
{
}
[DisableChecks, DisableObjectAccessChecks]
public static void Dbg_ObjectCreated(Object obj, int size, ClassVData* classVData)
{
}
[DisableChecks, DisableObjectAccessChecks]
public static void Dbg_ObjectCreatedEx(Object obj, int size, ClassVData* classVData)
{
}
[DisableChecks, DisableObjectAccessChecks]
public static void Dbg_ObjectAllocated(Object obj, int size, ClassVData* classVData)
{
#if BF_ENABLE_OBJECT_DEBUG_FLAGS
obj.[Friend]mClassVData = (.)(void*)classVData;
obj.[Friend]mDbgAllocInfo = (.)GetReturnAddress(0);
#else
obj.[Friend]mClassVData = classVData;
#endif
}
[DisableChecks, DisableObjectAccessChecks]
public static void Dbg_ObjectAllocatedEx(Object obj, int size, ClassVData* classVData)
{
#if BF_ENABLE_OBJECT_DEBUG_FLAGS
obj.[Friend]mClassVData = (.)(void*)classVData;
obj.[Friend]mDbgAllocInfo = (.)GetReturnAddress(0);
#else
obj.[Friend]mClassVData = classVData;
#endif
}
public static int Dbg_PrepareStackTrace(int baseAllocSize, int maxStackTraceDepth)
{
return 0;
}
[DisableChecks, DisableObjectAccessChecks]
public static void Dbg_ObjectStackInit(Object obj, ClassVData* classVData)
{
#if BF_ENABLE_OBJECT_DEBUG_FLAGS
obj.[Friend]mClassVData = (.)(void*)classVData;
obj.[Friend]mClassVData |= (.)BfObjectFlags.StackAlloc;
obj.[Friend]mDbgAllocInfo = (.)GetReturnAddress(0);
#else
obj.[Friend]mClassVData = classVData;
#endif
}
public static Object Dbg_ObjectAlloc(TypeInstance typeInst, int size)
{
return null;
}
public static Object Dbg_ObjectAlloc(ClassVData* classVData, int size, int align, int maxStackTraceDepth)
{
return null;
}
public static void Dbg_ObjectPreDelete(Object obj)
{
}
public static void Dbg_ObjectPreCustomDelete(Object obj)
{
}
public static void Dbg_MarkObjectDeleted(Object obj)
{
#if BF_ENABLE_OBJECT_DEBUG_FLAGS
obj.[Friend]mClassVData |= (.)BfObjectFlags.Deleted;
#endif
}
public static void* Dbg_RawAlloc(int size)
{
return null;
}
public static void* Dbg_RawObjectAlloc(int size)
{
return null;
}
public static void* Dbg_RawAlloc(int size, DbgRawAllocData* rawAllocData)
{
return null;
}
public static void Dbg_RawFree(void* ptr)
{
}
[AlwaysInclude]
static void Shutdown()
{
}
#endif
[AlwaysInclude]
static void AddRtFlags(int32 flags)
{
@ -209,15 +440,15 @@ namespace System
}
[Error("Cannot be called directly"), SkipCall]
static void SetDeleted1(void* dest);
static void SetDeleted1(void* dest);
[Error("Cannot be called directly"), SkipCall]
static void SetDeleted4(void* dest);
static void SetDeleted4(void* dest);
[Error("Cannot be called directly"), SkipCall]
static void SetDeleted8(void* dest);
static void SetDeleted8(void* dest);
[Error("Cannot be called directly"), SkipCall]
static void SetDeleted16(void* dest);
static void SetDeleted16(void* dest);
[Error("Cannot be called directly"), SkipCall]
static extern void SetDeletedX(void* dest, int size);
static extern void SetDeletedX(void* dest, int size);
[Error("Cannot be called directly"), SkipCall]
static extern void SetDeleted(void* dest, int size, int32 align);
[Error("Cannot be called directly"), SkipCall]
@ -254,9 +485,9 @@ namespace System
}
}
[AlwaysInclude]
public static String[] CreateParamsArray()
{
#if !BF_RUNTIME_DISABLE
char8* cmdLine = GetCommandLineArgs();
//Windows.MessageBoxA(default, scope String()..AppendF("CmdLine: {0}", StringView(cmdLine)), "HI", 0);
@ -336,7 +567,7 @@ namespace System
if (firstCharIdx == -1)
firstCharIdx = i;
if (c == '^')
{
{
i++;
}
if (c == '"')
@ -357,9 +588,11 @@ namespace System
}
return strVals;
#else
return new String[0];
#endif
}
[AlwaysInclude]
public static void DeleteStringArray(String[] arr)
{
for (var str in arr)
@ -367,8 +600,10 @@ namespace System
delete arr;
}
#if !BF_RUNTIME_DISABLE
extern static this();
extern static ~this();
#endif
}
struct CRTAlloc

View file

@ -223,7 +223,8 @@ namespace System
modf(d, out intPart);
return intPart;
}
#if !BF_RUNTIME_DISABLE
public static extern float Sqrt(float f);
public static extern double Sqrt(double d);
public static extern float Cbrt(float f);
@ -236,6 +237,20 @@ namespace System
public static extern double Exp(double d);
public static extern float Pow(float x, float y);
public static extern double Pow(double x, double y);
#else
public static float Sqrt(float f) => Runtime.NotImplemented();
public static double Sqrt(double d) => Runtime.NotImplemented();
public static float Cbrt(float f) => Runtime.NotImplemented();
public static double Cbrt(double d) => Runtime.NotImplemented();
public static float Log(float f) => Runtime.NotImplemented();
public static double Log(double d) => Runtime.NotImplemented();
public static float Log10(float f) => Runtime.NotImplemented();
public static double Log10(double d) => Runtime.NotImplemented();
public static float Exp(float f) => Runtime.NotImplemented();
public static double Exp(double d) => Runtime.NotImplemented();
public static float Pow(float x, float y) => Runtime.NotImplemented();
public static double Pow(double x, double y) => Runtime.NotImplemented();
#endif
public static float IEEERemainder(float x, float y)
{

View file

@ -1130,12 +1130,14 @@ namespace System
// Hexadecimal digits representation.
private static uint32 FastToDecHex (int32 val)
{
var decHexDigits = DecHexDigits;
if (val < 100)
return (uint32)DecHexDigits [val];
return (uint32)decHexDigits[val];
// Uses 2^19 (524288) to compute val / 100 for val < 10000.
int32 v = (val * 5243) >> 19;
return (uint32)((DecHexDigits [v] << 8) | DecHexDigits [val - v * 100]);
return (uint32)((decHexDigits[v] << 8) | decHexDigits[val - v * 100]);
}
// Helper to translate an int in the range 0 .. 99999999 to its
@ -1741,6 +1743,31 @@ namespace System
inst.IntegerToString(format, fp, outString);
}
public static void AddrToString (uint value, String outString)
{
const int bufLen = 18;
char8* strChars = scope:: char8[bufLen]* (?);
int32 curLen = 0;
uint64 valLeft = (.)value;
while (valLeft > 0)
{
if (curLen == 8)
strChars[bufLen - curLen++ - 1] = '\'';
strChars[bufLen - curLen++ - 1] = DigitUpperTable[(int)(valLeft & 0xF)];
valLeft >>= 4;
}
while (curLen < 10)
{
if (curLen == 8)
strChars[bufLen - curLen++ - 1] = '\'';
strChars[bufLen - curLen++ - 1] = '0';
}
char8* char8Ptr = &strChars[bufLen - curLen];
outString.Append(char8Ptr, curLen);
}
public static void NumberToString (StringView format, int32 value, IFormatProvider fp, String outString)
{
NumberFormatter inst = GetInstance!(fp);

View file

@ -10,10 +10,11 @@ namespace System
#if BF_ENABLE_OBJECT_DEBUG_FLAGS
int mClassVData;
int mDbgAllocInfo;
#else
#else
ClassVData* mClassVData;
#endif
[AlwaysInclude]
public virtual ~this()
{
#if BF_ENABLE_OBJECT_DEBUG_FLAGS
@ -47,42 +48,79 @@ namespace System
if (Compiler.IsComptime)
return Comptime_GetType();
Type type;
ClassVData* classVData;
#if BF_ENABLE_OBJECT_DEBUG_FLAGS
ClassVData* maskedVData = (ClassVData*)(void*)(mClassVData & ~(int)0xFF);
type = maskedVData.mType;
classVData = (ClassVData*)(void*)(mClassVData & ~(int)0xFF);
#else
type = mClassVData.mType;
classVData = mClassVData;
#endif
#if BF_32_BIT
Type type = Type.[Friend]GetType_(classVData.mType2);
#else
Type type = Type.[Friend]GetType_((.)(classVData.mType >> 32));
#endif
if ((type.[Friend]mTypeFlags & TypeFlags.Boxed) != 0)
{
//int32 underlyingType = (int32)((TypeInstance)type).mUnderlyingType;
type = Type.[Friend]GetType(((TypeInstance)type).[Friend]mUnderlyingType);
}
return type;
}
TypeId GetTypeId()
{
ClassVData* classVData;
#if BF_ENABLE_OBJECT_DEBUG_FLAGS
classVData = (ClassVData*)(void*)(mClassVData & ~(int)0xFF);
#else
classVData = mClassVData;
#endif
#if BF_32_BIT
return (.)classVData.mType2;
#else
return (.)(classVData.mType >> 32);
#endif
}
[NoShow]
Type RawGetType()
{
if (Compiler.IsComptime)
return Comptime_GetType();
Type type;
ClassVData* classVData;
#if BF_ENABLE_OBJECT_DEBUG_FLAGS
ClassVData* maskedVData = (ClassVData*)(void*)(mClassVData & ~(int)0xFF);
type = maskedVData.mType;
#else
type = mClassVData.mType;
#endif
return type;
classVData = (ClassVData*)(void*)(mClassVData & ~(int)0xFF);
#else
classVData = mClassVData;
#endif
#if BF_32_BIT
Type type = Type.[Friend]GetType_(classVData.mType);
#else
Type type = Type.[Friend]GetType_((.)(classVData.mType & 0xFFFFFFFF));
#endif
return type;
}
TypeId RawGetTypeId()
{
ClassVData* classVData;
#if BF_ENABLE_OBJECT_DEBUG_FLAGS
classVData = (ClassVData*)(void*)(mClassVData & ~(int)0xFF);
#else
classVData = mClassVData;
#endif
#if BF_32_BIT
return (.)classVData.mType;
#else
return (.)(classVData.mType & 0xFFFFFFFF);
#endif
}
#if BF_DYNAMIC_CAST_CHECK || BF_ENABLE_REALTIME_LEAK_CHECK
[NoShow]
public virtual Object DynamicCastToTypeId(int32 typeId)
{
if (typeId == (int32)RawGetType().[Friend]mTypeId)
if (typeId == (.)RawGetTypeId())
return this;
return null;
}
@ -98,9 +136,13 @@ namespace System
{
return (int)Internal.UnsafeCastToPtr(this);
}
public virtual void ToString(String strBuffer)
{
#if BF_REFLECT_MINIMAL
strBuffer.AppendF($"Type#{(Int.Simple)GetTypeId()}@0x");
NumberFormatter.AddrToString((uint)Internal.UnsafeCastToPtr(this), strBuffer);
#else
let t = RawGetType();
if (t.IsBoxedStructPtr)
{
@ -108,13 +150,15 @@ namespace System
let innerPtr = *(void**)((uint8*)Internal.UnsafeCastToPtr(this) + ti.[Friend]mMemberDataOffset);
strBuffer.Append("(");
ti.UnderlyingType.GetFullName(strBuffer);
strBuffer.AppendF("*)0x{0:A}", (uint)(void*)innerPtr);
//strBuffer.AppendF("*)0x{0:A}", (UInt.Simple)(uint)(void*)innerPtr);
strBuffer.Append("*)0x");
NumberFormatter.AddrToString((uint)(void*)innerPtr, strBuffer);
return;
}
t.GetFullName(strBuffer);
strBuffer.Append("@0x");
((int)Internal.UnsafeCastToPtr(this)).ToString(strBuffer, "A", null);
NumberFormatter.AddrToString((uint)Internal.UnsafeCastToPtr(this), strBuffer);
#endif
}
private static void ToString(Object obj, String strBuffer)
@ -124,7 +168,7 @@ namespace System
else
obj.ToString(strBuffer);
}
[SkipCall, NoShow]
protected virtual void GCMarkMembers()
{

View file

@ -78,7 +78,7 @@ namespace System
public uint32 dwFileDateLS; // e.g. 0
}
[CLink, CallingConvention(.Stdcall)]
[Import("kernel32.lib"), CLink, CallingConvention(.Stdcall)]
extern static bool GetVersionExA(OSVersionInfoExA* lpVersionInformation);
[CLink, CallingConvention(.Stdcall)]
@ -274,9 +274,9 @@ namespace System
String arch = Arch32;
#endif
if (Version.Revision == 0)
outVar.AppendF("{} (Version {}.{}, Build {}, {})", Name, Version.Major, Version.Minor, Version.Build, arch);
outVar.AppendF("{} (Version {}.{}, Build {}, {})", Name, (UInt.Simple)Version.Major, (UInt.Simple)Version.Minor, (UInt.Simple)Version.Build, arch);
else
outVar.AppendF("{} Service Pack {} (Version {}.{}, Build {}, {})", Name, Version.Revision, Version.Major, Version.Minor, Version.Build, arch);
outVar.AppendF("{} Service Pack {} (Version {}.{}, Build {}, {})", Name, (UInt.Simple)Version.Revision, (UInt.Simple)Version.Major, (UInt.Simple)Version.Minor, (UInt.Simple)Version.Build, arch);
#elif BF_PLATFORM_LINUX
outVar.AppendF("{} {} (Version {}.{}.{})", PrettyName, Name, Version.Major, Version.Minor, Version.Revision);
#else // MACOS and ANDROID

View file

@ -34,15 +34,29 @@ namespace System
NotEmpty
};
public struct BfpCritSect {}
public struct BfpSpawn {}
public struct BfpFile {}
public struct BfpFindFileData {}
public struct BfpDynLib {}
public struct BfpEvent {};
public struct BfpFileWatcher {}
public struct BfpProcess {}
public struct BfpTLS;
#if !BF_RUNTIME_DISABLE
public struct BfpCritSect {}
public struct BfpEvent {};
#else
public struct BfpCritSect
{
public int mEmpty;
}
public struct BfpEvent
{
public bool mSet;
public bool mAuto;
};
#endif
public enum BfpSystemResult : int32
{
@ -51,6 +65,7 @@ namespace System
TempFileError = (int)Result.TempFileError
}
#if !BF_RUNTIME_DISABLE
[CallingConvention(.Stdcall), CLink]
public static extern uint32 BfpSystem_TickCount();
[CallingConvention(.Stdcall), CLink]
@ -107,6 +122,62 @@ namespace System
public static extern void BfpTLS_SetValue(BfpTLS* tls, void* value);
[CallingConvention(.Stdcall), CLink]
public static extern void* BfpTLS_GetValue(BfpTLS* tls);
#else
public static uint32 BfpSystem_TickCount() => Runtime.NotImplemented();
public static uint32 BfpSystem_SetCrashRelaunchCmd(char8* cmd) => Runtime.NotImplemented();
public static BfpTimeStamp BfpSystem_GetTimeStamp() => Runtime.NotImplemented();
public static uint8 BfpSystem_InterlockedExchange8(uint8* ptr, uint8 val) => Runtime.NotImplemented();
public static uint16 BfpSystem_InterlockedExchange16(uint16* ptr, uint16 val) => Runtime.NotImplemented();
public static uint32 BfpSystem_InterlockedExchange32(uint32* ptr, uint32 val) => Runtime.NotImplemented();
public static uint64 BfpSystem_InterlockedExchange64(uint64* ptr, uint64 val) => Runtime.NotImplemented();
public static uint8 BfpSystem_InterlockedExchangeAdd8(uint8* ptr, uint8 val) => Runtime.NotImplemented();
public static uint16 BfpSystem_InterlockedExchangeAdd16(uint16* ptr, uint16 val) => Runtime.NotImplemented(); /// Returns the initial value in 'ptr'
public static uint32 BfpSystem_InterlockedExchangeAdd32(uint32* ptr, uint32 val) => Runtime.NotImplemented(); /// Returns the initial value in 'ptr'
public static uint64 BfpSystem_InterlockedExchangeAdd64(uint64* ptr, uint64 val) => Runtime.NotImplemented();
public static uint8 BfpSystem_InterlockedCompareExchange8(uint8* ptr, uint8 oldVal, uint8 newVal) => Runtime.NotImplemented();
public static uint16 BfpSystem_InterlockedCompareExchange16(uint16* ptr, uint16 oldVal, uint16 newVal) => Runtime.NotImplemented();
public static uint32 BfpSystem_InterlockedCompareExchange32(uint32* ptr, uint32 oldVal, uint32 newVal) => Runtime.NotImplemented();
public static uint64 BfpSystem_InterlockedCompareExchange64(uint64* ptr, uint64 oldVal, uint64 newVal) => Runtime.NotImplemented();
public static void BfpSystem_GetExecutablePath(char8* outStr, int32* inOutStrSize, BfpSystemResult* outResult) => Runtime.NotImplemented();
public static void BfpSystem_GetEnvironmentStrings(char8* outStr, int32* inOutStrSize, BfpSystemResult* outResult) => Runtime.NotImplemented();
public static int32 BfpSystem_GetNumLogicalCPUs(BfpSystemResult* outResult) => Runtime.NotImplemented();
public static int64 BfpSystem_GetCPUTick() => Runtime.NotImplemented();
public static int64 BfpSystem_GetCPUTickFreq() => Runtime.NotImplemented();
public static void BfpSystem_CreateGUID(Guid* outGuid) => Runtime.NotImplemented();
public static void BfpSystem_GetComputerName(char8* outStr, int32* inOutStrSize, BfpSystemResult* outResult) => Runtime.NotImplemented();
public static int BfpThread_GetCurrentId() => Runtime.NotImplemented();
public static BfpTLS* BfpTLS_Create(function [CallingConvention(.Stdcall)] void(void*) exitProc) => Runtime.NotImplemented();
public static void BfpTLS_Release(BfpTLS* tls) => Runtime.NotImplemented();
public static void BfpTLS_SetValue(BfpTLS* tls, void* value) => Runtime.NotImplemented();
public static void* BfpTLS_GetValue(BfpTLS* tls) => Runtime.NotImplemented();
#endif
public enum BfpFileWatcherFlags : int32
{
@ -125,10 +196,16 @@ namespace System
public function void BfpDirectoryChangeFunc(BfpFileWatcher* watcher, void* userData, BfpFileChangeKind changeKind, char8* directory, char8* fileName, char8* oldName);
#if !BF_RUNTIME_DISABLE
[CallingConvention(.Stdcall), CLink]
public static extern BfpFileWatcher* BfpFileWatcher_WatchDirectory(char8* path, BfpDirectoryChangeFunc callback, BfpFileWatcherFlags flags, void* userData, BfpFileResult* outResult);
[CallingConvention(.Stdcall), CLink]
public static extern void BfpFileWatcher_Release(BfpFileWatcher* fileWatcher);
#else
public static BfpFileWatcher* BfpFileWatcher_WatchDirectory(char8* path, BfpDirectoryChangeFunc callback, BfpFileWatcherFlags flags, void* userData, BfpFileResult* outResult) => Runtime.NotImplemented();
public static void BfpFileWatcher_Release(BfpFileWatcher* fileWatcher) => Runtime.NotImplemented();
#endif
public enum BfpProcessResult : int32
{
@ -136,6 +213,7 @@ namespace System
InsufficientBuffer = (int)Result.InsufficientBuffer
}
#if !BF_RUNTIME_DISABLE
[CallingConvention(.Stdcall), CLink]
public static extern bool BfpProcess_IsRemoteMachine(char8* machineName);
[CallingConvention(.Stdcall), CLink]
@ -150,6 +228,22 @@ namespace System
public static extern void BfpProcess_GetProcessName(BfpProcess* process, char8* outName, int32* inOutNameSize, BfpProcessResult* outResult);
[CallingConvention(.Stdcall), CLink]
public static extern int32 BfpProcess_GetProcessId(BfpProcess* process);
#else
public static bool BfpProcess_IsRemoteMachine(char8* machineName) => Runtime.NotImplemented();
public static BfpProcess* BfpProcess_GetById(char8* machineName, int32 processId, BfpProcessResult* outResult) => Runtime.NotImplemented();
public static void BfpProcess_Enumerate(char8* machineName, BfpProcess** outProcesses, int32* inOutProcessesSize, BfpProcessResult* outResult) => Runtime.NotImplemented();
public static void BfpProcess_Release(BfpProcess* process) => Runtime.NotImplemented();
public static void BfpProcess_GetMainWindowTitle(BfpProcess* process, char8* outTitle, int32* inOutTitleSize, BfpProcessResult* outResult) => Runtime.NotImplemented();
public static void BfpProcess_GetProcessName(BfpProcess* process, char8* outName, int32* inOutNameSize, BfpProcessResult* outResult) => Runtime.NotImplemented();
public static int32 BfpProcess_GetProcessId(BfpProcess* process) => Runtime.NotImplemented();
#endif
public enum BfpSpawnFlags : int32
{
@ -181,6 +275,7 @@ namespace System
UnknownError = (int)Result.UnknownError
};
#if !BF_RUNTIME_DISABLE
[CallingConvention(.Stdcall), CLink]
public static extern BfpSpawn* BfpSpawn_Create(char8* targetPath, char8* args, char8* workingDir, char8* env, BfpSpawnFlags flags, BfpSpawnResult* outResult);
[CallingConvention(.Stdcall), CLink]
@ -205,6 +300,47 @@ namespace System
public static extern bool BfpCritSect_TryEnter(BfpCritSect* critSect, int32 waitMS);
[CallingConvention(.Stdcall), CLink]
public static extern void BfpCritSect_Leave(BfpCritSect* critSect);
#else
public static BfpSpawn* BfpSpawn_Create(char8* targetPath, char8* args, char8* workingDir, char8* env, BfpSpawnFlags flags, BfpSpawnResult* outResult)
{
*outResult = .UnknownError;
return null;
}
public static void BfpSpawn_Release(BfpSpawn* spawn) => Runtime.NotImplemented();
public static void BfpSpawn_Kill(BfpSpawn* spawn, int32 exitCode, BfpKillFlags killFlags, BfpSpawnResult* outResult) => Runtime.NotImplemented();
public static bool BfpSpawn_WaitFor(BfpSpawn* spawn, int waitMS, int* outExitCode, BfpSpawnResult* outResult) => Runtime.NotImplemented();
public static void BfpSpawn_GetStdHandles(BfpSpawn* spawn, BfpFile** outStdIn, BfpFile** outStdOut, BfpFile** outStdErr) => Runtime.NotImplemented();
public static int BfpProcess_GetCurrentId() => Runtime.NotImplemented();
public static BfpCritSect* BfpCritSect_Create() => new BfpCritSect();
public static void BfpCritSect_Release(BfpCritSect* critSect)
{
delete critSect;
}
public static void BfpCritSect_Enter(BfpCritSect* critSect)
{
}
public static bool BfpCritSect_TryEnter(BfpCritSect* critSect, int32 waitMS)
{
return true;
}
public static void BfpCritSect_Leave(BfpCritSect* critSect)
{
}
#endif
public enum BfpEventFlags : int32
{
@ -221,6 +357,7 @@ namespace System
BfpEventResult_NotSupported = (int)Result.NotSupported
};
#if !BF_RUNTIME_DISABLE
[CallingConvention(.Stdcall), CLink]
public static extern BfpEvent* BfpEvent_Create(BfpEventFlags flags);
[CallingConvention(.Stdcall), CLink]
@ -231,6 +368,46 @@ namespace System
public static extern void BfpEvent_Reset(BfpEvent* event, BfpEventResult* outResult);
[CallingConvention(.Stdcall), CLink]
public static extern bool BfpEvent_WaitFor(BfpEvent* event, int32 waitMS);
#else
public static BfpEvent* BfpEvent_Create(BfpEventFlags flags)
{
var result = new BfpEvent();
result.mSet = flags.HasFlag(.InitiallySet_Auto) | flags.HasFlag(.InitiallySet_Manual);
result.mAuto = flags.HasFlag(.InitiallySet_Auto);
return result;
}
public static void BfpEvent_Release(BfpEvent* event)
{
delete event;
}
public static void BfpEvent_Set(BfpEvent* event, bool requireManualReset)
{
event.mSet = true;
event.mAuto = !requireManualReset;
}
public static void BfpEvent_Reset(BfpEvent* event, BfpEventResult* outResult)
{
event.mSet = false;
event.mAuto = false;
*outResult = .BfpEventResult_Ok;
}
public static bool BfpEvent_WaitFor(BfpEvent* event, int32 waitMS)
{
if (!event.mSet)
return false;
if (event.mAuto)
{
event.mSet = false;
event.mAuto = false;
}
return true;
}
#endif
public enum BfpLibResult : int32
{
@ -239,6 +416,7 @@ namespace System
InsufficientBuffer = (int)Result.InsufficientBuffer
};
#if !BF_RUNTIME_DISABLE
[CallingConvention(.Stdcall), CLink]
public static extern BfpDynLib* BfpDynLib_Load(char8* fileName);
[CallingConvention(.Stdcall), CLink]
@ -247,6 +425,16 @@ namespace System
public static extern void BfpDynLib_GetFilePath(BfpDynLib* lib, char8* outPath, int32* inOutPathSize, BfpLibResult* outResult);
[CallingConvention(.Stdcall), CLink]
public static extern void* BfpDynLib_GetProcAddress(BfpDynLib* lib, char8* name);
#else
public static BfpDynLib* BfpDynLib_Load(char8* fileName) => Runtime.NotImplemented();
public static void BfpDynLib_Release(BfpDynLib* lib) => Runtime.NotImplemented();
public static void BfpDynLib_GetFilePath(BfpDynLib* lib, char8* outPath, int32* inOutPathSize, BfpLibResult* outResult) => Runtime.NotImplemented();
public static void* BfpDynLib_GetProcAddress(BfpDynLib* lib, char8* name) => Runtime.NotImplemented();
#endif
public enum BfpFileResult : int32
{
@ -265,6 +453,7 @@ namespace System
NotEmpty = (int)Result.NotEmpty,
};
#if !BF_RUNTIME_DISABLE
[CallingConvention(.Stdcall), CLink]
public static extern void BfpDirectory_Create(char8* name, BfpFileResult* outResult);
[CallingConvention(.Stdcall), CLink]
@ -279,6 +468,22 @@ namespace System
public static extern bool BfpDirectory_Exists(char8* path);
[CallingConvention(.Stdcall), CLink]
public static extern void BfpDirectory_GetSysDirectory(BfpSysDirectoryKind sysDirKind, char8* outPath, int32* inOutPathLen, BfpFileResult* outResult);
#else
public static void BfpDirectory_Create(char8* name, BfpFileResult* outResult) => Runtime.NotImplemented();
public static void BfpDirectory_Rename(char8* oldName, char8* newName, BfpFileResult* outResult) => Runtime.NotImplemented();
public static void BfpDirectory_Delete(char8* name, BfpFileResult* outResult) => Runtime.NotImplemented();
public static void BfpDirectory_GetCurrent(char8* outPath, int32* inOutPathSize, BfpFileResult* outResult) => Runtime.NotImplemented();
public static void BfpDirectory_SetCurrent(char8* path, BfpFileResult* outResult) => Runtime.NotImplemented();
public static bool BfpDirectory_Exists(char8* path) => Runtime.NotImplemented();
public static void BfpDirectory_GetSysDirectory(BfpSysDirectoryKind sysDirKind, char8* outPath, int32* inOutPathLen, BfpFileResult* outResult) => Runtime.NotImplemented();
#endif
public enum BfpFileCreateKind : int32
{
@ -347,6 +552,7 @@ namespace System
In
}
#if !BF_RUNTIME_DISABLE
[CallingConvention(.Stdcall), CLink]
public static extern BfpFile* BfpFile_Create(char8* name, BfpFileCreateKind createKind, BfpFileCreateFlags createFlags, BfpFileAttributes createdFileAttrs, BfpFileResult* outResult);
[CallingConvention(.Stdcall), CLink]
@ -389,6 +595,50 @@ namespace System
public static extern void BfpFile_GetFullPath(char8* inPath, char8* outPath, int32* inOutPathSize, BfpFileResult* outResult);
[CallingConvention(.Stdcall), CLink]
public static extern void BfpFile_GetActualPath(char8* inPath, char8* outPath, int32* inOutPathSize, BfpFileResult* outResult);
#else
public static BfpFile* BfpFile_Create(char8* name, BfpFileCreateKind createKind, BfpFileCreateFlags createFlags, BfpFileAttributes createdFileAttrs, BfpFileResult* outResult) => Runtime.NotImplemented();
public static BfpFile* BfpFile_GetStd(BfpFileStdKind kind, BfpFileResult* outResult) => Runtime.NotImplemented();
public static int BfpFile_GetSystemHandle(BfpFile* file) => Runtime.NotImplemented();
public static void BfpFile_Release(BfpFile* file) => Runtime.NotImplemented();
public static int BfpFile_Write(BfpFile* file, void* buffer, int size, int timeoutMS, BfpFileResult* outResult) => Runtime.NotImplemented();
public static int BfpFile_Read(BfpFile* file, void* buffer, int size, int timeoutMS, BfpFileResult* outResult) => Runtime.NotImplemented();
public static void BfpFile_Flush(BfpFile* file) => Runtime.NotImplemented();
public static int64 BfpFile_GetFileSize(BfpFile* file) => Runtime.NotImplemented();
public static int64 BfpFile_Seek(BfpFile* file, int64 offset, BfpFileSeekKind seekKind) => Runtime.NotImplemented();
public static void BfpFile_Truncate(BfpFile* file, BfpFileResult* outResult) => Runtime.NotImplemented();
public static BfpTimeStamp BfpFile_GetTime_LastWrite(char8* path) => Runtime.NotImplemented();
public static BfpFileAttributes BfpFile_GetAttributes(char8* path, BfpFileResult* outResult) => Runtime.NotImplemented();
public static void BfpFile_SetAttributes(char8* path, BfpFileAttributes attribs, BfpFileResult* outResult) => Runtime.NotImplemented();
public static void BfpFile_Copy(char8* oldPath, char8* newPath, BfpFileCopyKind copyKind, BfpFileResult* outResult) => Runtime.NotImplemented();
public static void BfpFile_Rename(char8* oldPath, char8* newPath, BfpFileResult* outResult) => Runtime.NotImplemented();
public static void BfpFile_Delete(char8* path, BfpFileResult* outResult) => Runtime.NotImplemented();
public static bool BfpFile_Exists(char8* path) => Runtime.NotImplemented();
public static void BfpFile_GetTempPath(char8* outPath, int32* inOutPathSize, BfpFileResult* outResult) => Runtime.NotImplemented();
public static void BfpFile_GetTempFileName(char8* outName, int32* inOutNameSize, BfpFileResult* outResult) => Runtime.NotImplemented();
public static void BfpFile_GetFullPath(char8* inPath, char8* outPath, int32* inOutPathSize, BfpFileResult* outResult) => Runtime.NotImplemented();
public static void BfpFile_GetActualPath(char8* inPath, char8* outPath, int32* inOutPathSize, BfpFileResult* outResult) => Runtime.NotImplemented();
#endif
public enum BfpFindFileFlags : int32
{
@ -397,6 +647,7 @@ namespace System
Directories = 2,
};
#if !BF_RUNTIME_DISABLE
[CallingConvention(.Stdcall), CLink]
public static extern BfpFindFileData* BfpFindFileData_FindFirstFile(char8* path, BfpFindFileFlags flags, BfpFileResult* outResult);
[CallingConvention(.Stdcall), CLink]
@ -415,6 +666,26 @@ namespace System
public static extern int64 BfpFindFileData_GetFileSize(BfpFindFileData* findData);
[CallingConvention(.Stdcall), CLink]
public static extern void BfpFindFileData_Release(BfpFindFileData* findData);
#else
public static BfpFindFileData* BfpFindFileData_FindFirstFile(char8* path, BfpFindFileFlags flags, BfpFileResult* outResult) => Runtime.NotImplemented();
public static bool BfpFindFileData_FindNextFile(BfpFindFileData* findData) => Runtime.NotImplemented();
public static void BfpFindFileData_GetFileName(BfpFindFileData* findData, char8* outName, int32* inOutNameSize, BfpFileResult* outResult) => Runtime.NotImplemented();
public static BfpTimeStamp BfpFindFileData_GetTime_LastWrite(BfpFindFileData* findData) => Runtime.NotImplemented();
public static BfpTimeStamp BfpFindFileData_GetTime_Created(BfpFindFileData* findData) => Runtime.NotImplemented();
public static BfpTimeStamp BfpFindFileData_GetTime_Access(BfpFindFileData* findData) => Runtime.NotImplemented();
public static BfpFileAttributes BfpFindFileData_GetFileAttributes(BfpFindFileData* findData) => Runtime.NotImplemented();
public static int64 BfpFindFileData_GetFileSize(BfpFindFileData* findData) => Runtime.NotImplemented();
public static void BfpFindFileData_Release(BfpFindFileData* findData) => Runtime.NotImplemented();
#endif
public enum BfpSysDirectoryKind : int32
{

View file

@ -18,7 +18,7 @@ namespace System
public override void ToString(String strBuffer)
{
strBuffer.AppendF("0x{0:A}", (uint)(void*)mVal);
strBuffer.AppendF("0x{0:A}", (UInt.Simple)(uint)(void*)mVal);
}
}
@ -34,8 +34,8 @@ namespace System
public override void ToString(String strBuffer)
{
strBuffer.Append("(");
typeof(T).GetFullName(strBuffer);
strBuffer.AppendF("*)0x{0:A}", (uint)(void*)mVal);
typeof(T).ToString(strBuffer);
strBuffer.AppendF("*)0x{0:A}", (UInt.Simple)(uint)(void*)mVal);
}
}
}

View file

@ -1,9 +1,11 @@
using System.Threading;
using System.Collections;
#if BF_ENABLE_OBJECT_DEBUG_FLAGS || BF_DEBUG_ALLOC
#if (BF_ENABLE_OBJECT_DEBUG_FLAGS || BF_DEBUG_ALLOC) && !BF_RUNTIME_DISABLE
#define BF_DBG_RUNTIME
#endif
using internal System.Threading.Thread;
namespace System
{
struct RuntimeFeatures
@ -17,7 +19,7 @@ namespace System
{
const int32 cVersion = 10;
[CRepr, AlwaysInclude]
[CRepr]
struct BfDebugMessageData
{
enum MessageType : int32
@ -104,7 +106,7 @@ namespace System
struct BfRtCallbacks
{
public static BfRtCallbacks sCallbacks = .();
public static BfRtCallbacks sCallbacks;
function void* (int size) mAlloc;
function void (void* ptr) mFree;
@ -115,7 +117,7 @@ namespace System
function Object (Object obj, int32 typeId) mObject_DynamicCastToTypeId;
function void (Type type, String str) mType_GetFullName;
function String () mString_Alloc;
function char8* (String str) mString_ToCStr;
function StringView (String str) mString_ToStringView;
function Object () mThread_Alloc;
function Object () mThread_GetMainThread;
function void (Object thread) mThread_ThreadProc;
@ -178,7 +180,7 @@ namespace System
static void Type_GetFullName(Type type, String str)
{
#if BF_DBG_RUNTIME
type.GetFullName(str);
type.ToString(str);
#else
//
#endif
@ -189,9 +191,9 @@ namespace System
return new String();
}
static char8* String_ToCStr(String str)
static StringView String_ToStringView(String str)
{
return str.CStr();
return str;
}
static void GC_MarkAllStaticMembers()
@ -219,39 +221,37 @@ namespace System
static void DebugMessageData_SetupError(char8* str, int32 stackWindbackCount)
{
#if !BF_RUNTIME_REDUCED
BfDebugMessageData.gBfDebugMessageData.SetupError(str, stackWindbackCount);
#endif
}
static void DebugMessageData_SetupProfilerCmd(char8* str)
{
#if !BF_RUNTIME_REDUCED
BfDebugMessageData.gBfDebugMessageData.SetupProfilerCmd(str);
#endif
}
static void DebugMessageData_Fatal()
{
#if !BF_RUNTIME_REDUCED
BfDebugMessageData.gBfDebugMessageData.Fatal();
#endif
}
static void DebugMessageData_Clear()
{
#if !BF_RUNTIME_REDUCED
BfDebugMessageData.gBfDebugMessageData.Clear();
#endif
}
static int32 CheckErrorHandler(char8* kind, char8* arg1, char8* arg2, int arg3)
static int32 CheckErrorHandle(char8* kind, char8* arg1, char8* arg2, int arg3)
{
Error error = null;
switch (StringView(kind))
{
case "FatalError":
error = scope:: FatalError() { mError = new .(arg1) };
case "LoadSharedLibrary":
error = scope:: LoadSharedLibraryError() { mPath = new .(arg1) };
case "GetSharedProcAddress":
error = scope:: GetSharedProcAddressError() { mPath = new .(arg1), mProcName = new .(arg2) };
}
if (error == null)
return 0;
return (int32)Runtime.CheckErrorHandlers(error);
if (Runtime.CheckErrorHandler != null)
return Runtime.CheckErrorHandler(kind, arg1, arg2, arg3);
return 0;
}
public void Init() mut
@ -264,7 +264,7 @@ namespace System
mObject_DynamicCastToTypeId = => Object_DynamicCastToTypeId;
mType_GetFullName = => Type_GetFullName;
mString_Alloc = => String_Alloc;
mString_ToCStr = => String_ToCStr;
mString_ToStringView = => String_ToStringView;
mGC_MarkAllStaticMembers = => GC_MarkAllStaticMembers;
mGC_CallRootCallbacks = => GC_CallRootCallbacks;
mGC_Shutdown = => GC_Shutdown;
@ -277,12 +277,23 @@ namespace System
}
};
#if !BF_RUNTIME_DISABLE
private static extern void Init(int32 version, int32 flags, BfRtCallbacks* callbacks);
private static extern void InitCrashCatcher(int32 flags);
private static extern void ShutdownCrashCatcher();
private static extern void AddCrashInfoFunc(void* func);
private static extern void Dbg_Init(int32 version, int32 flags, BfRtCallbacks* callbacks);
private static extern void SetErrorString(char8* error);
private static extern void* Dbg_GetCrashInfoFunc();
public static extern void SetCrashReportKind(RtCrashReportKind crashReportKind);
#else
private static void Init(int32 version, int32 flags, BfRtCallbacks* callbacks) {}
private static void AddCrashInfoFunc(void* func) {}
private static void Dbg_Init(int32 version, int32 flags, BfRtCallbacks* callbacks) {}
private static void SetErrorString(char8* error) {}
private static void* Dbg_GetCrashInfoFunc() => null;
public static void SetCrashReportKind(RtCrashReportKind crashReportKind) {}
#endif
public enum RtCrashReportKind : int32
{
@ -359,18 +370,23 @@ namespace System
Fail
}
public delegate ErrorHandlerResult ErrorHandler(ErrorStage stage, Error error);
static struct ErrorHandlerData
{
public delegate ErrorHandlerResult ErrorHandler(ErrorStage stage, Error error);
public static AllocWrapper<Monitor> sMonitor ~ _.Dispose();
public static List<ErrorHandler> sErrorHandlers ~ DeleteContainerAndItems!(_);
public static bool sInsideErrorHandler;
}
static RtFlags sExtraFlags;
static AllocWrapper<Monitor> sMonitor ~ _.Dispose();
static List<ErrorHandler> sErrorHandlers ~ DeleteContainerAndItems!(_);
static bool sInsideErrorHandler;
static bool sQueriedFeatures = false;
static RuntimeFeatures sFeatures;
static function void() sThreadInit;
public static this()
{
#if !BF_RUNTIME_DISABLE
BfRtCallbacks.sCallbacks.Init();
RtFlags flags = sExtraFlags;
@ -384,84 +400,134 @@ namespace System
flags |= .DebugAlloc;
#endif
Init(cVersion, (int32)flags, &BfRtCallbacks.sCallbacks);
#if !BF_RUNTIME_REDUCED && BF_PLATFORM_WINDOWS
InitCrashCatcher((int32)flags);
#endif
#if BF_DBG_RUNTIME
Dbg_Init(cVersion, (int32)flags, &BfRtCallbacks.sCallbacks);
#endif
Thread.[Friend]Init();
if (sThreadInit != null)
sThreadInit();
#endif
}
[NoReturn]
public static void FatalError(String msg = "Fatal error encountered", String filePath = Compiler.CallerFilePath, int line = Compiler.CallerLineNum)
{
String failStr = scope .()..AppendF("{} at line {} in {}", msg, line, filePath);
#if !BF_RUNTIME_REDUCED
String failStr = scope .()..Append(msg, " at line ");
line.ToString(failStr);
failStr.Append(" in ", filePath);
Internal.FatalError(failStr, 1);
#else
Internal.FatalError("Fatal error", 1);
#endif
}
[NoReturn]
public static void NotImplemented(String filePath = Compiler.CallerFilePath, int line = Compiler.CallerLineNum)
{
String failStr = scope .()..AppendF("Not Implemented at line {} in {}", line, filePath);
String failStr = scope .()..Append("Not implemented at line ");
line.ToString(failStr);
failStr.Append(" in ", filePath);
Internal.FatalError(failStr, 1);
}
public static void Assert(bool condition, String error = Compiler.CallerExpression[0], String filePath = Compiler.CallerFilePath, int line = Compiler.CallerLineNum)
public static void Assert(bool condition, String error = Compiler.CallerExpression[0], String filePath = Compiler.CallerFilePath, int line = Compiler.CallerLineNum)
{
if (!condition)
{
if (Runtime.CheckErrorHandlers(scope Runtime.AssertError(.Runtime, error, filePath, line)) == .Ignore)
if ((Runtime.CheckAssertError != null) && (Runtime.CheckAssertError(.Runtime, error, filePath, line) == .Ignore))
return;
String failStr = scope .()..AppendF("Assert failed: {} at line {} in {}", error, line, filePath);
#if !BF_RUNTIME_REDUCED
String failStr = scope .()..Append("Assert failed: ", error, " at line ");
line.ToString(failStr);
failStr.Append(" in ", filePath);
Internal.FatalError(failStr, 1);
#else
Internal.FatalError("Assert failed", 1);
#endif
}
}
public static void AddErrorHandler(ErrorHandler handler)
public static void AddErrorHandler(ErrorHandlerData.ErrorHandler handler)
{
if (Compiler.IsComptime)
return;
using (sMonitor.Val.Enter())
using (ErrorHandlerData.sMonitor.Val.Enter())
{
if (sErrorHandlers == null)
sErrorHandlers = new .();
sErrorHandlers.Add(handler);
if (CheckAssertError == null)
{
CheckAssertError = => CheckAssertError_Impl;
CheckErrorHandler = => CheckErrorHandler_Impl;
}
if (ErrorHandlerData.sErrorHandlers == null)
ErrorHandlerData.sErrorHandlers = new .();
ErrorHandlerData.sErrorHandlers.Add(handler);
}
}
public static Result<void> RemoveErrorHandler(ErrorHandler handler)
public static Result<void> RemoveErrorHandler(ErrorHandlerData.ErrorHandler handler)
{
if (Compiler.IsComptime)
return .Ok;
using (sMonitor.Val.Enter())
using (ErrorHandlerData.sMonitor.Val.Enter())
{
if (sErrorHandlers.RemoveStrict(handler))
if (ErrorHandlerData.sErrorHandlers.RemoveStrict(handler))
return .Ok;
}
return .Err;
}
public static ErrorHandlerResult CheckErrorHandlers(Error error)
public static function ErrorHandlerResult(AssertError.Kind kind, String error, String filePath, int lineNum) CheckAssertError;
public static function int32(char8* kind, char8* arg1, char8* arg2, int arg3) CheckErrorHandler;
static ErrorHandlerResult CheckAssertError_Impl(AssertError.Kind kind, String error, String filePath, int lineNum)
{
return CheckErrorHandlers(scope AssertError(kind, error, filePath, lineNum));
}
static int32 CheckErrorHandler_Impl(char8* kind, char8* arg1, char8* arg2, int arg3)
{
Error error = null;
switch (StringView(kind))
{
case "FatalError":
error = scope:: FatalError() { mError = new .(arg1) };
case "LoadSharedLibrary":
error = scope:: LoadSharedLibraryError() { mPath = new .(arg1) };
case "GetSharedProcAddress":
error = scope:: GetSharedProcAddressError() { mPath = new .(arg1), mProcName = new .(arg2) };
}
if (error == null)
return 0;
return (int32)CheckErrorHandlers(error);
}
static ErrorHandlerResult CheckErrorHandlers(Error error)
{
if (Compiler.IsComptime)
return .ContinueFailure;
using (sMonitor.Val.Enter())
using (ErrorHandlerData.sMonitor.Val.Enter())
{
if (sInsideErrorHandler)
if (ErrorHandlerData.sInsideErrorHandler)
return .ContinueFailure;
sInsideErrorHandler = true;
defer { sInsideErrorHandler = false; }
ErrorHandlerData.sInsideErrorHandler = true;
defer { ErrorHandlerData.sInsideErrorHandler = false; }
for (int pass = 0; pass < 2; pass++)
{
int idx = (sErrorHandlers?.Count).GetValueOrDefault() - 1;
int idx = (ErrorHandlerData.sErrorHandlers?.Count).GetValueOrDefault() - 1;
while (idx >= 0)
{
if (idx < sErrorHandlers.Count)
if (idx < ErrorHandlerData.sErrorHandlers.Count)
{
var handler = sErrorHandlers[idx];
var handler = ErrorHandlerData.sErrorHandlers[idx];
var result = handler((pass == 0) ? .PreFail : .Fail, error);
if (result == .Ignore)
{
@ -562,5 +628,122 @@ namespace System
[Intrinsic("xgetbv")]
private static extern uint64 xgetbv(uint32 xcr);
#endif
public static void Shutdown()
{
#if !BF_RUNTIME_REDUCED && BF_PLATFORM_WINDOWS
ShutdownCrashCatcher();
#endif
}
}
}
#if BF_RUNTIME_DISABLE
namespace System
{
[AlwaysInclude, StaticInitPriority(1000)]
static class MinRuntime
{
static function void*(int) sMallocFunc;
static function void(void*) sFreeFunc;
static this()
{
var lib = Windows.LoadLibraryA("msvcrt.dll");
sMallocFunc = (.)Windows.GetProcAddress(lib, "malloc");
sFreeFunc = (.)Windows.GetProcAddress(lib, "free");
}
/*[LinkName(.C), AlwaysInclude]
static void __chkstk()
{
}*/
[LinkName(.C), AlwaysInclude]
static void* malloc(int size)
{
return sMallocFunc(size);
}
[LinkName(.C), AlwaysInclude]
static void free(void* ptr)
{
sFreeFunc(ptr);
}
[LinkName(.C), AlwaysInclude]
static void memset(void* dest, uint8 val, int size)
{
uint8* outPtr = (.)dest;
for (int i < size)
*(outPtr++) = val;
}
[LinkName(.C), AlwaysInclude]
static void memcpy(void* dest, void* src, int size)
{
uint8* destPtr = (.)dest;
uint8* srcPtr = (.)src;
if (destPtr < srcPtr)
{
for (int i < size)
*(destPtr++) = *(srcPtr++);
}
else
{
destPtr += size;
srcPtr += size;
for (int i < size)
*(--destPtr) = *(--srcPtr);
}
}
[LinkName(.C), AlwaysInclude]
static void memmove(void* dest, void* src, int size)
{
uint8* destPtr = (.)dest;
uint8* srcPtr = (.)src;
if (destPtr < srcPtr)
{
for (int i < size)
*(destPtr++) = *(srcPtr++);
}
else
{
destPtr += size;
srcPtr += size;
for (int i < size)
*(--destPtr) = *(--srcPtr);
}
}
[LinkName(.C), AlwaysInclude]
static double strtod(char8* str, char8** endPtr)
{
return 0;
}
[LinkName(.C), AlwaysInclude]
static extern void WinMain(void* module, void* prevModule, char8* args, int32 showCmd);
[LinkName(.C), AlwaysInclude]
static extern int32 main(int argc, char8** argv);
[LinkName(.C), AlwaysInclude]
static void mainCRTStartup()
{
//WinMain(null, null, "hi", 1);
main(0, null);
}
[LinkName(.C), Export]
static int32 _tls_index;
[LinkName(.C), Export]
static bool _fltused;
}
}
#endif

View file

@ -330,7 +330,7 @@ namespace System
public override void ToString(String strBuffer)
{
strBuffer.Append("(");
typeof(T).GetFullName(strBuffer);
typeof(T).ToString(strBuffer);
strBuffer.AppendF("*)0x{0:A}[{1}]", (uint)(void*)mPtr, mLength);
}

View file

@ -10,6 +10,8 @@ using System.Threading;
using System.Interop;
using System;
using internal System.String;
namespace System
{
// String size type
@ -46,6 +48,13 @@ namespace System
NullTerminate = 1
}
internal struct Interns
{
public static Monitor sMonitor = new Monitor() ~ delete _;
public static HashSet<String> sInterns = new .() ~ delete _;
public static List<String> sOwnedInterns = new .() ~ DeleteContainerAndItems!(_);
}
int_strsize mLength;
uint_strsize mAllocSizeAndFlags;
char8* mPtrOrBuffer = null;
@ -53,9 +62,6 @@ namespace System
extern const String* sStringLiterals;
extern const String* sIdStringLiterals;
static String* sPrevInternLinkPtr; // For detecting changes to sStringLiterals for hot loads
static Monitor sMonitor = new Monitor() ~ delete _;
static HashSet<String> sInterns = new .() ~ delete _;
static List<String> sOwnedInterns = new .() ~ DeleteContainerAndItems!(_);
public const String Empty = "";
#if BF_LARGE_STRINGS
@ -619,7 +625,6 @@ namespace System
String.Quote(Ptr, mLength, outString);
}
[AlwaysInclude]
public char8* CStr()
{
EnsureNullTerminator();
@ -2846,15 +2851,15 @@ namespace System
String str = *(ptr++);
if (str == null)
break;
sInterns.Add(str);
Interns.sInterns.Add(str);
}
}
public String Intern()
{
using (sMonitor.Enter())
using (Interns.sMonitor.Enter())
{
bool needsLiteralPass = sInterns.Count == 0;
bool needsLiteralPass = Interns.sInterns.Count == 0;
String* internalLinkPtr = *((String**)(sStringLiterals));
if (internalLinkPtr != sPrevInternLinkPtr)
{
@ -2865,13 +2870,13 @@ namespace System
CheckLiterals(sStringLiterals);
String* entryPtr;
if (sInterns.TryAdd(this, out entryPtr))
if (Interns.sInterns.TryAdd(this, out entryPtr))
{
String result = new String(mLength + 1);
result.Append(this);
result.EnsureNullTerminator();
*entryPtr = result;
sOwnedInterns.Add(result);
Interns.sOwnedInterns.Add(result);
return result;
}
return *entryPtr;
@ -4256,9 +4261,9 @@ namespace System
public String Intern()
{
using (String.[Friend]sMonitor.Enter())
using (String.Interns.sMonitor.Enter())
{
bool needsLiteralPass = String.[Friend]sInterns.Count == 0;
bool needsLiteralPass = String.Interns.sInterns.Count == 0;
String* internalLinkPtr = *((String**)(String.[Friend]sStringLiterals));
if (internalLinkPtr != String.[Friend]sPrevInternLinkPtr)
{
@ -4269,13 +4274,13 @@ namespace System
String.[Friend]CheckLiterals(String.[Friend]sStringLiterals);
String* entryPtr;
if (String.[Friend]sInterns.TryAddAlt(this, out entryPtr))
if (String.Interns.sInterns.TryAddAlt(this, out entryPtr))
{
String result = new String(mLength + 1);
result.Append(this);
result.EnsureNullTerminator();
*entryPtr = result;
String.[Friend]sOwnedInterns.Add(result);
String.Interns.sOwnedInterns.Add(result);
return result;
}
return *entryPtr;
@ -4367,7 +4372,7 @@ namespace System
}
#if TEST
extension String
class StringTest
{
[Test]
public static void Test_Intern()

View file

@ -70,7 +70,7 @@ namespace System
{
if (!condition)
{
if (Runtime.CheckErrorHandlers(scope Runtime.AssertError(.Test, error, filePath, line)) == .Ignore)
if ((Runtime.CheckAssertError != null) && (Runtime.CheckAssertError(.Test, error, filePath, line) == .Ignore))
return;
String failStr = scope .()..AppendF("Assert failed: {} at line {} in {}", error, line, filePath);
Internal.[Friend]Test_Error(failStr);

View file

@ -1,4 +1,5 @@
using System.Diagnostics;
using System.Threading;
namespace System.Text
{
[StaticInitPriority(100)]
@ -15,11 +16,39 @@ namespace System.Text
case PartialEncode(int inChars, int encodedBytes);
}
public static readonly ASCIIEncoding ASCII = new ASCIIEncoding() ~ delete _;
public static readonly UTF8Encoding UTF8 = new UTF8Encoding() ~ delete _;
public static readonly UTF8EncodingWithBOM UTF8WithBOM = new UTF8EncodingWithBOM() ~ delete _;
public static readonly UTF16Encoding UTF16 = new UTF16Encoding() ~ delete _;
public static readonly UTF16EncodingWithBOM UTF16WithBOM = new UTF16EncodingWithBOM() ~ delete _;
static Encoding sASCII ~ delete _;
static Encoding sUTF8 ~ delete _;
static Encoding sUTF8WithBOM ~ delete _;
static Encoding sUTF16 ~ delete _;
static Encoding sUTF16WithBOM ~ delete _;
static T GetEncoding<T>(ref Encoding encoding) where T : Encoding, new, delete
{
if (encoding != null)
return (.)encoding;
var newEncoding = new T();
if (Compiler.IsComptime)
{
encoding = newEncoding;
return newEncoding;
}
let prevValue = Interlocked.CompareExchange(ref encoding, null, newEncoding);
if (prevValue != null)
{
// This was already set - race condition
delete newEncoding;
return (.)prevValue;
}
return newEncoding;
}
public static ASCIIEncoding ASCII => GetEncoding<ASCIIEncoding>(ref sASCII);
public static UTF8Encoding UTF8 => GetEncoding<UTF8Encoding>(ref sUTF8);
public static UTF8EncodingWithBOM UTF8WithBOM => GetEncoding<UTF8EncodingWithBOM>(ref sUTF8WithBOM);
public static UTF16Encoding UTF16 => GetEncoding<UTF16Encoding>(ref sUTF16);
public static UTF16EncodingWithBOM UTF16WithBOM => GetEncoding<UTF16EncodingWithBOM>(ref sUTF16WithBOM);
public abstract int GetCharUnitSize();
public abstract int GetEncodedLength(char32 c);

View file

@ -26,7 +26,7 @@ namespace System.Threading
static Event<delegate void()> sOnExit ~ _.Dispose();
Event<delegate void()> mOnExit ~ _.Dispose();
public static Thread sMainThread = new Thread() ~ delete _;
public static Thread sMainThread ~ delete _;
[StaticInitPriority(102)]
struct RuntimeThreadInit
@ -48,8 +48,10 @@ namespace System.Threading
static void Thread_SetInternalThread(Object thread, void* internalThread)
{
#if BF_ENABLE_REALTIME_LEAK_CHECK
if (internalThread != null)
GC.[Friend]AddPendingThread(internalThread);
#endif
((Thread)thread).[Friend]mInternalThread = (int)internalThread;
}
@ -118,9 +120,20 @@ namespace System.Threading
cb.[Friend]mThread_AutoDelete = => Thread_AutoDelete;
cb.[Friend]mThread_GetMaxStackSize = => Thread_GetMaxStackSize;
cb.[Friend]mThread_Exiting = => Thread_Exiting;
Runtime.[Friend, NoStaticCtor]sThreadInit = => Thread.Init;
}
public static void Check()
{
}
}
public static this()
{
RuntimeThreadInit.Check();
}
private this()
{
@ -170,6 +183,7 @@ namespace System.Threading
{
#unwarn
RuntimeThreadInit runtimeThreadInitRef = ?;
sMainThread = new Thread();
sMainThread.ManualThreadInit();
}
@ -225,11 +239,6 @@ namespace System.Threading
}
}
extern void ManualThreadInit();
extern void StartInternal();
extern void SetStackStart(void* ptr);
extern void ThreadStarted();
public void Start(bool autoDelete = true)
{
mAutoDelete = autoDelete;
@ -247,7 +256,7 @@ namespace System.Threading
StartInternal();
}
#if BF_PLATFORM_WINDOWS
#if BF_PLATFORM_WINDOWS && !BF_RUNTIME_DISABLE
[CLink]
static extern int32 _tls_index;
#endif
@ -256,7 +265,7 @@ namespace System.Threading
{
get
{
#if BF_PLATFORM_WINDOWS
#if BF_PLATFORM_WINDOWS && !BF_RUNTIME_DISABLE
return _tls_index;
#else
return 0;
@ -264,10 +273,6 @@ namespace System.Threading
}
}
public static extern void RequestExitNotify();
public extern void Suspend();
public extern void Resume();
public ThreadPriority Priority
{
get
@ -283,12 +288,7 @@ namespace System.Threading
SetPriorityNative((int32)value);
}
}
[CallingConvention(.Cdecl)]
private extern int32 GetPriorityNative();
[CallingConvention(.Cdecl)]
private extern void SetPriorityNative(int32 priority);
extern bool GetIsAlive();
public bool IsAlive
{
get
@ -297,8 +297,7 @@ namespace System.Threading
}
}
[CallingConvention(.Cdecl)]
extern bool GetIsThreadPoolThread();
public bool IsThreadPoolThread
{
get
@ -307,8 +306,6 @@ namespace System.Threading
}
}
private extern bool JoinInternal(int32 millisecondsTimeout);
public void Join()
{
JoinInternal(Timeout.Infinite);
@ -328,7 +325,6 @@ namespace System.Threading
return Join((int32)tm);
}
private static extern void SleepInternal(int32 millisecondsTimeout);
public static void Sleep(int32 millisecondsTimeout)
{
SleepInternal(millisecondsTimeout);
@ -342,15 +338,11 @@ namespace System.Threading
Sleep((int32)tm);
}
private static extern void SpinWaitInternal(int32 iterations);
public static void SpinWait(int iterations)
{
SpinWaitInternal((int32)iterations);
}
private static extern bool YieldInternal();
public static bool Yield()
{
return YieldInternal();
@ -364,9 +356,6 @@ namespace System.Threading
}
}
[CallingConvention(.Cdecl)]
extern int GetThreadId();
public int Id
{
get
@ -376,9 +365,6 @@ namespace System.Threading
}
public static int CurrentThreadId => Platform.BfpThread_GetCurrentId();
[CallingConvention(.Cdecl)]
private static extern Thread GetCurrentThreadNative();
void SetStart(Delegate ownStartDelegate, int32 maxStackSize)
{
@ -405,18 +391,11 @@ namespace System.Threading
delete mDelegate;
}
[CallingConvention(.Cdecl)]
private extern void InternalFinalize();
public bool IsBackground
{
get { return IsBackgroundNative(); }
set { SetBackgroundNative(value); }
}
[CallingConvention(.Cdecl)]
private extern bool IsBackgroundNative();
[CallingConvention(.Cdecl)]
private extern void SetBackgroundNative(bool isBackground);
public void SetJoinOnDelete(bool joinOnDelete)
{
@ -427,8 +406,6 @@ namespace System.Threading
{
get { return (ThreadState)GetThreadStateNative(); }
}
[CallingConvention(.Cdecl)]
private extern int32 GetThreadStateNative();
public void SetName(String name)
{
@ -450,7 +427,63 @@ namespace System.Threading
if (mName != null)
outName.Append(mName);
}
#if !BF_RUNTIME_DISABLE
[CallingConvention(.Cdecl)]
private extern void InformThreadNameChange(String name);
[CallingConvention(.Cdecl)]
private extern bool IsBackgroundNative();
[CallingConvention(.Cdecl)]
private extern void SetBackgroundNative(bool isBackground);
[CallingConvention(.Cdecl)]
private extern void InternalFinalize();
[CallingConvention(.Cdecl)]
private static extern Thread GetCurrentThreadNative();
[CallingConvention(.Cdecl)]
private extern int32 GetPriorityNative();
[CallingConvention(.Cdecl)]
private extern void SetPriorityNative(int32 priority);
[CallingConvention(.Cdecl)]
extern bool GetIsThreadPoolThread();
[CallingConvention(.Cdecl)]
extern int GetThreadId();
[CallingConvention(.Cdecl)]
private extern int32 GetThreadStateNative();
private static extern void SpinWaitInternal(int32 iterations);
private static extern void SleepInternal(int32 millisecondsTimeout);
private extern bool JoinInternal(int32 millisecondsTimeout);
private static extern bool YieldInternal();
extern void ManualThreadInit();
extern void StartInternal();
extern void SetStackStart(void* ptr);
extern void ThreadStarted();
public static extern void RequestExitNotify();
public extern void Suspend();
public extern void Resume();
extern bool GetIsAlive();
#else
private void InformThreadNameChange(String name) {}
private bool IsBackgroundNative() => false;
private void SetBackgroundNative(bool isBackground) {}
private void InternalFinalize() {}
private static Thread GetCurrentThreadNative() => null;
private int32 GetPriorityNative() => 0;
private void SetPriorityNative(int32 priority) {}
bool GetIsThreadPoolThread() => false;
int GetThreadId() => 0;
private int32 GetThreadStateNative() => 0;
private static void SpinWaitInternal(int32 iterations) {}
private static void SleepInternal(int32 millisecondsTimeout) {}
private bool JoinInternal(int32 millisecondsTimeout) => false;
private static bool YieldInternal() => false;
void ManualThreadInit() {}
void StartInternal() {}
void SetStackStart(void* ptr) {}
void ThreadStarted() {}
public static void RequestExitNotify() {}
public void Suspend() {}
public void Resume() {}
bool GetIsAlive() => false;
#endif
}
}

View file

@ -7,12 +7,15 @@ namespace System
{
struct ClassVData
{
public Type mType;
public int mType;
#if BF_32_BIT
public int mType2;
#endif
// The rest of this structured is generated by the compiler,
// including the vtable and interface slots
}
[Ordered, AlwaysInclude(AssumeInstantiated=true)]
[Ordered, AlwaysInclude, Reflect(.Type)]
public class Type
{
extern const Type* sTypes;
@ -647,7 +650,7 @@ namespace System
{
GetFullName(strBuffer);
}*/
protected this()
{
}
@ -746,7 +749,12 @@ namespace System
public override void ToString(String strBuffer)
{
#if !BF_REFLECT_MINIMAL
GetFullName(strBuffer);
#else
strBuffer.Append("Type#");
mTypeId.ToString(strBuffer);
#endif
}
public struct Enumerator : IEnumerator<Type>
@ -767,11 +775,11 @@ namespace System
return .Ok(type);
}
}
}
}
}
enum TypeCode : uint8
{
{
None,
CharPtr,
StringId,
@ -890,6 +898,7 @@ namespace System.Reflection
public int32 mCustomAttributesIdx;
}
[CRepr, AlwaysInclude]
public struct InterfaceData
{
public TypeId mInterfaceType;
@ -926,7 +935,7 @@ namespace System.Reflection
int32 mCustomAttributesIdx;
TypeId mBaseType;
TypeId mUnderlyingType;
TypeId mOuterType;
TypeId mOuterType;
int32 mInheritanceId;
int32 mInheritanceCount;
@ -1262,17 +1271,17 @@ namespace System.Reflection
checkType = arrayType.UnderlyingType;
continue;
}
checkType.GetFullName(strBuffer);
break;
}
for (var size in sizes)
{
if (size == -1)
strBuffer.Append("[?]");
else
strBuffer.AppendF($"[{size}]");
strBuffer.AppendF($"[{(Int.Simple)size}]");
}
}
}
@ -1499,7 +1508,7 @@ namespace System.Reflection
Protected = 0x0003,
Public = 0x0006,
// end member access mask
// field contract attributes.
Static = 0x0010, // Defined on type, else per instance.
InitOnly = 0x0020, // Field may only be initialized, not written to after init.

View file

@ -11,6 +11,14 @@ namespace System
case InvalidChar(uint partialResult);
}
public struct Simple : uint
{
public override void ToString(String strBuffer)
{
((uint)this).ToString(strBuffer);
}
}
public const uint MaxValue = (sizeof(uint) == 8) ? 0xFFFFFFFFFFFFFFFFUL : 0xFFFFFFFFL;
public const uint MinValue = 0;

View file

@ -58,8 +58,6 @@ namespace System
}
}
static String sHexUpperChars = "0123456789ABCDEF";
static String sHexLowerChars = "0123456789abcdef";
public void ToString(String outString, String format, IFormatProvider formatProvider)
{
if(format == null || format.IsEmpty)