mirror of
https://github.com/beefytech/Beef.git
synced 2025-06-24 10:38:02 +02:00
Initial checkin
This commit is contained in:
parent
c74712dad9
commit
078564ac9e
3242 changed files with 1616395 additions and 0 deletions
|
@ -0,0 +1,61 @@
|
|||
namespace System.Diagnostics.Contracts
|
||||
{
|
||||
class Contract
|
||||
{
|
||||
public enum ContractFailureKind
|
||||
{
|
||||
Precondition,
|
||||
//[SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly", MessageId = "Postcondition")]
|
||||
Postcondition,
|
||||
//[SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly", MessageId = "Postcondition")]
|
||||
PostconditionOnException,
|
||||
Invariant,
|
||||
Assert,
|
||||
Assume,
|
||||
}
|
||||
|
||||
static extern void ReportFailure(ContractFailureKind failureKind, char8* userMessage, int32 userMessageLen, char8* conditionText, int32 conditionTextLen);
|
||||
|
||||
/// <summary>
|
||||
/// This method is used internally to trigger a failure indicating to the "programmer" that he is using the interface incorrectly.
|
||||
/// It is NEVER used to indicate failure of actual contracts at runtime.
|
||||
/// </summary>
|
||||
static void AssertMustUseRewriter(ContractFailureKind kind, String contractKind)
|
||||
{
|
||||
}
|
||||
|
||||
public static void Assume(bool condition, StringView userMessage)
|
||||
{
|
||||
if (!condition)
|
||||
{
|
||||
ReportFailure(ContractFailureKind.Assume, userMessage.Ptr, (int32)userMessage.Length, null, 0);
|
||||
}
|
||||
}
|
||||
|
||||
public static void Assert(bool condition)
|
||||
{
|
||||
if (!condition)
|
||||
ReportFailure(ContractFailureKind.Assert, null, 0, null, 0);
|
||||
}
|
||||
|
||||
public static void Assert(bool condition, String userMessage)
|
||||
{
|
||||
if (!condition)
|
||||
ReportFailure(ContractFailureKind.Assert, userMessage.Ptr, (int32)userMessage.Length, null, 0);
|
||||
}
|
||||
|
||||
public static void Requires(bool condition)
|
||||
{
|
||||
if (!condition)
|
||||
ReportFailure(ContractFailureKind.Assert, null, 0, null, 0);
|
||||
//AssertMustUseRewriter(ContractFailureKind.Precondition, "Requires");
|
||||
}
|
||||
|
||||
public static void Requires(bool condition, StringView userMessage)
|
||||
{
|
||||
AssertMustUseRewriter(ContractFailureKind.Precondition, "Requires");
|
||||
}
|
||||
|
||||
public static void EndContractBlock() { }
|
||||
}
|
||||
}
|
|
@ -0,0 +1,6 @@
|
|||
namespace System.Diagnostics.Contracts
|
||||
{
|
||||
class ContractsBcl
|
||||
{
|
||||
}
|
||||
}
|
50
IDE/mintest/minlib/src/System/Diagnostics/Debug.bf
Normal file
50
IDE/mintest/minlib/src/System/Diagnostics/Debug.bf
Normal file
|
@ -0,0 +1,50 @@
|
|||
namespace System.Diagnostics
|
||||
{
|
||||
class Debug
|
||||
{
|
||||
//[System.Diagnostics.Conditional("DEBUG")]
|
||||
|
||||
#if !DEBUG
|
||||
[SkipCall]
|
||||
#endif
|
||||
public static void Assert(bool condition)
|
||||
{
|
||||
if (!condition)
|
||||
Internal.FatalError("Assert failed", 1);
|
||||
}
|
||||
|
||||
#if !DEBUG
|
||||
[SkipCall]
|
||||
#endif
|
||||
public static void Assert(bool condition, StringView error)
|
||||
{
|
||||
if (!condition)
|
||||
Internal.FatalError("Assert failed", 1);
|
||||
}
|
||||
|
||||
#if !DEBUG
|
||||
[SkipCall]
|
||||
#endif
|
||||
static extern void Write(char8* str, int strLen);
|
||||
|
||||
public static void WriteLine(StringView line)
|
||||
{
|
||||
Write(line.Ptr, line.Length);
|
||||
Write("\n", 1);
|
||||
}
|
||||
|
||||
/*public static void WriteLine(StringView strFormat, params Object[] args)
|
||||
{
|
||||
String paramStr = scope String();
|
||||
paramStr.FormatInto(strFormat, args);
|
||||
paramStr.Append('\n');
|
||||
Write(paramStr.Ptr, paramStr.Length);
|
||||
}*/
|
||||
|
||||
[NoReturn]
|
||||
public static void FatalError(String str = "")
|
||||
{
|
||||
Internal.FatalError(str, 1);
|
||||
}
|
||||
}
|
||||
}
|
95
IDE/mintest/minlib/src/System/Diagnostics/Profiler.bf
Normal file
95
IDE/mintest/minlib/src/System/Diagnostics/Profiler.bf
Normal file
|
@ -0,0 +1,95 @@
|
|||
using System.Threading;
|
||||
|
||||
namespace System.Diagnostics
|
||||
{
|
||||
enum ProfilerScope
|
||||
{
|
||||
Thread,
|
||||
Process
|
||||
}
|
||||
|
||||
struct ProfileId : int32
|
||||
{
|
||||
}
|
||||
|
||||
class Profiler
|
||||
{
|
||||
public enum Priority
|
||||
{
|
||||
Low,
|
||||
Normal,
|
||||
High
|
||||
}
|
||||
|
||||
static int32 gProfileId = 1;
|
||||
|
||||
public struct AutoLeave
|
||||
{
|
||||
//Profiler mProfiler;
|
||||
|
||||
public this(/*Profiler profiler*/)
|
||||
{
|
||||
//mProfiler = profiler;
|
||||
}
|
||||
|
||||
void Dispose()
|
||||
{
|
||||
Profiler.LeaveSection();
|
||||
}
|
||||
}
|
||||
|
||||
static Result<ProfileId> StartSampling(int32 threadId, StringView profileDesc)
|
||||
{
|
||||
//int32 curId = Interlocked.Increment(ref gProfileId);
|
||||
int32 curId = gProfileId++;
|
||||
|
||||
String str = scope String();
|
||||
str.Append("StartSampling\t");
|
||||
curId.ToString(str);
|
||||
str.Append("\t");
|
||||
threadId.ToString(str);
|
||||
str.Append("\t");
|
||||
str.Append(profileDesc);
|
||||
Internal.ProfilerCmd(str);
|
||||
return (ProfileId)curId;
|
||||
}
|
||||
|
||||
public static void StopSampling(ProfileId profileId)
|
||||
{
|
||||
String str = scope String();
|
||||
str.Append("StopSampling\t");
|
||||
((int32)profileId).ToString(str);
|
||||
Internal.ProfilerCmd(str);
|
||||
}
|
||||
|
||||
public static Result<ProfileId> StartSampling(Thread thread, StringView profileDesc = default)
|
||||
{
|
||||
return StartSampling(thread.Id, profileDesc);
|
||||
}
|
||||
|
||||
public static Result<ProfileId> StartSampling(StringView profileDesc = default)
|
||||
{
|
||||
return StartSampling(0, profileDesc);
|
||||
}
|
||||
|
||||
public static void ClearSampling()
|
||||
{
|
||||
Internal.ProfilerCmd("ClearSampling");
|
||||
}
|
||||
|
||||
public void Mark()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public static AutoLeave EnterSection(StringView name, Priority priority = Priority.Normal)
|
||||
{
|
||||
return AutoLeave();
|
||||
}
|
||||
|
||||
public static void LeaveSection()
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
}
|
135
IDE/mintest/minlib/src/System/Diagnostics/Stopwatch.bf
Normal file
135
IDE/mintest/minlib/src/System/Diagnostics/Stopwatch.bf
Normal file
|
@ -0,0 +1,135 @@
|
|||
// ==++== b
|
||||
//
|
||||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
//
|
||||
// ==--==
|
||||
/*============================================================
|
||||
**
|
||||
** Class: Stopwatch
|
||||
**
|
||||
** Purpose: Implementation for Stopwatch class.
|
||||
**
|
||||
** Date: Nov 27, 2002
|
||||
**
|
||||
===========================================================*/
|
||||
|
||||
namespace System.Diagnostics
|
||||
{
|
||||
using System;
|
||||
|
||||
public class Stopwatch
|
||||
{
|
||||
private const int64 TicksPerMillisecond = 1000;
|
||||
private const int64 TicksPerSecond = TicksPerMillisecond * 1000;
|
||||
|
||||
private int64 elapsed;
|
||||
private int64 startTimeStamp;
|
||||
private bool isRunning;
|
||||
|
||||
public this()
|
||||
{
|
||||
}
|
||||
|
||||
public void Start()
|
||||
{
|
||||
// Calling start on a running Stopwatch is a no-op.
|
||||
if (!isRunning)
|
||||
{
|
||||
startTimeStamp = GetTimestamp();
|
||||
isRunning = true;
|
||||
}
|
||||
}
|
||||
|
||||
public static Stopwatch StartNew()
|
||||
{
|
||||
Stopwatch s = new Stopwatch();
|
||||
s.Start();
|
||||
return s;
|
||||
}
|
||||
|
||||
public void Stop()
|
||||
{
|
||||
// Calling stop on a stopped Stopwatch is a no-op.
|
||||
if (isRunning)
|
||||
{
|
||||
int64 endTimeStamp = GetTimestamp();
|
||||
int64 elapsedThisPeriod = endTimeStamp - startTimeStamp;
|
||||
elapsed += elapsedThisPeriod;
|
||||
isRunning = false;
|
||||
|
||||
if (elapsed < 0)
|
||||
{
|
||||
// When measuring small time periods the StopWatch.Elapsed*
|
||||
// properties can return negative values. This is due to
|
||||
// bugs in the basic input/output system (BIOS) or the hardware
|
||||
// abstraction layer (HAL) on machines with variable-speed CPUs
|
||||
// (e.g. Intel SpeedStep).
|
||||
elapsed = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void Reset()
|
||||
{
|
||||
elapsed = 0;
|
||||
isRunning = false;
|
||||
startTimeStamp = 0;
|
||||
}
|
||||
|
||||
// Convenience method for replacing {sw.Reset(); sw.Start();} with a single sw.Restart()
|
||||
public void Restart()
|
||||
{
|
||||
elapsed = 0;
|
||||
startTimeStamp = GetTimestamp();
|
||||
isRunning = true;
|
||||
}
|
||||
|
||||
public bool IsRunning
|
||||
{
|
||||
get { return isRunning; }
|
||||
}
|
||||
|
||||
public TimeSpan Elapsed
|
||||
{
|
||||
get { return TimeSpan(GetElapsedDateTimeTicks()); }
|
||||
}
|
||||
|
||||
public int64 ElapsedMilliseconds
|
||||
{
|
||||
get { return GetRawElapsedTicks() / TicksPerMillisecond; }
|
||||
}
|
||||
|
||||
public int64 ElapsedMicroseconds
|
||||
{
|
||||
get { return GetRawElapsedTicks(); }
|
||||
}
|
||||
|
||||
public static int64 GetTimestamp()
|
||||
{
|
||||
return Internal.GetTickCountMicro();
|
||||
}
|
||||
|
||||
// Get the elapsed ticks.
|
||||
private int64 GetRawElapsedTicks()
|
||||
{
|
||||
int64 timeElapsed = elapsed;
|
||||
|
||||
if (isRunning)
|
||||
{
|
||||
// If the StopWatch is running, add elapsed time since
|
||||
// the Stopwatch is started last time.
|
||||
int64 currentTimeStamp = GetTimestamp();
|
||||
int64 elapsedUntilNow = currentTimeStamp - startTimeStamp;
|
||||
timeElapsed += elapsedUntilNow;
|
||||
}
|
||||
return timeElapsed;
|
||||
}
|
||||
|
||||
// Get the elapsed ticks.
|
||||
private int64 GetElapsedDateTimeTicks()
|
||||
{
|
||||
return GetRawElapsedTicks() * 10;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue