1
0
Fork 0
mirror of https://github.com/beefytech/Beef.git synced 2025-06-19 16:40:26 +02:00

Added System.Compiler compile-time values

This commit is contained in:
Brian Fiete 2020-09-04 08:09:04 -07:00
parent 24aaa22f7a
commit 25f44ae133
11 changed files with 294 additions and 75 deletions

View file

@ -0,0 +1,29 @@
namespace System
{
static class Compiler
{
[LinkName("#CallerLineNum")]
public static extern int CallerLineNum;
[LinkName("#CallerFilePath")]
public static extern String CallerFilePath;
[LinkName("#CallerFileName")]
public static extern String CallerFileName;
[LinkName("#CallerFileDir")]
public static extern String CallerFileDir;
[LinkName("#CallerMemberName")]
public static extern String CallerMemberName;
[LinkName("#CallerProject")]
public static extern String CallerProject;
[LinkName("#CallerExpression")]
public static extern String[Int32.MaxValue] CallerExpression;
[LinkName("#TimeLocal")]
public static extern String TimeLocal;
}
}

View file

@ -5,27 +5,22 @@ namespace System.Diagnostics
#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, String error)
public static void Assert(bool condition, String error = Compiler.CallerExpression[0], String filePath = Compiler.CallerFilePath, int line = Compiler.CallerLineNum)
{
if (!condition)
Internal.FatalError(error, 1);
{
String failStr = scope .()..AppendF("Assert failed: {} at line {} in {}", error, line, filePath);
Internal.FatalError(failStr, 1);
}
}
#if !DEBUG
[SkipCall]
#endif
public static void FatalError(String msg = "Fatal error encountered")
public static void FatalError(String msg = "Fatal error encountered", String filePath = Compiler.CallerFilePath, int line = Compiler.CallerLineNum)
{
Internal.FatalError(msg, 1);
String failStr = scope .()..AppendF("{} at line {} in {}", msg, line, filePath);
Internal.FatalError(failStr, 1);
}
#if !DEBUG

View file

@ -306,27 +306,26 @@ namespace System
}
[NoReturn]
public static void FatalError(String msg = "Fatal error encountered")
public static void FatalError(String msg = "Fatal error encountered", String filePath = Compiler.CallerFilePath, int line = Compiler.CallerLineNum)
{
Internal.FatalError(msg, 1);
String failStr = scope .()..AppendF("{} at line {} in {}", msg, line, filePath);
Internal.FatalError(failStr, 1);
}
[NoReturn]
public static void NotImplemented()
public static void NotImplemented(String filePath = Compiler.CallerFilePath, int line = Compiler.CallerLineNum)
{
Internal.FatalError("Not Implemented", 1);
String failStr = scope .()..AppendF("Not Implemented at line {} in {}", line, filePath);
Internal.FatalError(failStr, 1);
}
public static void Assert(bool condition)
public static void Assert(bool condition, String error = Compiler.CallerExpression[0], String filePath = Compiler.CallerFilePath, int line = Compiler.CallerLineNum)
{
if (!condition)
Internal.FatalError("Assert failed", 1);
}
public static void Assert(bool condition, String error)
{
if (!condition)
Internal.FatalError(error, 1);
{
String failStr = scope .()..AppendF("Assert failed: {} at line {} in {}", error, line, filePath);
Internal.FatalError(failStr, 1);
}
}
}
}