1 module memutils.constants; 2 3 import std.traits : isNumeric; 4 5 void function(string) nothrow @safe writeln; 6 char[]function(long) nothrow @safe parseInt; 7 package: 8 9 enum 10 { // overhead allocator definitions, lazily loaded 11 NativeGC = 0x01, // instances are freed automatically when no references exist in the program's threads 12 LocklessFreeList = 0x02, // instances are owned by the creating thread thus must be freed by it 13 CryptoSafe = 0x03, // Same as above, but zeroise is called upon freeing 14 } 15 16 enum Mallocator = 0x05; // For use by the DebugAllocator. 17 enum Ctfe = 0x06; 18 const LogLevel = Error; 19 version (DictionaryDebugger) 20 const HasDictionaryDebugger = true; 21 else 22 const HasDictionaryDebugger = false; 23 version (EnableDebugger) 24 const HasDebuggerEnabled = true; 25 else 26 const HasDebuggerEnabled = false; 27 version (DisableDebugger) 28 const DisableDebugAllocations = true; 29 else version (VibeNoDebug) 30 const DisableDebugAllocations = true; 31 else 32 const DisableDebugAllocations = false; 33 public: 34 static if (HasDebuggerEnabled && !DisableDebugAllocations) 35 const HasDebugAllocations = true; 36 else static if (!DisableDebugAllocations) 37 const HasDebugAllocations = true; 38 else 39 const HasDebugAllocations = false; 40 package: 41 version (SkipMemutilsTests) 42 const SkipUnitTests = true; 43 else 44 const SkipUnitTests = false; 45 46 enum 47 { // LogLevel 48 Trace, 49 Info, 50 Debug, 51 Error, 52 None 53 } 54 nothrow: 55 56 string charFromInt = "0123456789"; 57 __gshared bool recursing = true; 58 59 void logTrace(ARGS...)(ARGS args) 60 { 61 static if (LogLevel <= Trace) 62 { 63 if (recursing) 64 return; 65 recursing = true; 66 scope (exit) 67 recursing = false; 68 import memutils.vector; 69 70 Vector!char app = Vector!char(); 71 app.reserve(32); 72 foreach (arg; args) 73 { 74 static if (isNumeric!(typeof(arg))) 75 app ~= parseInt(cast(long) arg); 76 else 77 app ~= arg; 78 } 79 version (WebAssembly) 80 writeln(cast(string) app[]); 81 version (unittest) 82 { 83 import std.stdio : writeln; 84 85 writeln(cast(string) app[]); 86 } 87 } 88 } 89 90 void logInfo(ARGS...)(ARGS args) 91 { 92 static if (LogLevel <= Info) 93 { 94 if (recursing) 95 return; 96 recursing = true; 97 scope (exit) 98 recursing = false; 99 import memutils.vector; 100 101 Vector!char app = Vector!char(); 102 app.reserve(32); 103 foreach (arg; args) 104 { 105 static if (isNumeric!(typeof(arg))) 106 app ~= parseInt(cast(long) arg); 107 else 108 app ~= arg; 109 } 110 version (WebAssembly) 111 writeln(cast(string) app[]); 112 version (unittest) 113 { 114 import std.stdio : writeln; 115 116 writeln(cast(string) app[]); 117 } 118 } 119 } 120 121 void logDebug(ARGS...)(ARGS args) 122 { 123 124 static if (LogLevel <= Debug) 125 { 126 if (recursing) 127 return; 128 recursing = true; 129 scope (exit) 130 recursing = false; 131 import memutils.vector; 132 133 Vector!char app = Vector!char(); 134 app.reserve(32); 135 foreach (arg; args) 136 { 137 static if (isNumeric!(typeof(arg))) 138 app ~= parseInt(cast(long) arg); 139 else 140 app ~= arg; 141 } 142 143 version (WebAssembly) 144 writeln(cast(string) app[]); 145 version (unittest) 146 { 147 import std.stdio : writeln; 148 149 writeln(cast(string) app[]); 150 } 151 } 152 } 153 154 void logError(ARGS...)(ARGS args) 155 { 156 static if (LogLevel <= Error) 157 { 158 if (recursing) 159 return; 160 recursing = true; 161 scope (exit) 162 recursing = false; 163 import memutils.vector; 164 165 Vector!char app = Vector!char(); 166 app.reserve(32); 167 foreach (arg; args) 168 { 169 static if (isNumeric!(typeof(arg))) 170 app ~= parseInt(cast(long) arg); 171 else 172 app ~= arg; 173 } 174 version (WebAssembly) 175 writeln(cast(string) app[]); 176 version (unittest) 177 { 178 import std.stdio : writeln; 179 180 writeln("Error: "); 181 writeln(cast(string) app[]); 182 assert(0); 183 } 184 } 185 }