diff --git a/Array.h b/Array.h index d81c8f1..c67e43d 100644 --- a/Array.h +++ b/Array.h @@ -12,9 +12,8 @@ the MPL was not distributed with this file, You can obtain one at #include <_Config.h> namespace _ { -struct Autoject; /* Fills the array with the given fill_char identical to memset. */ -LIB_MEMBER CHA* ArrayFill(void* origin, ISW size_bytes, CHA fill_char = 0); +LIB_MEMBER CHA* RAMFill(void* origin, ISW size_bytes, CHA fill_char = 0); } //< namespace _ @@ -30,35 +29,35 @@ namespace _ { /* ASCII OBJ and RAMFactory. */ struct Autoject { - RAMFactory ram; //< Autoject Factory function pointer. - IUW* origin; //< Pointer to the Autoject. + RAMFactory ram; //< Autoject Factory function pointer. + IUW* origin; //< Pointer to the Autoject. }; -enum AsciiFactoryFunction { - cFactoryDelete = 0, //< Factory function deletes an OBJ. - cFactoryNew = 1, //< Factory function checks if the size can double. - cFactoryGrow = 2, //< Factory function double OBJ size. - cFactoryClone = 3, //< Factory function clones the OBJ. - cFactoryName = 4, //< Factory function gets the info string. - cFactoryFunctionCount = 5, //< Factory function count. +enum RAMFactoryFunction { + RAMFactoryDelete = 0, //< Factory function deletes an OBJ. + RAMFactoryNew = 1, //< Factory function checks if the size can double. + RAMFactoryGrow = 2, //< Factory function double OBJ size. + RAMFactoryClone = 3, //< Factory function clones the OBJ. + RAMFactoryName = 4, //< Factory function gets the info string. + RAMFactoryFunctionCount = 5, //< Factory function count. }; -enum AsciiFactoryError { - cFactorySuccess = 0, //< Factory operation completed successfully error. - cFactoryNil = 1, //< Factory missing error. - cFactoryNilOBJ = 2, //< Factory found nil obj.origin pointer error. - cFactoryNilArg = 3, //< Factory arg nil error. - cFactoryCantGrow = 4, //< Factory can't grow. - cFactorySizeInvalid = 5, //< Factory size invalid. - cFactoryErrorCount = 6, //< Factory function count. +enum RAMFactoryError { + RAMFactorySuccess = 0, //< Factory operation completed successfully error. + RAMFactoryNil = 1, //< Factory missing error. + RAMFactoryNilOBJ = 2, //< Factory found nil obj.origin pointer error. + RAMFactoryNilArg = 3, //< Factory arg nil error. + FactoryCantGrow = 4, //< Factory can't grow. + RAMFactorySizeInvalid = 5, //< Factory size invalid. + RAMFactoryErrorCount = 6, //< Factory function count. }; -/* RAMFactory for Autojects on the heap that deletes a the buffer. */ -LIB_MEMBER IUW* RamFactoryHeap(IUW* buffer, ISW size_bytes); - /* RAMFactory for Autojects on the program stack that doesn't delete the buffer. */ -LIB_MEMBER IUW* RamFactoryStack(IUW* buffer, ISW size_bytes); +LIB_MEMBER IUW* RAMFactoryStack(IUW* buffer, ISW size_bytes); + +/* RAMFactory for Autojects on the heap that deletes a the buffer. */ +LIB_MEMBER IUW* RAMFactoryHeap(IUW* buffer, ISW size_bytes); class Nil { public: @@ -84,7 +83,7 @@ class Nil { @param origin The origin of the read socket. @param read_size Number of bytes to copy. @return Pointer to the last IUA written or nil upon failure. */ -LIB_MEMBER ISW ArrayCopy(void* write, ISW size, const void* read, +LIB_MEMBER ISW RAMCopy(void* write, ISW size, const void* read, ISW read_size); /* Compares the two memory sockets. @@ -95,22 +94,22 @@ LIB_MEMBER ISW ArrayCopy(void* write, ISW size, const void* read, @return a_size_bytes if a is identical to b, or if a and b are not identical the return will be -1 times the number of bytes that were identical in a and b. */ -LIB_MEMBER ISW ArrayCompare(const void* a, ISW a_size_bytes, - const void* b, ISW b_size_bytes); +LIB_MEMBER ISW RAMCompare(const void* a, ISW a_size_bytes, + const void* b, ISW b_size_bytes); /* Shifts the memory up by the given count in bytes. @return 0 upon failure and count upon success. @param origin The origin byte address. @param end The end IUA. @param count_bytes The IUA count to shift up. */ -LIB_MEMBER ISW ArrayShiftUp(void* origin, void* end, ISW count_bytes); +LIB_MEMBER ISW RAMShiftUp(void* origin, void* end, ISW count_bytes); /* Shifts the memory down by the given bytes_count. @return 0 upon failure and count upon success. @param origin The start IUA. @param end The end IUA. @param count_bytes The IUA count to shift up. */ -LIB_MEMBER ISW ArrayShiftDown(void* origin, void* end, ISW bytes_count); +LIB_MEMBER ISW RAMShiftDown(void* origin, void* end, ISW bytes_count); } //< namespace _ #endif diff --git a/Array.hpp b/Array.hpp index fd2db5c..d360056 100644 --- a/Array.hpp +++ b/Array.hpp @@ -14,8 +14,8 @@ the MPL was not distributed with this file, You can obtain one at namespace _ { /* Overwrites the memory with fill_char; functionally equivalent to memset. */ -inline CHA* ArrayFill(void* start, void* stop, CHA fill_char) { - return ArrayFill(start, TPtr(stop) - TPtr(start) + 1, fill_char); +inline CHA* RAMFill(void* start, void* stop, CHA fill_char) { + return RAMFill(start, TPtr(stop) - TPtr(start) + 1, fill_char); } /* The maximum autoject size. @@ -99,7 +99,7 @@ inline T* TArrayStart(Class* autoject) { /* Prints the item to the printer. */ template -Printer& TArrayPrint(Printer& o, TArray* item) { +Printer& TArrayPrint(Printer& o, const TArray* item) { IS size = item->size; o << Linef("\n+---\nTArray() << "> size:" << size; @@ -112,6 +112,22 @@ Printer& TArrayPrint(Printer& o, TArray* item) { return o << Linef("\n+---"); } +// Copies the source to the destination. +template +TArray* TArrayCopy(void* destination, const void* source) { + auto dst = TPtr(destination); + auto src = TPtr(source); + auto dst_count = *dst; + auto src_count = *src; + auto result = RAMCopy(TAlignUpPTR<>(dst + 1, AlignMask), + dst_count * sizeof(T), + TAlignUpPTR<>(src + 1, AlignMask), + src_count * sizeof(T)); + if (result <= 0) return nullptr; + *dst = src_count; + return TPtr>(dst); +} + /* Calculates the size in bytes of an array with given element_count. */ template inline IS TSizeOf(IS element_count) { @@ -173,7 +189,7 @@ inline IS TSizeBytes(Autoject& autoject) { template inline IS TSizeWords(IS size) { IS size_aligned_up = AlignUp(TSizeBytes(size)); - return size_aligned_up >> WordBitCount; + return size_aligned_up >> ACPUBitCount; } template inline IS TSizeWords(IUW* origin) { @@ -188,7 +204,7 @@ inline IS TSizeWords(Autoject& autoject) { @return Nil upon failure or a pointer to the cloned autoject upon success. @param socket A raw ASCII Socket to clone. */ template -IUW* TArrayNew(RAMFactory factory, IS size) { +IUW* TRAMFactoryNew(RAMFactory factory, IS size) { IUW* origin = factory(nullptr, TSizeBytes(size)); TSizeSet(origin, size); return origin; @@ -220,7 +236,7 @@ TArray* TArrayWrite(TArray* destination, TArray* source, D_ASSERT(source); ISW size_bytes = (ISW)TSizeBytes(size); - if (!ArrayCopy(destination, size_bytes, source, size_bytes)) return nullptr; + if (!RAMCopy(destination, size_bytes, source, size_bytes)) return nullptr; return destination; } @@ -243,7 +259,7 @@ IUW* TArrayClone(Autoject& obj) { TArray* o = TPtr>(origin); IS size = o->size; - IUW* clone = TArrayNew>(size); + IUW* clone = TRAMFactoryNew>(size); return TArrayWrite(clone, origin, size); } @@ -251,7 +267,11 @@ IUW* TArrayClone(Autoject& obj) { @return True if the autoject can double in size. */ template BOL TCanGrow(IS size) { - return !(size >> (sizeof(IS) * 8 - 2)); + auto size_new = size >> (sizeof(IS) * 8 - 2); + if (size_new == 0) return true; + COut("\n\nError! Max size hit! size:").Star() << size; + return false; + } /* Resizes the given array. @@ -363,9 +383,9 @@ IS TArrayFind(const T* elements, IS element_count, const T& item) { @param origin The origin of Array B. @param end The end of Array B. @return True if they are the same and false if they are not. */ -inline ISW ArrayCompare(const void* a_begin, const void* end_a, +inline ISW RAMCompare(const void* a_begin, const void* end_a, const void* b_begin, const void* end_b) { - return ArrayCompare(a_begin, SizeOf(a_begin, end_a), b_begin, + return RAMCompare(a_begin, SizeOf(a_begin, end_a), b_begin, SizeOf(b_begin, end_b)); } @@ -375,28 +395,28 @@ inline ISW ArrayCompare(const void* a_begin, const void* end_a, @param origin The origin of Array B. @param size The size of Array B. @return True if they are the same and false if they are not. */ -inline ISW ArrayCompare(const void* a_begin, void* a_end, const void* b_begin, +inline ISW RAMCompare(const void* a_begin, void* a_end, const void* b_begin, ISW b_size_bytes) { - return ArrayCompare(a_begin, a_end, a_begin, + return RAMCompare(a_begin, a_end, a_begin, TPtr(b_begin) + b_size_bytes); } -/* Casts ArrayCompare to type T. */ +/* Casts RAMCompare to type T. */ template inline T* TArrayCompare(void* a_begin, void* a_end, void* b_begin, ISW b_size_bytes) { - return TPtr(ArrayCompare(a_begin, a_end, b_begin, b_size_bytes)); + return TPtr(RAMCompare(a_begin, a_end, b_begin, b_size_bytes)); } -/* Casts ArrayCompare to type T. */ +/* Casts RAMCompare to type T. */ template inline const T* TArrayCompare(const void* a_begin, void* a_end, const void* b_begin, ISW b_size_bytes) { - return TPtr(ArrayCompare(a_begin, a_end, b_begin, b_size_bytes)); + return TPtr(RAMCompare(a_begin, a_end, b_begin, b_size_bytes)); } -/* A word-aligned array of cSize_ elements of T on the progam stack. */ -template class TBUF { public: @@ -441,13 +461,13 @@ class TBUF { /* Sets the size to the new value. */ template inline IUW* SizeSet(ISW size) { - A_ASSERT((size & WordLSbMask) == 0) + A_ASSERT((size & ACPUAlignMask) == 0) *TPtr(words_) = size; return words_; } /* The size in elements. */ - static constexpr IS Size() { return IS((cSize_ < 0) ? 0 : IS(cSize_)); } + static constexpr IS Size() { return IS((Size_ < 0) ? 0 : IS(Size_)); } /* The size in bytes including the header. */ static constexpr IS SizeBytes() { @@ -462,31 +482,31 @@ class TBUF { }; /* A Block of heap. */ -template -class TRamFactory { +template +class TRAMFactory { /* RAMFactory for the Stack deletes a non-nil buffer. */ - static IUW* RamFactoryHeap(IUW* buffer, ISW size_bytes) { - if (size_bytes == 0) return (IUW*)RamFactoryHeap; - if (size_bytes < 0) return TPtr(IUW(cType)); - return _::RamFactoryHeap(buffer, size_bytes); + static IUW* RAMFactoryHeap(IUW* buffer, ISW size_bytes) { + if (size_bytes == 0) return (IUW*)RAMFactoryHeap; + if (size_bytes < 0) return TPtr(IUW(Type)); + return _::RAMFactoryHeap(buffer, size_bytes); } /* RAMFactory for the Stack doesn't delete a non-nil buffer. */ - static IUW* RamFactoryStack(IUW* buffer, ISW size_bytes) { - if (size_bytes == 0) return (IUW*)RamFactoryHeap; - if (size_bytes < 0) return TPtr(cType); - return _::RamFactoryStack(buffer, size_bytes); + static IUW* RAMFactoryStack(IUW* buffer, ISW size_bytes) { + if (size_bytes == 0) return (IUW*)RAMFactoryHeap; + if (size_bytes < 0) return TPtr(Type); + return _::RAMFactoryStack(buffer, size_bytes); } /* Gets the initial RAMFactory for the program stack or heap. */ template static constexpr RAMFactory RamFactoryInit() { - return (sizeof(BUF) == 0) ? RamFactoryHeap : RamFactoryStack; + return (sizeof(BUF) == 0) ? RAMFactoryHeap : RAMFactoryStack; } public: /* Does nothing. */ - TRamFactory() {} + TRAMFactory() {} /* Gets the RAMFactory to use upon construction. */ template @@ -511,12 +531,12 @@ class AArray { public: /* Gets the ASCII Data Type. */ - static constexpr DTA Type() { return CTypeSize(_ARY); } + static constexpr DTA Type() { return CATypeSize(_ARY); } /* Constructs. */ AArray() { TArrayInit(obj_, buffer_.Words(), IS(buffer_.Size()), - TRamFactory().Init()); + TRAMFactory().Init()); } /* Creates a autoject with either statically or dynamically allocated @@ -525,7 +545,7 @@ class AArray { dynamic memory will be created. */ AArray(IS size, RAMFactory ram = nullptr) { TArrayInit(obj_, buffer_.Words(), size, - TRamFactory().Init(ram)); + TRAMFactory().Init(ram)); } /* Stores the origin and ram to the obj_. */ @@ -605,7 +625,7 @@ class AArray { return TArrayPrint(o, Array()); } - void CPrint() { PrintTo<_::COut>(_::COut().Star()); } + void CPrint() { PrintTo<_::COut>(_::StdOut()); } }; } //< namespace _ diff --git a/Array.inl b/Array.inl index b3c92fa..1bb3ea0 100644 --- a/Array.inl +++ b/Array.inl @@ -7,7 +7,6 @@ Form is subject to the terms of the Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed with this file, You can obtain one at . */ #include "Array.hpp" -#include "Binary.hpp" namespace _ { /* Creates a CPU word from the repeated fill_char. */ @@ -27,7 +26,7 @@ inline IUW FillWord(CHA fill_char) { #endif } -CHA* ArrayFill(void* origin, ISW count, CHA fill_char) { +CHA* RAMFill(void* origin, ISW count, CHA fill_char) { if (!origin) return nullptr; CHA* start = TPtr(origin); if (count < 3 * sizeof(ISW)) { @@ -55,7 +54,6 @@ CHA* ArrayFill(void* origin, ISW count, CHA fill_char) { } //< namespace _ #if SEAM >= SCRIPT2_STACK -#include "Array.hpp" #if SEAM == SCRIPT2_STACK #include "_Debug.inl" @@ -65,16 +63,16 @@ CHA* ArrayFill(void* origin, ISW count, CHA fill_char) { namespace _ { -IUW* RamFactoryStack(IUW* origin, ISW size_bytes) { +IUW* RAMFactoryStack(IUW* origin, ISW size_bytes) { if (size_bytes <= 0) return nullptr; - size_bytes += (-size_bytes) & WordLSbMask; //< Word align up. - ISW size_words = size_bytes >> WordBitCount; + size_bytes += (-size_bytes) & ACPUAlignMask; //< Word align up. + ISW size_words = size_bytes >> ACPUBitCount; IUW* socket = new IUW[size_words]; return socket; } -IUW* RamFactoryHeap(IUW* origin, ISW size_bytes) { - if (!origin) return RamFactoryStack(origin, size_bytes); +IUW* RAMFactoryHeap(IUW* origin, ISW size_bytes) { + if (!origin) return RAMFactoryStack(origin, size_bytes); delete[] origin; return nullptr; } @@ -215,7 +213,7 @@ ISW ArrayCompareFast(const void* a, const ISW a_size_bytes, const void* b, return a_size_bytes; } -ISW ArrayCompare(const void* a, ISW a_size_bytes, const void* b, +ISW RAMCompare(const void* a, ISW a_size_bytes, const void* b, const ISW b_size_bytes) { return ArrayCompareFast(a, a_size_bytes, b, b_size_bytes); } @@ -307,24 +305,24 @@ ISW ArrayCopyFast(void* write, ISW w_size, const void* read, return r_size; } -ISW ArrayCopy(void* write, ISW w_size, const void* source, +ISW RAMCopy(void* write, ISW w_size, const void* source, const ISW s_size) { return ArrayCopySlow(write, w_size, source, s_size); } -inline ISW ArrayCopy(void* write, void* w_end, const void* read, +inline ISW RAMCopy(void* write, void* w_end, const void* read, ISW read_size) { - return ArrayCopy(write, TDelta(write, w_end), read, read_size); + return RAMCopy(write, TDelta(write, w_end), read, read_size); } -inline ISW ArrayCopy(void* write, ISW r_size, const void* read, +inline ISW RAMCopy(void* write, ISW r_size, const void* read, const void* r_end) { - return ArrayCopy(write, r_size, read, TDelta(read, r_end)); + return RAMCopy(write, r_size, read, TDelta(read, r_end)); } /* -inline ISW ArrayCopy(void* write, void* write_end, const void* read, +inline ISW RAMCopy(void* write, void* write_end, const void* read, const ISW r_size) { - return ArrayCopy(write, TDelta(write, write_end), read, r_size); + return RAMCopy(write, TDelta(write, write_end), read, r_size); }*/ inline ISW ArrayCopyFast(void* write, void* w_end, const void* read, @@ -343,7 +341,7 @@ constexpr ISW Nil::SizeBytes() { return 0; } constexpr ISW Nil::SizeWords() { return 0; } IUW* Nil::Words() { return nullptr; } -ISW ArrayShiftUp(void* origin, void* end, ISW count) { +ISW RAMShiftUp(void* origin, void* end, ISW count) { if (!origin || origin <= end || count <= 0) return 0; CHA *start = TPtr(origin), *stop = TPtr(end); @@ -373,7 +371,7 @@ ISW ArrayShiftUp(void* origin, void* end, ISW count) { return count; } -ISW ArrayShiftDown(void* origin, void* end, ISW count) { +ISW RAMShiftDown(void* origin, void* end, ISW count) { if (!origin || origin <= end || count <= 0) return 0; CHA *start = TPtr(origin), *stop = TPtr(end); diff --git a/Autoject.h b/Autoject.h index 3da347d..ae129f3 100644 --- a/Autoject.h +++ b/Autoject.h @@ -30,31 +30,31 @@ struct Autoject { IUW* begin; //< Pointer to the Autoject. }; -enum AsciiFactoryFunction { - cFactoryDelete = 0, //< Factory function deletes an OBJ. - cFactoryNew = 1, //< Factory function checks if the size can double. - cFactoryGrow = 2, //< Factory function double OBJ size. - cFactoryClone = 3, //< Factory function clones the OBJ. - cFactoryName = 4, //< Factory function gets the info AString. - cFactoryFunctionCount = 5, //< Factory function count. +enum RAMFactoryFunction { + RAMFactoryDelete = 0, //< Factory function deletes an OBJ. + RAMFactoryNew = 1, //< Factory function checks if the size can double. + RAMFactoryGrow = 2, //< Factory function double OBJ size. + RAMFactoryClone = 3, //< Factory function clones the OBJ. + RAMFactoryName = 4, //< Factory function gets the info AString. + RAMFactoryFunctionCount = 5, //< Factory function count. }; -enum AsciiFactoryError { - cFactorySuccess = 0, //< Factory operation completed successfully error. - cFactoryNil = 1, //< Factory missing error. - cFactoryNilOBJ = 2, //< Factory found nil obj.begin pointer error. - cFactoryNilArg = 3, //< Factory arg nil error. - cFactoryCantGrow = 4, //< Factory can't grow. - cFactorySizeInvalid = 5, //< Factory size invalid. - cFactoryErrorCount = 6, //< Factory function count. +enum RAMFactoryError { + RAMFactorySuccess = 0, //< Factory operation completed successfully error. + RAMFactoryNil = 1, //< Factory missing error. + RAMFactoryNilOBJ = 2, //< Factory found nil obj.begin pointer error. + RAMFactoryNilArg = 3, //< Factory arg nil error. + FactoryCantGrow = 4, //< Factory can't grow. + RAMFactorySizeInvalid = 5, //< Factory size invalid. + RAMFactoryErrorCount = 6, //< Factory function count. }; /* Creates or destroys a block of heap memory. @pre size_bytes > 0 */ -LIB_MEMBER IUW* RamFactoryHeap(IUW* obj, ISW size_bytes); +LIB_MEMBER IUW* RAMFactoryHeap(IUW* obj, ISW size_bytes); /* Creates a block of heap memory. */ -LIB_MEMBER IUW* RamFactoryStack(IUW* ptr, ISW size_bytes); +LIB_MEMBER IUW* RAMFactoryStack(IUW* ptr, ISW size_bytes); LIB_INLINE IUW* AutojectBeginSet(Autoject& obj, void* buffer); @@ -62,10 +62,10 @@ LIB_INLINE IUW* AutojectBeginSet(Autoject& obj, void* buffer); LIB_MEMBER void Delete(Autoject& obj); /* Overwrites the memory with fill_char; functionally identical to memset. */ -LIB_MEMBER CHA* ArrayFill(void* begin, void* end, CHA fill_char = 0); +LIB_MEMBER CHA* RAMFill(void* begin, void* end, CHA fill_char = 0); /* Overwrites the memory with fill_char; functionally identical to memset. */ -LIB_MEMBER CHA* ArrayFill(void* begin, ISW size, CHA fill_char = 0); +LIB_MEMBER CHA* RAMFill(void* begin, ISW size, CHA fill_char = 0); /* Overwrites the memory with fill_char; functionally identical to memset. */ LIB_MEMBER CHA* ArrayWipe(void* begin, void* end); @@ -79,7 +79,7 @@ LIB_MEMBER CHA* ArrayWipe(void* begin, ISW size); @param begin The begin of the read socket. @param read_size Number of bytes to copy. @return Pointer to the last IUA written or nil upon failure. */ -LIB_MEMBER CHA* ArrayCopy(void* begin, ISW size, const void* read, +LIB_MEMBER CHA* RAMCopy(void* begin, ISW size, const void* read, ISW read_size); /* Copies the source to the target functionally identical to memcpy. @@ -88,7 +88,7 @@ LIB_MEMBER CHA* ArrayCopy(void* begin, ISW size, const void* read, @param begin The begin of the read socket. @param size Number of bytes to copy. @return Pointer to the last IUA written or nil upon failure. */ -LIB_MEMBER CHA* ArrayCopy(void* start, void* stop, const void* begin, +LIB_MEMBER CHA* RAMCopy(void* start, void* stop, const void* begin, ISW read_size); /* Copies the source to the target functionally identical to memcpy. @@ -97,7 +97,7 @@ LIB_MEMBER CHA* ArrayCopy(void* start, void* stop, const void* begin, @param begin The begin of the read socket. @param end The end of the read socket. @return Pointer to the last IUA written or nil upon failure. */ -LIB_INLINE CHA* ArrayCopy(void* start, void* stop, const void* begin, +LIB_INLINE CHA* RAMCopy(void* start, void* stop, const void* begin, const void* end); /* Compares the two memory sockets. @@ -106,7 +106,7 @@ LIB_INLINE CHA* ArrayCopy(void* start, void* stop, const void* begin, @param begin The begin of Socket B. @param end The end of Socket B. @return True if they are the same and false if they are not. */ -LIB_MEMBER const void* ArrayCompare(const void* start, const void* stop, +LIB_MEMBER const void* RAMCompare(const void* start, const void* stop, const void* begin, const void* end); /* Compares the two memory sockets. @@ -115,7 +115,7 @@ LIB_MEMBER const void* ArrayCompare(const void* start, const void* stop, @param begin The begin of Socket B. @param size The size of Socket B. @return True if they are the same and false if they are not. */ -LIB_MEMBER const void* ArrayCompare(const void* start, void* stop, +LIB_MEMBER const void* RAMCompare(const void* start, void* stop, const void* begin, ISW size); /* Compares the two memory sockets. @@ -124,7 +124,7 @@ LIB_MEMBER const void* ArrayCompare(const void* start, void* stop, @param start The begin of socket b. @param size_b The size of Socket B. @return True if they are the same and false if they are not. */ -LIB_MEMBER const void* ArrayCompare(const void* start, ISW size_a, +LIB_MEMBER const void* RAMCompare(const void* start, ISW size_a, const void* begin, ISW size_b); /* Shifts the memory up by the given count in bytes. @@ -132,14 +132,14 @@ LIB_MEMBER const void* ArrayCompare(const void* start, ISW size_a, @param begin The begin IUA. @param end The end IUA. @param count_bytes The IUA count to shift up. */ -LIB_MEMBER ISW ArrayShiftUp(void* begin, void* end, ISW count_bytes); +LIB_MEMBER ISW RAMShiftUp(void* begin, void* end, ISW count_bytes); /* Shifts the memory down by the given bytes_count. @return 0 upon failure and count upon success. @param begin The start IUA. @param end The end IUA. @param count_bytes The IUA count to shift up. */ -LIB_MEMBER ISW ArrayShiftDown(void* begin, void* end, ISW bytes_count); +LIB_MEMBER ISW RAMShiftDown(void* begin, void* end, ISW bytes_count); } //< namespace _ #endif diff --git a/BIn.inl b/BIn.inl index 60280b9..9eb39d7 100644 --- a/BIn.inl +++ b/BIn.inl @@ -135,7 +135,7 @@ ISC BInStreamByte(BIn* bin) { : (stop - origin) + (open - origin) + 2); if (length < 1) { - BInError(bin, cErrorBufferOverflow, TParams<1, cSTR>(), 2, origin); + BInError(bin, cErrorBufferOverflow, TParams<1, STR_>(), 2, origin); return -1; } // IUA b = *cursor; @@ -304,7 +304,7 @@ const Op* BInRead(BIn* bin, const ISC* params, void** args) { #else return BInError(bin, cErrorInvalidType, params, index, origin); #endif - case cSTR: //< _R_e_a_d__S_t_r_i_n_g_-_8____________________ + case STR_: //< _R_e_a_d__S_t_r_i_n_g_-_8____________________ // Load buffered-type argument length and increment the index. ++num_params; count = params[++index]; @@ -313,7 +313,7 @@ const Op* BInRead(BIn* bin, const ISC* params, void** args) { iua_ptr = TPtr(args[arg_index]); if (iua_ptr == nullptr) return BInError(bin, cErrorImplementation, params, index, origin); - D_COUT("\nReading cSTR:0x" << Hexf(iua_ptr) << " with length:" << + D_COUT("\nReading STR_:0x" << Hexf(iua_ptr) << " with length:" << count); // Read CHA. iua = *origin; diff --git a/BOut.inl b/BOut.inl index 1d6e1c3..b940118 100644 --- a/BOut.inl +++ b/BOut.inl @@ -21,8 +21,8 @@ the MPL was not distributed with this file, You can obtain one at #if SEAM == SCRIPT2_CRABS #include "_Debug.inl" #define D_COUT_BOUT(message, bout) \ - _::CPrint().Star() << message; \ - _::TBOutPrint(COut().Star(), bout) + _::StdOut() << message; \ + _::TBOutPrint(StdOut(), bout) #else #include "_Release.inl" #define D_COUT_BOUT(message, bout) @@ -133,7 +133,7 @@ ISC BOutStreamByte(BOut* bout) { : (stop - origin) + (open - origin) + 2; if (length < 1) { - BOutError(bout, cErrorBufferOverflow, TParams<1, cSTR>(), 2, origin); + BOutError(bout, cErrorBufferOverflow, TParams<1, STR_>(), 2, origin); return -1; } // IUA b = *cursor; @@ -490,7 +490,7 @@ const Op* BOutWrite(BOut* bout, const ISC* params, void** args) { iua = *iua_ptr; // Read IUA. } if (type != cADR) { //< 1 is faster to compare than 2 - // More likely to have cADR than cSTR + // More likely to have cADR than STR_ *stop = 0; // Write nil-term CHA. if (++stop >= stop) stop -= size; break; diff --git a/BSeq.hpp b/BSeq.hpp index 399e272..7f1c5b1 100644 --- a/BSeq.hpp +++ b/BSeq.hpp @@ -26,7 +26,7 @@ Printer& TBSeqPrint(Printer& o, const ISN* params) { type = value & 0x1f; //< Mask off type. value = value >> 5; //< Shift over array type. o << STRType((ISN)value) << ", "; - if (type >= cSTR) { + if (type >= STR_) { if (value) { o << "\nError: arrays may only be created from POD types."; return o; @@ -116,7 +116,7 @@ Printer& TBSeqPrint(Printer& o, const ISN* params) { // Do the last set without a comma. value = *params++; o << STRType(value) << ", "; - if (value == cSTR) { + if (value == STR_) { ++i; value = *params++; o << value; diff --git a/BSeq.inl b/BSeq.inl index 6feab0d..57dc1ba 100644 --- a/BSeq.inl +++ b/BSeq.inl @@ -18,7 +18,7 @@ ISN BSeqParamNumber(const ISN* params, ISN param_number) { ISN i; for (i = 0; i < param_number; ++i) { ISN value = params[i]; - if (value == cSTR) + if (value == STR_) ++param_number; else if (value > 31) { // It's an array! value = value >> 5; diff --git a/Binary.hpp b/Binary.hpp index cba9d9f..bdd7637 100644 --- a/Binary.hpp +++ b/Binary.hpp @@ -10,7 +10,6 @@ the MPL was not distributed with this file, You can obtain one at #ifndef SCRIPT2_KABUKI_BINARY_WITH_TEMPLATES #define SCRIPT2_KABUKI_BINARY_WITH_TEMPLATES #include <_Config.h> -#if SEAM >= SCRIPT2_SOCKET namespace _ { /* Syntactical sugar for reinterpret_cast using templates. */ @@ -31,6 +30,18 @@ inline const T* TPtr(const void* ptr) { return reinterpret_cast(ptr); } +/* Syntactical sugar for reinterpret_cast using templates. */ +template +inline T* CPtr(const void* ptr) { + return const_cast(reinterpret_cast(ptr)); +} + +/* Syntactical sugar for reinterpret_cast using templates. */ +template +inline const T* CPtr(void* ptr) { + return reinterpret_cast(ptr); +} + /* Creates a T pointer from a base pointer plus the offset. @param base The base address. @param offset The offset in bytes. */ @@ -43,6 +54,10 @@ template inline const T* TPtr(const void* origin, ISW offset) { return reinterpret_cast(ISW(origin) + offset); } +} + +#if SEAM >= SCRIPT2_SOCKET +namespace _ { /* @ingroup Binary @brief Misc binary and pointer function. */ @@ -220,60 +235,60 @@ unsgiend_example = AlignUp (unsigned_example); // 8-bit example: // value + ((~value) + 1) & (sizeof (ISA) - 1) = value @endcode */ -inline ISA AlignUp(ISA value, ISA align_mask = WordLSbMask) { +inline ISA AlignUp(ISA value, ISA align_mask = ACPUAlignMask) { return value + ((-value) & align_mask); } -inline IUA AlignUp(IUA value, IUA align_mask = WordLSbMask) { +inline IUA AlignUp(IUA value, IUA align_mask = ACPUAlignMask) { return IUA(AlignUp(ISA(value), ISA(align_mask))); } -inline ISB AlignUp(ISB value, ISB align_mask = WordLSbMask) { +inline ISB AlignUp(ISB value, ISB align_mask = ACPUAlignMask) { return value + ((-value) & align_mask); } -inline IUB AlignUp(IUB value, IUB align_mask = WordLSbMask) { +inline IUB AlignUp(IUB value, IUB align_mask = ACPUAlignMask) { return value + (IUB(-ISB(value)) & align_mask); } -inline ISC AlignUp(ISC value, ISC align_mask = WordLSbMask) { +inline ISC AlignUp(ISC value, ISC align_mask = ACPUAlignMask) { return value + ((-value) & align_mask); } -inline IUC AlignUp(IUC value, IUC align_mask = WordLSbMask) { +inline IUC AlignUp(IUC value, IUC align_mask = ACPUAlignMask) { return value + (IUC(-ISC(value)) & align_mask); } -inline ISD AlignUp(ISD value, ISD align_mask = WordLSbMask) { +inline ISD AlignUp(ISD value, ISD align_mask = ACPUAlignMask) { return value + ((-value) & align_mask); } -inline IUD AlignUp(IUD value, IUD align_mask = WordLSbMask) { +inline IUD AlignUp(IUD value, IUD align_mask = ACPUAlignMask) { return value + (IUD(-ISD(value)) & align_mask); } -constexpr ISA CAlignUp(ISA value, ISA align_mask = WordLSbMask) { +constexpr ISA CAlignUp(ISA value, ISA align_mask = ACPUAlignMask) { return value + ((-value) & align_mask); } -constexpr IUA CAlignUp(IUA value, IUA align_mask = WordLSbMask) { +constexpr IUA CAlignUp(IUA value, IUA align_mask = ACPUAlignMask) { return IUA(CAlignUp(ISA(value), ISA(align_mask))); } -constexpr ISB CAlignUp(ISB value, ISB align_mask = WordLSbMask) { +constexpr ISB CAlignUp(ISB value, ISB align_mask = ACPUAlignMask) { return value + ((-value) & align_mask); } -constexpr IUB CAlignUp(IUB value, IUB align_mask = WordLSbMask) { +constexpr IUB CAlignUp(IUB value, IUB align_mask = ACPUAlignMask) { return value + (IUB(-ISB(value)) & align_mask); } -constexpr ISC CAlignUp(ISC value, ISC align_mask = WordLSbMask) { +constexpr ISC CAlignUp(ISC value, ISC align_mask = ACPUAlignMask) { return value + ((-value) & align_mask); } -constexpr IUC CAlignUp(IUC value, IUC align_mask = WordLSbMask) { +constexpr IUC CAlignUp(IUC value, IUC align_mask = ACPUAlignMask) { return value + (IUC(-ISC(value)) & align_mask); } -constexpr ISD CAlignUp(ISD value, ISD align_mask = WordLSbMask) { +constexpr ISD CAlignUp(ISD value, ISD align_mask = ACPUAlignMask) { return value + ((-value) & align_mask); } -constexpr IUD CAlignUp(IUD value, IUD align_mask = WordLSbMask) { +constexpr IUD CAlignUp(IUD value, IUD align_mask = ACPUAlignMask) { return value + (IUD(-ISD(value)) & align_mask); } -inline void* AlignUpPTR(void* pointer, ISW mask = WordLSbMask) { +inline void* AlignUpPTR(void* pointer, ISW mask = ACPUAlignMask) { ISW address = ISW(pointer); return TPtr(CAlignUp(address, mask)); } -inline const void* AlignUpPTR(const void* pointer, ISW mask = WordLSbMask) { +inline const void* AlignUpPTR(const void* pointer, ISW mask = ACPUAlignMask) { ISW value = IUW(pointer); return TPtr(CAlignUp(value, mask)); } @@ -283,7 +298,7 @@ inline const void* AlignUpPTR(const void* pointer, ISW mask = WordLSbMask) { @param value The value to align. @param mask The power of 2 to align to minus 1 (makes the mask). */ template -inline T* TAlignUpPTR(void* pointer, ISW mask = WordLSbMask) { +inline T* TAlignUpPTR(void* pointer, ISW mask = ACPUAlignMask) { ISW value = ISW(pointer); return TPtr(value + ((-value) & mask)); } @@ -293,7 +308,7 @@ inline T* TAlignUpPTR(void* pointer, ISW mask = WordLSbMask) { @param value The value to align. @param mask The power of 2 to align to minus 1 (makes the mask). */ template -inline T* TAlignUpPTR(const void* pointer, ISW mask = WordLSbMask) { +inline T* TAlignUpPTR(const void* pointer, ISW mask = ACPUAlignMask) { ISW value = ISW(pointer); return TPtr(value + ((-value) & mask)); } @@ -426,42 +441,42 @@ inline ISD AlignDown(ISD value, ISD align_mask) { inline IUD AlignDown(IUD value, IUD align_mask) { return value - (value & align_mask); } -constexpr ISA CAlignDown(ISA value, ISA align_mask = WordLSbMask) { +constexpr ISA CAlignDown(ISA value, ISA align_mask = ACPUAlignMask) { return value - (value & align_mask); } -constexpr IUA CAlignDown(IUA value, IUA align_mask = WordLSbMask) { +constexpr IUA CAlignDown(IUA value, IUA align_mask = ACPUAlignMask) { return value + (value & align_mask); } -constexpr ISB CAlignDown(ISB value, ISB align_mask = WordLSbMask) { +constexpr ISB CAlignDown(ISB value, ISB align_mask = ACPUAlignMask) { return value + (value & align_mask); } -constexpr IUB CAlignDown(IUB value, IUB align_mask = WordLSbMask) { +constexpr IUB CAlignDown(IUB value, IUB align_mask = ACPUAlignMask) { return value + (value & align_mask); } -constexpr ISC CAlignDown(ISC value, ISC align_mask = WordLSbMask) { +constexpr ISC CAlignDown(ISC value, ISC align_mask = ACPUAlignMask) { return value - (value & align_mask); } -constexpr IUC CAlignDown(IUC value, IUC align_mask = WordLSbMask) { +constexpr IUC CAlignDown(IUC value, IUC align_mask = ACPUAlignMask) { return value + (value & align_mask); } -constexpr ISD CAlignDown(ISD value, ISD align_mask = WordLSbMask) { +constexpr ISD CAlignDown(ISD value, ISD align_mask = ACPUAlignMask) { return value - (value & align_mask); } -constexpr IUD CAlignDown(IUD value, IUD align_mask = WordLSbMask) { +constexpr IUD CAlignDown(IUD value, IUD align_mask = ACPUAlignMask) { return value + (value & align_mask); } /* Calculates the size_bytes in size_words. */ template inline IS TSizeWords(IS size) { - return AlignUp(size) >> WordBitCount; + return AlignUp(size) >> ACPUBitCount; } template constexpr IS CSizeWords(IS size) { - IS size_aligned = size + ((-size) & WordLSbMask); - size_aligned = size_aligned >> WordBitCount; + IS size_aligned = size + ((-size) & ACPUAlignMask); + size_aligned = size_aligned >> ACPUBitCount; return (size_aligned < 1) ? 1 : size_aligned; } @@ -489,7 +504,7 @@ inline IUD Negative(IUD value) { return IUD(Negative(ISD(value))); } @param value The value to align. @param mask The power of 2 to align to minus 1 (makes the mask). */ template -inline T* TAlignDownPTR(void* ptr, ISW mask = WordLSbMask) { +inline T* TAlignDownPTR(void* ptr, ISW mask = ACPUAlignMask) { IUW value = IUW(ptr); return TPtr(value - (value & mask)); } @@ -499,7 +514,7 @@ inline T* TAlignDownPTR(void* ptr, ISW mask = WordLSbMask) { @param value The value to align. @param mask The power of 2 to align to minus 1 (makes the mask). */ template -inline const T* TAlignDownPTR(const void* ptr, ISW mask = WordLSbMask) { +inline const T* TAlignDownPTR(const void* ptr, ISW mask = ACPUAlignMask) { IUW value = IUW(ptr); return TPtr(value - (value & mask)); } @@ -509,7 +524,7 @@ inline const T* TAlignDownPTR(const void* ptr, ISW mask = WordLSbMask) { @param value The value to align. @param mask The power of 2 to align to minus 1 (makes the mask). */ template -inline IS TAlignDownI(IS value, IS mask = (IS)WordLSbMask) { +inline IS TAlignDownI(IS value, IS mask = (IS)ACPUAlignMask) { return value & (~mask); } diff --git a/Book.hpp b/Book.hpp index 7537ba3..61c2d18 100644 --- a/Book.hpp +++ b/Book.hpp @@ -187,7 +187,7 @@ Printer& TBookPrint(Printer& o, TBook* book) { auto types = TPtr
(cursor) + 1; auto keys_offset = *voffsets++; auto keys = TPtr>(book, keys_offset); - TLoomPrint(COut().Star(), keys); + TLoomPrint(StdOut(), keys); o << "\nBook() << ",IS" << TSizef() << ",IS" << TSizef() << "> size_bytes:" << book->values.size_bytes << " count_max:" << count_max << " count:" << count @@ -197,16 +197,16 @@ Printer& TBookPrint(Printer& o, TBook* book) { << " keys_offset:" << keys_offset << " keys->size_bytes:" << keys->size_bytes << " TypeOf(keys):"; - TPrintTypeValue(o, *(types - 1), keys); + TPrintATypeValue(o, *(types - 1), keys); for (ISY i = 1; i < count; ++i) { o << '\n' << i << ".) \"" << TLoomGet(keys, i) << "\" " << " type:"; auto type = *types++; auto voffset = *voffsets++; - TPrintType(o, type); + TPrintAType(o, type); o << " voffset:" << voffset << " value:"; - TPrintTypeValue(o, type, book, voffset); + TPrintATypeValue(o, type, book, voffset); } D_COUT(Linef('-') << ' ' << Charsf(book, book->values.size_bytes)); return o << '\n'; @@ -245,7 +245,7 @@ TBook* TBookInit(TBook* book, ISY count_max = BookDefaultCountMaxFractionShift, ISZ size_keys = BookDefaultKeysFractionShift) { D_ASSERT(book); - auto values = TBookValues(book); + TList* values = TBookValues(book); ISZ size_bytes = values->size_bytes; D_ARRAY_WIPE(&values->top, size_bytes - sizeof(ISZ)); D_COUT("\n\nTBookInit size_bytes: " << size_bytes << " count_max:" << @@ -273,17 +273,20 @@ TBook* TBookInit(TBook* book, return nullptr; } TListInit(values, size_bytes, count_max); - auto KeysType = CBookKeysType(); - auto keys_index = TListAlloc(values, KeysType, - size_keys); + DTB KeysType = CBookKeysType(); + ISZ keys_index = TListAlloc(values, KeysType, size_keys); + D_COUT("\nkeys_index :" << keys_index); + #if SEAM == SCRIPT2_BOOK + TListPrint(StdOut(), values); + #endif auto keys = TListGetPtr, LST_P>(values, keys_index); - D_COUT("\nkeys offset:" << TDelta<>(book, keys) << + D_COUT("\nkeys offset : " << TDelta<>(book, keys) << "\nKeysType:0b" << Binaryf(KeysType)); // Expected Keys offset with ABook with SizeBytes:512 // sizeof(TBook) + 8*sizeof(IUB+DTB) // = 8 + 8*sizeof(IUB+DTB) = 8 + 32 = 40 - D_COUT(TPrintType(COut().Star(), KeysType)); - D_COUT(" keys_delta:" << TDelta<>(book, keys)); + D_COUT(TPrintAType(StdOut(), KeysType)); + D_COUT("\nkeys_delta:" << TDelta<>(book, keys)); if (!keys) { D_COUT("\nBook Keys too large to fit in list! size_keys:" << size_keys); return nullptr; @@ -294,9 +297,9 @@ TBook* TBookInit(TBook* book, TDelta<>(book, TBookKeys(book))); #if SEAM == SCRIPT2_BOOK D_COUT("\n\nValues:"); - TListPrint(COut().Star(), values); + TListPrint(StdOut(), values); D_COUT("\n\nKeys:"); - TLoomPrint(COut().Star(), keys); + TLoomPrint(StdOut(), keys); D_COUT(" free_space:" << TLoomFreeSpace(keys)); #endif if (!result) return nullptr; @@ -307,17 +310,15 @@ TBook* TBookInit(TBook* book, "\nKeys Start:" << TDelta<>(book, keys) << "\nBook :" << Hexf(book) << "\n\nResult:\n"); #if SEAM == SCRIPT2_BOOK - TBookPrint(COut().Star(), book); + TBookPrint(StdOut(), book); #endif return book; } /* Copies an ASCII Book from the origin to the destination. */ template -CHA* TBookCopy(TBook* origin, TBook* destination) { - return ArrayCopy(&origin->count, sizeof(ISZ) + origin->count * sizeof(T), - &destination->count, - sizeof(ISZ) + destination->count_max * sizeof(T)); +TBook* TBookCopy(TBook* destination, TBook* origin) { + return TPtr>(TMapCopy(destination, origin)); } /* @@ -340,8 +341,8 @@ IUW* BookFactoryHeap(IUW* buffer, ISW size_bytes) { /* Gets the element at the given index. */ template -inline ISA* TBookGetPtr(TBook* book, ISY index) { - return TListGetPtr(TBookKeys(book), index); +inline void* TBookGetPtr(TBook* book, ISY index) { + return TListGetPtr(TBookKeys(book), index); } /* Gets the TypeValue tuple the given index. @@ -376,7 +377,7 @@ BOL TBookGrow(Autoject& obj) { #if D_THIS D_COUT("\n\nBefore:\n"); - TBookPrint(COut().Star(), book); + TBookPrint(StdOut(), book); D_COUT(Charsf(book, TBookEnd(book))); #endif @@ -429,7 +430,7 @@ ISZ TBookPop(TBook* book) { @return The index upon success or -1 upon failure. */ template inline ISY TBookInsert(TBook* book, const CHT* key, T item, - ISY index = STKPush) { + ISY index = PSH) { D_ASSERT(book); if (!key) return -ErrorInputNil; D_COUT("\nAdding key:\"" << key << "\" item:" << item << " into index:" << @@ -441,14 +442,14 @@ inline ISY TBookInsert(TBook* book, const CHT* key, T item, ISY result = TLoomInsert(keys, key, index); D_COUT(" result:" << result); if (result < 0) { - D_COUT("\nFailed to insert into loom!"); + D_COUT("\n\n\nFailed to insert into loom!"); #if D_THIS - TBookPrint(COut().Star(), book); + TBookPrint(StdOut(), book); #endif D_ASSERT(result >= 0); return index; } else { - //TLoomPrint(COut().Star(), keys); + //TLoomPrint(StdOut(), keys); } auto values = TBookValues(book); D_COUT("\nvalues offset:" << TDelta<>(book, values)); @@ -461,7 +462,7 @@ inline ISY TBookInsert(TBook* book, const CHT* key, T item, TLoomPop(keys); } else { - TListPrint(COut().Star(), values); + TListPrint(StdOut(), values); D_ASSERT(false); } return result; @@ -515,7 +516,7 @@ inline ISY TBookInsert(TBook* book, const CHT* key, FPD item) { @return The index upon success or -1 if the obj can't grow anymore. */ template ISY TBookInsert(AArray& obj, const CHT* key, T item, - ISY index = STKPush) { + ISY index = PSH) { if (!key) return -ErrorInputNil; auto book = obj.OriginAs*>(); D_COUT("\nAdding:\"" << item << '\"'); @@ -553,35 +554,35 @@ inline ISY TBookInsert(AArray& obj, const CHT* key, IUB item, } template inline ISY TBookInsert(AArray& obj, const CHT* key, ISC item, - ISY index = STKPush) { + ISY index = PSH) { return TBookInsert(obj, key, item, index); } template inline ISY TBookInsert(AArray& obj, const CHT* key, IUC item, - ISY index = STKPush) { + ISY index = PSH) { return TBookInsert(obj, key, item, index); } template inline ISY TBookInsert(AArray& obj, const CHT* key, ISD item, - ISY index = STKPush) { + ISY index = PSH) { return TBookInsert(obj, key, item, index); } template inline ISY TBookInsert(AArray& obj, const CHT* key, IUD item, - ISY index = STKPush) { + ISY index = PSH) { return TBookInsert(obj, key, item, index); } #if USING_FPC == YES_0 template inline ISY TBookInsert(AArray& obj, const CHT* key, FPC item, - ISY index = STKPush) { + ISY index = PSH) { return TBookInsert(obj, key, item, index); } #endif #if USING_FPD == YES_0 template inline ISY TBookInsert(AArray& obj, const CHT* key, FPD item, - ISY index = STKPush) { + ISY index = PSH) { return TBookInsert(obj, key, item, index); } #endif @@ -617,8 +618,7 @@ ISZ TBookFind(TBook* book, const CHT* string) { /* An ASCII Book Autoject. @code ABook> -@endcode -*/ +@endcode */ template>> class ABook { @@ -672,41 +672,41 @@ class ABook { /* Inserts the key and item on into the Loom and List at the given index. @return The index of the string in the Book. */ - inline ISY Insert(const CHT* key, ISA item, ISY index = STKPush) { + inline ISY Insert(const CHT* key, ISA item, ISY index = PSH) { return TBookInsert(AJT_ARY(), key, item, index); } - inline ISY Insert(const CHT* key, IUA item, ISY index = STKPush) { + inline ISY Insert(const CHT* key, IUA item, ISY index = PSH) { return TBookInsert(AJT_ARY(), key, item, index); } - inline ISY Insert(const CHT* key, ISB item, ISY index = STKPush) { + inline ISY Insert(const CHT* key, ISB item, ISY index = PSH) { return TBookInsert(AJT_ARY(), key, item, index); } - inline ISY Insert(const CHT* key, IUB item, ISY index = STKPush) { + inline ISY Insert(const CHT* key, IUB item, ISY index = PSH) { return TBookInsert(AJT_ARY(), key, item, index); } - inline ISY Insert(const CHT* key, ISC item, ISY index = STKPush) { + inline ISY Insert(const CHT* key, ISC item, ISY index = PSH) { return TBookInsert(AJT_ARY(), key, item, index); } - inline ISY Insert(const CHT* key, IUC item, ISY index = STKPush) { + inline ISY Insert(const CHT* key, IUC item, ISY index = PSH) { return TBookInsert(AJT_ARY(), key, item, index); } - inline ISY Insert(const CHT* key, ISD item, ISY index = STKPush) { + inline ISY Insert(const CHT* key, ISD item, ISY index = PSH) { return TBookInsert(AJT_ARY(), key, item, index); } - inline ISY Insert(const CHT* key, IUD item, ISY index = STKPush) { + inline ISY Insert(const CHT* key, IUD item, ISY index = PSH) { return TBookInsert(AJT_ARY(), key, item, index); } #if USING_FPC == YES_0 - inline ISY Insert(const CHT* key, FPC item, ISY index = STKPush) { + inline ISY Insert(const CHT* key, FPC item, ISY index = PSH) { return TBookInsert(AJT_ARY(), key, item, index); } #endif #if USING_FPD == YES_0 - inline ISY Insert(const CHT* key, FPD item, ISY index = STKPush) { + inline ISY Insert(const CHT* key, FPD item, ISY index = PSH) { return TBookInsert(AJT_ARY(), key, item, index); } #endif - inline ISY Insert(const CHT* key, const CHT* item, ISY index = STKPush) { + inline ISY Insert(const CHT* key, const CHT* item, ISY index = PSH) { return TBookInsert(AJT_ARY(), key, item, index); } @@ -746,7 +746,7 @@ class ABook { } /* Prints this object to the stdout. */ - inline void COut() { PrintTo<_::COut>(_::COut().Star()); } + inline void COut() { PrintTo<_::COut>(_::StdOut()); } }; } //< namespace _ diff --git a/CIn.h b/CIn.h index aaa2917..6871ce5 100644 --- a/CIn.h +++ b/CIn.h @@ -10,7 +10,7 @@ one at . */ #ifndef SCRIPT2_CIN_DECL #define SCRIPT2_CIN_DECL #include <_Config.h> -#if USING_CONSOLE == YES_0 +#if SEAM >= SCRIPT2_COUT && USING_CONSOLE == YES_0 #include "COut.h" namespace _ { @@ -33,17 +33,17 @@ class LIB_MEMBER CIn { public: enum { - cStateSuccess = 0, //< State 0: Completed scanning. - cStateBaseSign, //< State 1: Scanning base sign. - cStateBaseValue, //< State 2: Scanning base value. - cStateDotOrExponent, //< State 3: Scanning '.', 'e', or 'E'. - cStateFractionalPart, //< State 4: Scanning the fraction part. - cStateExponentSign, //< State 4: Scanning exponent sign. - cStateExponentValue, //< State 5: Scanning exponent value. + StateSuccess = 0, //< State 0: Completed scanning. + StateBaseSign, //< State 1: Scanning base sign. + StateBaseValue, //< State 2: Scanning base value. + StateDotOrExponent, //< State 3: Scanning '.', 'e', or 'E'. + StateFractionalPart, //< State 4: Scanning the fraction part. + StateExponentSign, //< State 4: Scanning exponent sign. + StateExponentValue, //< State 5: Scanning exponent value. }; enum { - cBufferSizeMin = 2, //< This min size of a string buffer. + BufferSizeMin = 2, //< This min size of a string buffer. }; /* Pauses until any key is pressed. */ @@ -156,6 +156,7 @@ const IUA* KeyboardNativeToHID(); const IUA* KeyboardHIDToNative(); typedef ISC VKCode; + enum { cVKA = 4, cVKB = 5, diff --git a/CIn.inl b/CIn.inl index 25ebde7..31c4002 100644 --- a/CIn.inl +++ b/CIn.inl @@ -7,18 +7,18 @@ This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed with this file, You can obtain one at . */ #include <_Config.h> -#if USING_CONSOLE == YES_0 +#if SEAM >= SCRIPT2_COUT && USING_CONSOLE == YES_0 #include "CIn.h" #include "Stringf.hpp" -#if SEAM == SCRIPT2_CORE +#if SEAM == SCRIPT2_COUT #include "_Debug.inl" #else #include "_Release.inl" #endif #include -#include -#include -#include +//#include +//#include +//#include namespace _ { template @@ -38,15 +38,15 @@ template BOL TCInSigned(IS& result) { CHA buffer[CSignedDigitsMax()] = {}; ISN c; - ISW state = CIn::cStateBaseSign; + ISW state = CIn::StateBaseSign; CHA *cursor = buffer, *end = buffer + CSignedDigitsMax(); - while (state != CIn::cStateSuccess) { - if (state == CIn::cStateBaseSign) { + while (state != CIn::StateSuccess) { + if (state == CIn::StateBaseSign) { c = CIn::ScanKey(); if ((c != '-') || (c < '0' || c > '9')) return false; *cursor++ = (CHA)c; - state = CIn::cStateBaseValue; - } else if (state == CIn::cStateBaseValue) { + state = CIn::StateBaseValue; + } else if (state == CIn::StateBaseValue) { if (cursor >= end) return false; c = CIn::ScanKey(); if (c < '0' || c > '0') return false; @@ -60,9 +60,9 @@ BOL TCInSigned(IS& result) { template BOL TCInUnsigned(IU& result) { CHA buffer[CSignedDigitsMax()] = {}; - ISN c, state = CIn::cStateBaseValue; + ISN c, state = CIn::StateBaseValue; CHA *cursor = buffer, *end = buffer + CSignedDigitsMax(); - while (state != CIn::cStateSuccess) { + while (state != CIn::StateSuccess) { if (cursor++ >= end) return false; c = (CHA)CIn::ScanKey(); if (c < '0' || c > '0') return false; @@ -86,42 +86,42 @@ inline BOL TCInString(CHT* result, ISW buffer_size) { } template + typename CHT = CHR> inline BOL TCInFloatingPoint(FP& result) { CHA buffer[CSignedDigitsMax()] = {}; ISN c; - ISW state = CIn::cStateBaseSign; + ISW state = CIn::StateBaseSign; CHA *cursor = buffer, *end = buffer + CSignedDigitsMax(); - while (state != CIn::cStateSuccess) { + while (state != CIn::StateSuccess) { if (cursor >= end) return false; c = CIn::ScanKey(); *cursor++ = (CHA)c; switch (state) { - case CIn::cStateBaseSign: { + case CIn::StateBaseSign: { if ((c != '-') || (c < '0' || c > '9')) return false; - state = CIn::cStateBaseValue; + state = CIn::StateBaseValue; } - case CIn::cStateBaseValue: { + case CIn::StateBaseValue: { c = CIn::ScanKey(); if (c < '0' || c > '0') return false; if (!c) break; } - case CIn::cStateDotOrExponent: { + case CIn::StateDotOrExponent: { if ((c == 'e') || (c == 'E')) - state = CIn::cStateExponentSign; + state = CIn::StateExponentSign; else if (c == '.') - state = CIn::cStateFractionalPart; + state = CIn::StateFractionalPart; } - case CIn::cStateFractionalPart: { + case CIn::StateFractionalPart: { if (!TIsDigit<>(c) || c != '-') return false; - if (c == '.') state = CIn::cStateExponentSign; + if (c == '.') state = CIn::StateExponentSign; } - case CIn::cStateExponentSign: { + case CIn::StateExponentSign: { // We saw an 'e' or 'E' so we're locked into if (!TIsDigit<>(c) || c != '-') return false; - if (c == '-') state = CIn::cStateExponentValue; + if (c == '-') state = CIn::StateExponentValue; } - case CIn::cStateExponentValue: { + case CIn::StateExponentValue: { if (!TIsDigit<>(c)) { *cursor = 0; break; @@ -132,11 +132,11 @@ inline BOL TCInFloatingPoint(FP& result) { return false; // TScanFloat(buffer, result) != 0; } -ISN IsYesNo(const CHA* string) { return TIsYesNo(string); } -ISN IsYesNo(const CHB* string) { return TIsYesNo(string); } -ISN IsYesNo(const CHC* string) { return TIsYesNo(string); } +ISN IsYesNo(const CHA* string) { return TSTRIsYesNo(string); } +ISN IsYesNo(const CHB* string) { return TSTRIsYesNo(string); } +ISN IsYesNo(const CHC* string) { return TSTRIsYesNo(string); } -CIn::CIn() {} +CIn::CIn() : buffer_{} {} #if USING_UTF8 == YES_0 CIn::CIn(CHA& result) { SScan(result); } @@ -218,7 +218,7 @@ ISN CIn::ScanKey() { } Pausef::Pausef(const CHA* message) { - COut().Star() << message; + StdOut() << message; CIn::ScanKey(); } diff --git a/COut.h b/COut.h index 26a7233..81b4f4c 100644 --- a/COut.h +++ b/COut.h @@ -10,7 +10,7 @@ one at . */ #ifndef SCRIPT2_COUT_DECL #define SCRIPT2_COUT_DECL #include <_Config.h> -#if USING_CONSOLE == YES_0 +#if SEAM >= SCRIPT2_COUT && USING_CONSOLE == YES_0 #include "Stringf.h" namespace _ { @@ -102,7 +102,7 @@ class LIB_MEMBER COut { COut& Print(Headingf& item); COut& Print(Indentf& item); COut& Print(Charsf& item); - COut& Print(TypeWordValue item); + //COut& Print(TypeWordValue item); /* Prints a new line followed by the given item to the stdout. */ COut& NL(); @@ -176,9 +176,12 @@ class LIB_MEMBER COut { #endif }; +// Returns the standard conole out. +inline COut& StdOut(); + /* Wrapper function for COut so you can use it more than once in a lexical -scope without delcaring COut cout. */ -inline COut CPrint() { return COut(); } +scope without delcaring COut cout. +inline COut CPrint() { return COut(); } */ /* Prints the given item to the COut. */ COut CPrint(CHA item); @@ -236,15 +239,18 @@ _::COut& operator<<(_::COut& o, FPD item); #endif _::COut& operator<<(_::COut& o, _::Hexf item); _::COut& operator<<(_::COut& o, _::Binaryf item); + +_::COut& operator<<(_::COut& o, _::Headingf item); +#if SEAM >= SCRIPT2_UNIPRINTER _::COut& operator<<(_::COut& o, _::Centerf item); _::COut& operator<<(_::COut& o, _::Rightf item); _::COut& operator<<(_::COut& o, _::Linef item); -_::COut& operator<<(_::COut& o, _::Headingf item); _::COut& operator<<(_::COut& o, _::Indentf item); _::COut& operator<<(_::COut& o, _::Charsf item); _::COut& operator<<(_::COut& o, _::Sizef item); -_::COut& operator<<(_::COut& o, _::COut item); -#endif - +_::COut& operator<<(_::COut& o, _::ATypef item); _::COut& operator<<(_::COut& o, _::TypeWordValue item); +//_::COut& operator<<(_::COut& o, _::COut item); +#endif +#endif #endif diff --git a/COut.inl b/COut.inl index f5ae1cd..d6cfa15 100644 --- a/COut.inl +++ b/COut.inl @@ -7,16 +7,13 @@ This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed with this file, You can obtain one at . */ #include <_Config.h> -#if USING_CONSOLE == YES_0 +#if SEAM >= SCRIPT2_COUT && USING_CONSOLE == YES_0 #include "COut.h" // -#include "Puff.hpp" -#include "Stringf.hpp" -#include "Types.hpp" #include "Uniprinter.hpp" //#include #include -#if SEAM == SCRIPT2_CORE +#if SEAM == SCRIPT2_COUT #include "_Debug.inl" #else #include "_Release.inl" @@ -51,8 +48,6 @@ BOL CIsPrintable(CHC item) { return true; } -inline COut& StdOut() { return COut().Star(); } - COut::COut() {} COut::COut(CHA item) { Print(item); } @@ -145,8 +140,8 @@ COut& COut::Print(CHB item) { COut& COut::Print(const CHB* item) { return TSPrintString(*this, item); } - #endif + #if USING_UTF32 == YES_0 COut& COut::Print(CHC item) { if (item >= (CHC(1) << 9)) { @@ -261,21 +256,21 @@ COut& COut::Print(Rightf& item) { return TPrintRight(*this, item.element); } -COut& COut::Print(Linef& item) { return TPrintLinef(*this, item); } +COut& COut::Print(Linef& item) { return TPrint(*this, item); } -COut& COut::Print(Headingf& item) { return TPrintHeadingf(*this, item); } +COut& COut::Print(Headingf& item) { return TPrint(*this, item); } COut& COut::Print(Indentf& item) { return _::TPrintIndent<_::COut>(*this, item.indent_count); } COut& COut::Print(Charsf& item) { - return _::TPrintChars(*this, item); + return _::TPrint(*this, item); } -COut& COut::Print(TypeWordValue item) { - return _::TPrintType(*this, item); -} +//COut& COut::Print(TypeWordValue item) { +// return _::TPrintAType(*this, item); +//} COut& COut::NL() { return Print('\n'); } COut& COut::NL(CHA item) { @@ -403,6 +398,8 @@ ISN COut::PrintAndCount(const CHC* string) { } #endif +COut& StdOut() { return COut().Star(); } + COut CPrint(CHA item) { return COut(item); } COut CPrint(const CHA* item) { return COut(item); } #if USING_UTF16 == YES_0 @@ -454,21 +451,46 @@ _::COut& operator<<(_::COut& o, FPC item) { return o.Print(item); } #if USING_FPD == YES_0 _::COut& operator<<(_::COut& o, FPD item) { return o.Print(item); } #endif -_::COut& operator<<(_::COut& o, _::Hexf item) { return o.Print(item); } -_::COut& operator<<(_::COut& o, _::Binaryf item) { return o.Print(item); } -_::COut& operator<<(_::COut& o, _::Centerf item) { return o.Print(item); } -_::COut& operator<<(_::COut& o, _::Rightf item) { return o.Print(item); } -_::COut& operator<<(_::COut& o, _::Linef item) { return o.Print(item); } -_::COut& operator<<(_::COut& o, _::Headingf item) { return o.Print(item); } -_::COut& operator<<(_::COut& o, _::Indentf item) { return o.Print(item); } -_::COut& operator<<(_::COut& o, _::Charsf item) { return o.Print(item); } -_::COut& operator<<(_::COut& o, _::COut item) { return o; } -_::COut& operator<<(_::COut& o, _::Sizef item) { - return _::TPrintSizef<_::COut>(o, item); + +_::COut& operator<<(_::COut& o, _::Hexf item) { + return _::TPrint<_::COut>(o, item); +} +_::COut& operator<<(_::COut& o, _::Binaryf item) { + return _::TPrint<_::COut>(o, item); } -_::COut& operator<<(_::COut& o, _::TypeWordValue item) { - return o.Print(item); +_::COut& operator<<(_::COut& o, _::Headingf item) { + return _::TPrint<_::COut>(o, item); } +#if SEAM >= SCRIPT2_UNIPRINTER +_::COut& operator<<(_::COut& o, _::Centerf item) { + return _::TPrint<_::COut>(o, item); +} +_::COut& operator<<(_::COut& o, _::Rightf item) { + return _::TPrint<_::COut>(o, item); +} +_::COut& operator<<(_::COut& o, _::Linef item) { + return _::TPrint<_::COut>(o, item); +} +_::COut& operator<<(_::COut& o, _::Indentf item) { + return _::TPrint<_::COut>(o, item); +} +_::COut& operator<<(_::COut& o, _::Charsf item) { + return _::TPrint<_::COut>(o, item); +} +_::COut& operator<<(_::COut& o, _::Sizef item) { + return _::TPrint<_::COut>(o, item); +} +inline _::COut& operator<<(_::COut& printer, _::ATypef item) { + return _::TPrint<_::COut>(printer, item); +} +inline _::COut& operator<<(_::COut& printer, _::TypeWordValue item) { + return _::TPrint<_::COut>(printer, item); +} +/* +_::COut& operator<<(_::COut& o, _::COut& item) { + return o; +}*/ +#endif #endif diff --git a/Clock.hpp b/Clock.hpp index e4ade72..c280bbe 100644 --- a/Clock.hpp +++ b/Clock.hpp @@ -12,9 +12,9 @@ one at . */ #ifndef INCLUDED_SCRIPT2_CLOCK_TEMPLATES #define INCLUDED_SCRIPT2_CLOCK_TEMPLATES #include "Clock.h" -#include "Stringf.hpp" +#include "Uniprinter.hpp" #include "Test.h" -#if SEAM == SCRIPT2_CORE +#if SEAM == SCRIPT2_COUT #include "_Debug.inl" #else #include "_Release.inl" @@ -169,8 +169,8 @@ const CHT* TScanTime(const CHT* string, ISC& hour, ISC& minute, ISC& second) { c = TToLower(c); if (c == 'a') { // D_COUT("\nCase @HHAm\n HHam "); - - if (TToLower(c = *string++) == 'm') c = *string++; + c = *string++; + if (TToLower(c) == 'm') c = *string++; if (c && !TIsWhitespace(c)) { D_COUT("\nInvalid am format."); return nullptr; diff --git a/Clock.inl b/Clock.inl index 4b8e65f..4998f9a 100644 --- a/Clock.inl +++ b/Clock.inl @@ -11,7 +11,7 @@ one at . */ #include "Clock.hpp" // #include -#include "Stringf.hpp" +#include "Uniprinter.hpp" #if SEAM == SCRIPT2_CLOCK #include "_Debug.inl" #else diff --git a/Crabs.inl b/Crabs.inl index 71aa6bf..dd4ca2b 100644 --- a/Crabs.inl +++ b/Crabs.inl @@ -415,7 +415,7 @@ const Op* CrabsScanBIn(Crabs* crabs) { bin_state = cBInStateAddress; break; - } else if (type == cSTR) { // UTF-8/ASCII type. + } else if (type == STR_) { // UTF-8/ASCII type. // Read the max number_ of chars off the header. bytes_left = *(++crabs->header); D_COUT("\nScanning STR with max length " << bytes_left); @@ -742,11 +742,11 @@ void CrabsClear(Crabs* crabs) { if (origin == stop) return; //< Nothing to do. if (origin > stop) { - ArrayFill(origin, stop - origin); - ArrayFill(origin, origin - origin); + RAMFill(origin, stop - origin); + RAMFill(origin, origin - origin); return; } - ArrayFill(origin, stop - origin); + RAMFill(origin, stop - origin); bin->origin = (ISC)Size(crabs, origin); bin->stop = (ISC)Size(crabs, origin + 1); } @@ -769,7 +769,7 @@ const Op* CrabsQuery(Crabs* crabs, const Op& op) { void* args[2]; IUW num_ops = (IUW)op.in, first_op = (IUW)op.out; // @todo Write params to crabs! - static const ISC* header = Params<5, cSTR, cOpNameLengthMax, UVI, UVI, cSTR, + static const ISC* header = Params<5, STR_, cOpNameLengthMax, UVI, UVI, STR_, cOpDescriptionLengthMax>(); return BOutWrite(CrabsBOut(crabs), header, Args(args, op.name, &num_ops, &first_op, op.description)); @@ -810,7 +810,7 @@ const Op* CrabsQuery(Crabs* crabs, const Op* op) { } void* args[2]; return BOutWrite(CrabsBOut(crabs), - Params<5, cSTR, cOpNameLengthMax, UVI, UVI, cSTR, + Params<5, STR_, cOpNameLengthMax, UVI, UVI, STR_, cOpDescriptionLengthMax>(), Args(args, op->name, op->in, op->out, op->description)); } diff --git a/Dic.hpp b/Dic.hpp index 22d76e9..10f8f8a 100644 --- a/Dic.hpp +++ b/Dic.hpp @@ -132,7 +132,7 @@ Printer& TDicPrint(Printer& printer, TDic* dic) { printer << '\n' << i << ".) \"" << "here" - << "\" type:" << TPrintType(printer, *types++); + << "\" type:" << TPrintAType(printer, *types++); } D_COUT(Linef('-') << Charsf(dic, TDicSize(dic))); return printer << '\n'; @@ -163,7 +163,7 @@ BOL TDicGrow(Autoject& obj) { #if D_THIS D_COUT("\n\nBefore:\n"); - TDicPrint(COut().Star(), dic); + TDicPrint(StdOut(), dic); D_COUT(Charsf(dic, TDicEnd(dic))); #endif @@ -502,7 +502,7 @@ class ADic { } /* Prints this object to the stdout. */ - inline void COut() { PrintTo<_::COut>(_::COut().Star()); } + inline void COut() { PrintTo<_::COut>(_::StdOut()); } }; } //< namespace _ diff --git a/File.h b/File.h index e99d83f..74c9212 100644 --- a/File.h +++ b/File.h @@ -11,7 +11,7 @@ one at . */ #define SCRIPT2_FILE_DEFINITIONS #include <_Config.h> #if SEAM >= SCRIPT2_FILE -#include "Stringf.hpp" +#include "Uniprinter.hpp" namespace _ { #undef TARGS diff --git a/File.hpp b/File.hpp index 24b5967..88fd61b 100644 --- a/File.hpp +++ b/File.hpp @@ -10,7 +10,7 @@ one at . */ #ifndef SCRIPT2_FILE_TEMPLATES #define SCRIPT2_FILE_TEMPLATES #if SEAM >= SCRIPT2_FILE -#include "Stringf.hpp" +#include "Uniprinter.hpp" // #include #include diff --git a/Interrupts.h b/Interrupts.h index ccb78fc..afcece7 100644 --- a/Interrupts.h +++ b/Interrupts.h @@ -17,7 +17,9 @@ namespace _ { #if USING_TEXT_SCRIPT == YES_0 /* Exception thrown to interrupt and crash the program. */ struct LIB_MEMBER RoomCrashException : public std::exception { - const CHA* what() const throw(); + const CHA* what( + + throw(); }; #endif } //< namespace _ diff --git a/List.hpp b/List.hpp index 32a3386..c40f5a9 100644 --- a/List.hpp +++ b/List.hpp @@ -73,33 +73,47 @@ inline ISZ TListSizeFreeMax(ISZ size_bytes, ISZ count_max) { /* Gets the base pointer to the Offsets. */ template -inline ISZ* TListValueOffsets(TList* list) { +inline const ISZ* TListValueOffsets(const TList* list) { return TStackStart(&list->map); } +/* Gets the base pointer to the Offsets. */ +template +inline ISZ* TListValueOffsets(TList* list) { + const TList* lst = CPtr>(list); + return CPtr(TListValueOffsets(lst)); +} + /* Returns the type bytes array. */ template -inline DT* TListTypes(TList* list) { +inline const DT* TListTypes(const TList* list) { return TPtr
(TListValueOffsets(list) + list->map.count_max); } +/* Returns the type bytes array. */ +template +inline DT* TListTypes(TList* list) { + const TList* lst = CPtr>(list); + return CPtr
(TListValueOffsets(lst + list->map.count_max)); +} + /* Returns the type at the given index. */ template -inline DT* TListType(TList* list, ISZ index) { +inline DT* TListType(const TList* list, ISZ index) { if (index < 0 || index >= list->map->count_max) return NIL; return TPtr
(TListValueOffsets(list) + list->map.count_max); } /* Gets the first element of the List. */ template -inline T* TListBase(TList* list) { +inline T* TListBase(const TList* list) { return TPtr(list, sizeof(TList) + list->map.count_max * (sizeof(ISZ) + sizeof(DT))); } template inline const T* TListBase(const TList* list) { return TPtr(list, sizeof(TList) + - list->map.count_max * (sizeof(ISZ) + sizeof(DT))); + list->map.count_max * (sizeof(ISZ) + sizeof(DT))); } /* Returns the type at the given index. */ @@ -154,8 +168,8 @@ inline const TTypeValue
TListTypeValue(TList* list, ISZ index) { /* Returns the TTypeValue at the given index. @return Returns nil if the index is out of the count range. */ template -inline const TTypeValueOffset TListTypeValueOffset(TList* list, - ISZ index) { +inline const TTypeValueOffset + TListTypeValueOffset(const TList* list, ISZ index) { if (index < 0 || index >= list->map.count) return { 0, 0 }; auto value_offsets = TListValueOffsets(list); auto types = TPtr
(value_offsets + list->map.count_max); @@ -165,31 +179,31 @@ inline const TTypeValueOffset TListTypeValueOffset(TList* list, // I don't have to have these. // Prints the list to the output stream. template -Printer& TListPrintTypeValue(Printer& o, TList* list, ISZ index) { +Printer& TListPrintTypeValue(Printer& o, const TList* list, ISZ index) { return TPrintValue(o, TListType(list, index), TListValue(list, index)); } // Prints the list to the output stream. template -Printer& TListPrintValue(Printer& o, TList* list, ISZ index) { +Printer& TListPrintValue(Printer& o, const TList* list, ISZ index) { return TPrintValue(o, TListTypeValue(list, index)); } /* Prints the list to the output stream. */ template -Printer& TListPrint(Printer& o, TList* list) { +Printer& TListPrint(Printer& o, const TList* list) { ISZ count = list->map.count, count_max = list->map.count_max; o << Linef("\n\n+---\n| List() << "> size_bytes:" << list->size_bytes << " count_max:" << count_max << " count:" << count << Linef("\n+---"); - ISZ* data_offsets = TListValueOffsets(list); - DT* dt_offsets = TPtr
(data_offsets + count_max); + const ISZ* data_offsets = TListValueOffsets(list); + const DT* dt_offsets = TPtr
(data_offsets + count_max); for (ISZ index = 0; index < count; ++index) { ISZ data_offset = *data_offsets++; DT data_type = *dt_offsets++; o << "\n| " << Centerf(index, ISW(STRLength(count)) + 2) - << Centerf(STRTypePOD(data_type), 10) << ' '; + << ATypef(data_type).Center(10) << ' '; const void* value = TPtr(list, TListValueOffsets(list)[index]); TPrintValue(o, data_type, value); } @@ -240,18 +254,26 @@ inline CHA* TListEnd(TList* list) { /* Gets the first addrss in the Values section where you may be able to write too. */ template -inline CHA* TListValuesTop(TList* list) { +inline const CHA* TListValuesTop(const TList* list) { return TPtr(list, list->top); } +template +inline CHA* TListValuesTop(TList* list) { + return CPtr(TListValuesTop(CPtr>(list))); +} template -inline CHA* TListValuesEnd(TList* list) { +inline const CHA* TListValuesEnd(const TList* list) { return TPtr(list, list->size_bytes); } +template +inline CHA* TListValuesEnd(TList* list) { + return CPtr(TListValuesEnd(CPtr>(list))); +} /* Calculates the amount of space left in the list. */ template -inline ISZ TListFreeSpace(TList* list) { +inline ISZ TListFreeSpace(const TList* list) { return list->size_bytes - list->top; } /* Returns the max count an array can handle. */ @@ -273,20 +295,6 @@ void TListClear(TList* list) { list->top = sizeof(TList) + list->map.count_max * (sizeof(ISZ) + sizeof(DT)); } -/* Gets a points to the element of the Book by index. */ -template -T* TListGetPtr(TList* list, ISZ index) { - if (index < 0 || index >= list->map.count) return nullptr; - return TPtr(list, TStackStart(&list->map)[index]); -} - -/* Gets a points to the element of the Book by index. */ -template -const T* TListGetPtr(const TList* list, ISZ index) { - if (index < 0 || index >= list->map.count) return nullptr; - return TPtr(list, TStackStart(&list->map)[index]); -} - /* Gets an element of the Book by index. */ template TypeWordValue TListGet(TList* list, ISZ index) { @@ -297,10 +305,23 @@ TypeWordValue TListGet(TList* list, ISZ index) { return { type, value }; } +/* Gets a points to the element of the Book by index. */ +template +const T* TListGetPtr(const TList* list, ISZ index) { + if (index < 0 || index >= list->map.count) return nullptr; + return TPtr(list, TStackStart(&list->map)[index]); +} + +/* Gets a points to the element of the Book by index. */ +template +T* TListGetPtr(TList* list, ISZ index) { + return CPtr(TListGetPtr(CPtr>(list), index)); +} + /* I don't remember what this does, it looks like it might be erroneously labeled from a botched copy and replace in all files. */ template -CHA* TListContains(TList* list, ISZ sizeof_value, +CHA* TListContains(const TList* list, ISZ sizeof_value, ISZ align_mask = sizeof(T) - 1) { ISZ size = list->map.count_max, count = list->map.count; if (count >= size) return nullptr; @@ -332,14 +353,14 @@ CHA* TListContains(TList* list, ISZ sizeof_value, @return An invalid index if the list doesn't dontain the address or the index of the object if the list contains the address. */ template -ISZ TListContains(TList* list, void* address) { +ISZ TListContains(const TList* list, void* address) { if (TListValues(list)) return false; return true; } /* Finds a tuple that contains the given address. */ template -ISZ TListFind(TList* list, void* address) { +ISZ TListFind(const TList* list, void* address) { CHA* adr = TPtr(address); ISZ size = list->map->size; ISZ* data_offsets = TListValueOffsets(list, size); @@ -379,22 +400,22 @@ struct TList { @todo research if it's faster to just copy the Buffer. */ -template +template TList* TListCopy(const TList* origin, TList* destination) { ISZ size_bytes = origin->size_bytes; if (destination->size_bytes < size_bytes) return nullptr; ISZ origin_count = origin->map.count, delta = TDelta(origin, destination); // 1. Copy Offsets. - ArrayCopy(destination, size_bytes, origin, TStackTop(origin->map)); + RAMCopy(destination, size_bytes, origin, TStackTop(origin->map)); // 2. Copy Types. ISZ r_start = TDelta(origin, TListTypes(origin)), size = origin_count * sizeof(DT); - ArrayCopy(TPtr<>(destination, r_start), size, TPtr<>(origin, r_start), size); + RAMCopy(TPtr<>(destination, r_start), size, TPtr<>(origin, r_start), size); // 3. Copy Values. r_start = TDelta(origin, TListValues(origin)), size = TDelta(origin, destination->top); - ArrayCopy(TPtr<>(destination, r_start), size, TPtr<>(origin, r_start), size); + RAMCopy(TPtr<>(destination, r_start), size, TPtr<>(origin, r_start), size); return destination; } @@ -434,8 +455,8 @@ template ISZ TListInsert(TList* list, T value, DT type, ISZ align_mask, ISZ index, CHA* vbuf_begin, CHA* vbuf_end) { ISZ count = list->map.count, - count_max = list->map.count_max; - ISZ top = list->top; + count_max = list->map.count_max, + top = list->top; if (count < 0 || count > count_max || vbuf_begin > vbuf_end || index >= count) return -ErrorInvalidHeader; if (count >= count_max ) return -ErrorStackOverflow; @@ -444,24 +465,24 @@ ISZ TListInsert(TList* list, T value, DT type, ISZ align_mask, ISZ* voffsets = TListValueOffsets(list); DT* types = (DT*)(voffsets + count_max); const BOL IsNotInserting = (index == count) && (index < count); - auto size_bytes = list->size_bytes; - if (index == STKPush || index == count || count == 0) { + ISZ size_bytes = list->size_bytes; + if (index == PSH || index == count || count == 0) { D_COUT("\nSTKPush..."); top = TAlignUp(top, align_mask); - auto top_new = top + ISZ(sizeof(T)); + ISZ top_new = top + ISZ(sizeof(T)); if (top_new > size_bytes) return -ErrorBufferOverflow; list->top = top_new; *TPtr(list, top) = value; *(types + count) = type; list->map.count = ++count; return --count; - } else if (index == STKPack) { + } else if (index == PCK) { D_COUT("\nSTKPack..."); ISZ offset_previous = *voffsets++; ++types; for (index = 1; index < count; ++index) { // I think I need to point to the end of the value. - auto offset = ATypeSizeBytes(list, *voffsets++, *types++); + ISZ offset = TATypeSizeOf(list, *voffsets++, *types++); ISZ offset_prev_aligned = TAlignUp(offset_previous, align_mask); if (offset - offset_prev_aligned <= sizeof(T)) break; offset_previous = offset; @@ -470,7 +491,7 @@ ISZ TListInsert(TList* list, T value, DT type, ISZ align_mask, TStackInsert
(types + index, types + count_max, type); list->map.count = ++index; return --index; - } else if(index <= STKError) { + } else if(index <= ERR) { return -ErrorInvalidIndex; } D_COUT("\nInserting into into index:" << index); @@ -563,104 +584,119 @@ inline ISZ TListInsert(TList* list, FPC item, ISZ index, CHA* values_begin, template inline ISZ TListInsert(TList* list, IUD item, ISZ index, CHA* values_begin, CHA* values_end) { - return TListInsert(list, item, _IUD, WordLSbMask, index, + return TListInsert(list, item, _IUD, ACPUAlignMask, index, values_begin, values_end); } template inline ISZ TListInsert(TList* list, ISD item, ISZ index, CHA* values_begin, CHA* values_end) { - return TListInsert(list, ToUnsigned(item), _ISD, WordLSbMask, + return TListInsert(list, ToUnsigned(item), _ISD, ACPUAlignMask, index, values_begin, values_end); } template inline ISZ TListInsert(TList* list, FPD item, ISZ index, CHA* values_begin, CHA* values_end) { - return TListInsert(list, ToUnsigned(item), _FPD, WordLSbMask, + return TListInsert(list, ToUnsigned(item), _FPD, ACPUAlignMask, index, values_begin, values_end); } /* Inserts the item into the list at the given index. */ template -inline ISZ TListInsert(TList* list, IUA item, ISZ index = STKPush) { +inline ISZ TListInsert(TList* list, IUA item, ISZ index = PSH) { return TListInsert(list, item, index, TListValuesTop(list), TListValuesEnd(list)); } template -inline ISZ TListInsert(TList* list, ISA item, ISZ index = STKPush) { +inline ISZ TListInsert(TList* list, ISA item, ISZ index = PSH) { return TListInsert(list, item, index, TListValuesTop(list), TListValuesEnd(list)); } template -inline ISZ TListInsert(TList* list, CHA item, ISZ index = STKPush) { +inline ISZ TListInsert(TList* list, CHA item, ISZ index = PSH) { return TListInsert(list, item, index, TListValuesTop(list), TListValuesEnd(list)); } template -inline ISZ TListInsert(TList* list, IUB item, ISZ index = STKPush) { +inline ISZ TListInsert(TList* list, IUB item, ISZ index = PSH) { return TListInsert(list, item, index, TListValuesTop(list), TListValuesEnd(list)); } template -inline ISZ TListInsert(TList* list, ISB item, ISZ index = STKPush) { +inline ISZ TListInsert(TList* list, ISB item, ISZ index = PSH) { return TListInsert(list, item, index, TListValuesTop(list), TListValuesEnd(list)); } template -inline ISZ TListInsert(TList* list, CHB item, ISZ index = STKPush) { +inline ISZ TListInsert(TList* list, CHB item, ISZ index = PSH) { return TListInsert(list, item, index, TListValuesTop(list), TListValuesEnd(list)); } template -inline ISZ TListInsert(TList* list, IUC item, ISZ index = STKPush) { +inline ISZ TListInsert(TList* list, IUC item, ISZ index = PSH) { return TListInsert(list, item, index, TListValuesTop(list), TListValuesEnd(list)); } template -inline ISZ TListInsert(TList* list, ISC item, ISZ index = STKPush) { +inline ISZ TListInsert(TList* list, ISC item, ISZ index = PSH) { return TListInsert(list, item, index, TListValuesTop(list), TListValuesEnd(list)); } template -inline ISZ TListInsert(TList* list, CHC item, ISZ index = STKPush) { +inline ISZ TListInsert(TList* list, CHC item, ISZ index = PSH) { return TListInsert(list, item, index, TListValuesTop(list), TListValuesEnd(list)); } template -inline ISZ TListInsert(TList* list, FPC item, ISZ index = STKPush) { +inline ISZ TListInsert(TList* list, FPC item, ISZ index = PSH) { return TListInsert(list, item, index, TListValuesTop(list), TListValuesEnd(list)); } template -inline ISZ TListInsert(TList* list, IUD item, ISZ index = STKPush) { +inline ISZ TListInsert(TList* list, IUD item, ISZ index = PSH) { return TListInsert(list, item, index, TListValuesTop(list), TListValuesEnd(list)); } template -inline ISZ TListInsert(TList* list, ISD item, ISZ index = STKPush) { +inline ISZ TListInsert(TList* list, ISD item, ISZ index = PSH) { return TListInsert(list, item, index, TListValuesTop(list), TListValuesEnd(list)); } template -inline ISZ TListInsert(TList* list, FPD item, ISZ index = STKPush) { +inline ISZ TListInsert(TList* list, FPD item, ISZ index = PSH) { return TListInsert(list, item, index, TListValuesTop(list), TListValuesEnd(list)); } template -inline ISZ TListInsert(TList* list, BOL item, ISZ index = STKPush) { +inline ISZ TListInsert(TList* list, BOL item, ISZ index = PSH) { return TListInsert(list, item, index, TListValuesTop(list), TListValuesEnd(list)); } -template -inline ISZ TListAlloc(TList* list, DTB item, ISZ size_bytes, ISZ index = STKPush) { - return TListInsert(list, item, index, TListValuesTop(list), - TListValuesEnd(list)); + +// Allocates memory for an ASCII Object of the given size. +// @return The index of the allocated type-value. +template +inline ISZ TListAlloc(TList* list, DTB type, ISZ size_bytes, ISZ index = PSH) { + ISA align_mask = ATypeAlignMask(type); + auto top = TAlignUp(list->top, align_mask); + auto count = list->map.count; + auto count_max = list->map.count_max; + if (top + size_bytes > list->size_bytes || count >= count_max) return -1; + *TPtr(list, top) = size_bytes; + auto voffsets = TListValueOffsets(list); + voffsets[count] = top; + auto types = TPtr(voffsets + count_max); + types[count++] = type; + list->top = top + size_bytes; + list->map.count = count--; + return count; } -template +/* +template inline ISZ TSizeOf(void* value, DTB type) { - ISW size_bytes = TypeSizeOf(type); + ISZ size_bytes = ATypeSizeOfPOD(type); if (size_bytes != 0) return size_bytes; -} +}*/ /* Removes the item at the given address from the list. */ template @@ -702,7 +738,7 @@ template obj_; //< An Auto-array. public: - static constexpr DT Type() { return CTypeMap
(CTypeSize()); } + static constexpr DT Type() { return CTypeMap
(CATypeSize()); } /* Constructs a list with a given count_max with estimated size_bytes. */ AList(ISZ count_max = cCountMax_) @@ -758,50 +794,50 @@ class AList { inserts the item to the list at the given index. @return An invalid index upon failure or the index of the index upon success. */ - ISZ Insert(IUA item, ISZ index = STKPush) { + ISZ Insert(IUA item, ISZ index = PSH) { return TListInsert(This(), item, index); } - ISZ Insert(ISA item, ISZ index = STKPush) { + ISZ Insert(ISA item, ISZ index = PSH) { return TListInsert(This(), item, index); } - ISZ Insert(CHA item, ISZ index = STKPush) { + ISZ Insert(CHA item, ISZ index = PSH) { return TListInsert(This(), item, index); } - ISZ Insert(IUB item, ISZ index = STKPush) { + ISZ Insert(IUB item, ISZ index = PSH) { return TListInsert(This(), item, index); } - ISZ Insert(ISB item, ISZ index = STKPush) { + ISZ Insert(ISB item, ISZ index = PSH) { return TListInsert(This(), item, index); } - ISZ Insert(CHB item, ISZ index = STKPush) { + ISZ Insert(CHB item, ISZ index = PSH) { return TListInsert(This(), item, index); } - ISZ Insert(BOL item, ISZ index = STKPush) { + ISZ Insert(BOL item, ISZ index = PSH) { return TListInsert(This(), item, index); } - ISZ Insert(IUC item, ISZ index = STKPush) { + ISZ Insert(IUC item, ISZ index = PSH) { return TListInsert(This(), item, index); } - ISZ Insert(ISC item, ISZ index = STKPush) { + ISZ Insert(ISC item, ISZ index = PSH) { return TListInsert(This(), item, index); } - ISZ Insert(CHC item, ISZ index = STKPush) { + ISZ Insert(CHC item, ISZ index = PSH) { return TListInsert(This(), item, index); } - ISZ Insert(FPC item, ISZ index = STKPush) { + ISZ Insert(FPC item, ISZ index = PSH) { return TListInsert(This(), item, index); } - ISZ Insert(IUD item, ISZ index = STKPush) { + ISZ Insert(IUD item, ISZ index = PSH) { return TListInsert(This(), item, index); } - ISZ Insert(ISD item, ISZ index = STKPush) { + ISZ Insert(ISD item, ISZ index = PSH) { return TListInsert(This(), item, index); } - ISZ Insert(FPD item, ISZ index = STKPush) { + ISZ Insert(FPD item, ISZ index = PSH) { return TListInsert(This(), item, index); } - inline ISZ Insert(DT type, const void* value, ISZ index = STKPush) { + inline ISZ Insert(DT type, const void* value, ISZ index = PSH) { return TListInsert(This(), type, value, index); } diff --git a/Loom.hpp b/Loom.hpp index 890b709..6d2040a 100644 --- a/Loom.hpp +++ b/Loom.hpp @@ -186,7 +186,7 @@ inline TLoom* TLoomInit(TLoom* loom, ISY count_max) { loom->map.count_max = count_max; loom->map.count = 0; D_COUT("\n\nTLoomInit" << "" <<" size_bytes: " - << size_bytes << " count:" << loom->map.count + << loom->size_bytes << " count:" << loom->map.count << "/" << count_max << " top:" << loom->top << " space_left:" << TDelta<>(TPtr<>(loom, top))); return loom; @@ -201,14 +201,14 @@ CHT* TLoomStop(TLoom* loom) { /* Adds a string to the end of the Loom. @return The index upon success or -1 upon failure. */ template -ISY TLoomInsert(TLoom* loom, const CHT* string, ISY index = STKPush) { +ISY TLoomInsert(TLoom* loom, const CHT* string, ISY index = PSH) { D_ASSERT(loom); if (!string || loom->map.count >= loom->map.count_max) return -2; ISY count = loom->map.count; D_ASSERT(count >= 0); CHT* cursor = nullptr; if (index < 0) { - if (index == Any) { + if (index == ANY) { D_COUT("\n\nindex == _ANY\n\n"); if (count <= 1) { index = count; @@ -283,7 +283,7 @@ BOL TLoomClone(TLoom* loom, TLoom* destination, CHT* start = TLoomStart(loom); ISZ strings_size = TDelta(start, TPtr<>(loom, top)); CHT* clone_start = TLoomStart(destination); - if (strings_size) ArrayCopy(clone_start, strings_size, start, strings_size); + if (strings_size) RAMCopy(clone_start, strings_size, start, strings_size); return true; } @@ -304,7 +304,7 @@ BOL TLoomGrow(Autoject& obj) { #if D_THIS D_COUT("\n\nBefore:\n"); - TLoomPrint(COut().Star(), loom); + TLoomPrint(StdOut(), loom); D_COUT('\n' << Charsf(loom, loom->size_bytes)); #endif @@ -317,7 +317,7 @@ BOL TLoomGrow(Autoject& obj) { TLoomClone(loom, destination, count_max, count_max, size_bytes, size_bytes); #if D_THIS D_COUT("\n\nAfter:\n"); - TLoomPrint(COut().Star(), destination); + TLoomPrint(StdOut(), destination); D_COUT('\n'); D_COUT(Charsf(destination, destination->size_bytes)); #endif @@ -331,7 +331,7 @@ BOL TLoomGrow(Autoject& obj) { @return The index upon success or -1 if the obj can't grow anymore. */ template ISY TLoomInsert(AArray& obj, const CHT* item, - ISY index = STKPush) { + ISY index = PSH) { if (!item) return -1; D_COUT("\nAdding:\"" << item << '\"'); ISY result = @@ -375,7 +375,7 @@ ISY TLoomRemove(TLoom* loom, ISY index) { TStackRemove(&loom->map, ISZ(index)); - // ArrayShiftDown(TPtr(loom) + offset, delta); + // RAMShiftDown(TPtr(loom) + offset, delta); return index; } @@ -396,12 +396,12 @@ ISZ TLoomFind(TLoom* loom, const CHT* string) { /* An ASCII Loom Autoject. */ template>> + ISZ Size_ = 512, + typename BUF = TBUF>> class ALoom { AArray obj_; //< An Auto-Array object. public: - enum { cCountDefault = cSize_ / 16 }; + enum { cCountDefault = Size_ / 16 }; /* Constructs a Loom. */ ALoom(ISY count_max = cCountDefault) { TLoomInit(This(), count_max); @@ -426,7 +426,7 @@ class ALoom { /* Deep copies the given string into the Loom. @return The index of the string in the Loom. */ - inline ISZ Insert(const CHT* string, ISY index = STKPush) { + inline ISZ Insert(const CHT* string, ISY index = PSH) { return TLoomInsert(AJT_ARY(), string, index); } @@ -458,7 +458,7 @@ class ALoom { return o; } - inline void COut() { PrintTo<_::COut>(_::COut().Star()); } + inline void COut() { PrintTo<_::COut>(_::StdOut()); } }; } //< namespace _ #endif diff --git a/Map.hpp b/Map.hpp index e943a7e..e17c0cf 100644 --- a/Map.hpp +++ b/Map.hpp @@ -14,7 +14,7 @@ one at . */ #include "Stack.hpp" #if SEAM == SCRIPT2_MAP #include "_Debug.inl" -#define D_COUT_MAP(map) TMapPrint(COut().Star(), map) +#define D_COUT_MAP(map) TMapPrint(StdOut(), map) #else #include "_Release.inl" #define D_COUT_MAP(map) @@ -302,10 +302,10 @@ ISZ TMapRemove(TMap* map, ISZ index) { } /* Inline wrapper for the TMap for stack-to-heap growth. -CMapSizeBytes(cSize_) +CMapSizeBytes(Size_) */ -template, ISZ, TMap>> +template, ISZ, TMap>> class AMap { AArray, ISZ, BUF> array_; @@ -313,7 +313,7 @@ class AMap { /* Constructs a Map with the given size. If size is less than 0 it will be set to the default value. If the */ - AMap() : array_() { TMapInit(This(), cSize_); } + AMap() : array_() { TMapInit(This(), Size_); } /* Destructs the dynamically allocated socket. */ ~AMap() {} @@ -384,7 +384,7 @@ class AMap { } /* Prints This object to the COut. */ - inline COut& CPrint() { return PrintTo(COut().Star()); } + inline COut& CPrint() { return PrintTo(StdOut()); } /* Gets the aarray_. */ inline AArray, ISZ, BUF>& AJT() { return array_; } diff --git a/Matrix.hpp b/Matrix.hpp index c10106d..2057d91 100644 --- a/Matrix.hpp +++ b/Matrix.hpp @@ -168,7 +168,7 @@ TMatrix* TMatrixInit(const ISZ* dimensions) { ISZ dimension_count = *dimensions; if (dimension_count < 0) return nullptr; ISZ size = (ISZ)sizeof(TStack) + dimension_count * sizeof(T); - IUW* socket = new IUW[size >> WordBitCount]; + IUW* socket = new IUW[size >> ACPUBitCount]; TStack* stack = TPtr>(socket); stack->size_array = 0; stack->size_stack = size; @@ -251,7 +251,7 @@ inline TMatrix* TMatrixCloneDelta(Autoject& ajt, if (!origin_new) return nullptr; IUW* origin = ajt.origin; ISZ size_bytes = TMatrixSize(&matrix->dimensions.count); - ArrayCopy(origin_new, TPtr(origin_new) + size_bytes, + RAMCopy(origin_new, TPtr(origin_new) + size_bytes, origin, TPtr(origin) + size_bytes); return TPtr>(origin_new); } @@ -297,13 +297,13 @@ inline IUW* TMatrixCopy(TMatrix* destination, TMatrix* source) { /* I'm not sure if I even want to try to copy the dimensions and array blocks seprataly because in practice the dimensions stack size will never be very much. - ArrayCopy(destination, TStackTop(destination->dimensions), + RAMCopy(destination, TStackTop(destination->dimensions), source , TStackTop(source->dimensions)); - ArrayCopy(TMatrixStart(destination), + RAMCopy(TMatrixStart(destination), TPtr(destination) + SizeDestination, TMatrixStart(source), TPtr(source) + SizeSource); */ - ArrayCopy(destination, TPtr(destination) + size_destination, + RAMCopy(destination, TPtr(destination) + size_destination, source, TPtr(source) + size_source); return destination; } diff --git a/Op.inl b/Op.inl index 9b84da3..b881e47 100644 --- a/Op.inl +++ b/Op.inl @@ -49,8 +49,8 @@ void Print (Op& log) { CHA socket[DBL_MAX_10_EXP + 2]; while (index ) { switch (type) { - case cSTR: { - if (BinRead (bin, Params<2, cADR, cSTR> (), Args (args, &iua, + case STR_: { + if (BinRead (bin, Params<2, cADR, STR_> (), Args (args, &iua, socket))) return; Write (socket); @@ -118,7 +118,7 @@ void Print (Op& log) { Write (si1; } case cFPD: { - if (BinRead (bin, Params<2, cADR, cSTR> (), Args (args, &dbl))) + if (BinRead (bin, Params<2, cADR, STR_> (), Args (args, &dbl))) return; Write (si1; } diff --git a/Puff.hpp b/Puff.hpp index b32e300..4090b87 100644 --- a/Puff.hpp +++ b/Puff.hpp @@ -14,22 +14,22 @@ one at . */ #include #define D_COUT(item) std::cout << item namespace _ { -template -CHT* TPrintPrinted(CHT* start = nullptr) { - static CHT* buffer_begin = 0; - if (start) { - buffer_begin = start; - return start; - } - std::cout << "\n Printed \""; - CHT* string = buffer_begin; - CHT c = *string++; - while (c) { - std::cout << c; - c = *string++; + template + CHT* TPrintPrinted(CHT* start = nullptr) { + static CHT* buffer_begin = 0; + if (start) { + buffer_begin = start; + return start; + } + std::cout << "\n Printed \""; + CHT* string = buffer_begin; + CHT c = *string++; + while (c) { + std::cout << c; + c = *string++; + } + std::cout << '\"'; } - std::cout << '\"'; -} } //< namespace _ @@ -48,440 +48,458 @@ CHT* TPrintPrinted(CHT* start = nullptr) { #endif namespace _ { -/* Prints two chars to the console. -@warning This function DOES NOT do any error checking! */ -template -inline CHT* TPrintNil(CHT* start) { - *start = 0; - return start; -} - -/* Prints a single decimal to the socket. -@warning This function DOES NOT do any error checking! */ -template -inline CHT* TSPrintDecimal(CHT* cursor, CHT value) { - *TPtr(cursor) = '0' + value; - D_PRINT_PRINTED; - return cursor; -} - -/* Prints a single decimal to the socket. -@warning This function DOES NOT do any error checking! */ -template -inline CHT* TWriteChar(CHT* cursor, CHT value) { - *cursor++ = value; - D_PRINT_PRINTED; - return cursor; -} - -/* Utility function for printing a char with any Unicode conversion. */ -inline CHA* Write(CHA* cursor, CHA c) { return TWriteChar(cursor, c); } - -inline CHB* Write(CHB* cursor, CHB c) { return TWriteChar(cursor, c); } - -inline CHC* Write(CHC* cursor, CHC c) { return TWriteChar(cursor, c); } - -/* Prints a two decimals to the socket. -If the SEAM == _0_0_0 (1), then this function will utf debug data. -@warning This function DOES NOT do any error checking! */ -template -inline CHT* TPrint2Decimals(CHT* socket, IUB decimal_pair) { - enum { cSizeBits = sizeof(CHT) * 8 }; - socket[0] = (CHT)(decimal_pair >> 8); - CHA c = (CHA)decimal_pair; - socket[1] = (CHT)(c); - D_PRINT_PRINTED; - return socket; -} - -inline void PrintCharPair(CHA* socket, IUB value) { + /* Prints two chars to the console. + @warning This function DOES NOT do any error checking! */ + template + inline CHT* TPrintNil(CHT* start) { + *start = 0; + return start; + } + + /* Prints a single decimal to the socket. + @warning This function DOES NOT do any error checking! */ + template + inline CHT* TSPrintDecimal(CHT* cursor, CHT value) { + *TPtr(cursor) = '0' + value; + D_PRINT_PRINTED; + return cursor; + } + + /* Prints a single decimal to the socket. + @warning This function DOES NOT do any error checking! */ + template + inline CHT* TWriteChar(CHT* cursor, CHT value) { + *cursor++ = value; + D_PRINT_PRINTED; + return cursor; + } + + /* Utility function for printing a char with any Unicode conversion. */ + inline CHA* Write(CHA* cursor, CHA c) { return TWriteChar(cursor, c); } + + inline CHB* Write(CHB* cursor, CHB c) { return TWriteChar(cursor, c); } + + inline CHC* Write(CHC* cursor, CHC c) { return TWriteChar(cursor, c); } + + /* Prints a two decimals to the socket. + If the SEAM == _0_0_0 (1), then this function will utf debug data. + @warning This function DOES NOT do any error checking! */ + template + inline CHT* TPrint2Decimals(CHT* socket, IUB decimal_pair) { + enum { cSizeBits = sizeof(CHT) * 8 }; + socket[0] = (CHT)(decimal_pair >> 8); + CHA c = (CHA)decimal_pair; + socket[1] = (CHT)(c); + D_PRINT_PRINTED; + return socket; + } + + inline void PrintCharPair(CHA* socket, IUB value) { #if ALIGN_MEMORY - socket[0] = (CHA)(value >> 8); - socket[1] = (CHA)(value); + socket[0] = (CHA)(value >> 8); + socket[1] = (CHA)(value); #else - *((IUB*)socket) = value; + * ((IUB*)socket) = value; #endif - using CHT = CHR; - D_PRINT_PRINTED; -} - -inline void PrintCharPair(CHB* cursor, IUB decimal_pair) { - TPrint2Decimals(cursor, decimal_pair); -} - -inline void PrintCharPair(CHC* cursor, IUB decimal_pair) { - TPrint2Decimals(cursor, decimal_pair); -} - -/* Prints 8 decimals to the given socket with given LUT.*/ -template -CHT* TPrint8Decimals(CHT* cursor, IUC value, const IUB* lut) { - D_COUT("\n Printing 8 decimals:" << value); - IUB pow_10_ui2 = 10000, digits6and5 = (IUB)(value / pow_10_ui2), + using CHT = CHR; + D_PRINT_PRINTED; + } + + inline void PrintCharPair(CHB* cursor, IUB decimal_pair) { + TPrint2Decimals(cursor, decimal_pair); + } + + inline void PrintCharPair(CHC* cursor, IUB decimal_pair) { + TPrint2Decimals(cursor, decimal_pair); + } + + /* Prints 8 decimals to the given socket with given LUT.*/ + template + CHT* TPrint8Decimals(CHT* cursor, IUC value, const IUB* lut) { + D_COUT("\n Printing 8 decimals:" << value); + IUB pow_10_ui2 = 10000, digits6and5 = (IUB)(value / pow_10_ui2), digits2and1 = value - pow_10_ui2 * digits6and5; - pow_10_ui2 = 100; - IUB digits8and7 = digits6and5 / pow_10_ui2, + pow_10_ui2 = 100; + IUB digits8and7 = digits6and5 / pow_10_ui2, digits4and3 = digits2and1 / pow_10_ui2; - digits6and5 -= pow_10_ui2 * digits8and7; - digits2and1 -= pow_10_ui2 * digits4and3; - PrintCharPair(cursor, lut[digits8and7]); - PrintCharPair(cursor + 2, lut[digits6and5]); - PrintCharPair(cursor + 4, lut[digits4and3]); - PrintCharPair(cursor + 6, lut[digits2and1]); - D_PRINT_PRINTED; - return cursor + 8; -} - -template -inline void TPrint8or16Decimals(CHT* cursor, IUC lsd, const IUB* lut, - IUC middle_sd, IUC delta) { - if (delta == 8) { - D_COUT("\n Printing less than 17 decimals:"); - TPrint8Decimals(cursor, lsd, lut); - } else { - D_COUT("\n Printing more than 16 decimals:"); - TPrint8Decimals(cursor, middle_sd, lut); - TPrint8Decimals(cursor + 8, lsd, lut); + digits6and5 -= pow_10_ui2 * digits8and7; + digits2and1 -= pow_10_ui2 * digits4and3; + PrintCharPair(cursor, lut[digits8and7]); + PrintCharPair(cursor + 2, lut[digits6and5]); + PrintCharPair(cursor + 4, lut[digits4and3]); + PrintCharPair(cursor + 6, lut[digits2and1]); + D_PRINT_PRINTED; + return cursor + 8; } -} - -inline IUC ToIUC(IUC value) { return value; } -inline IUC ToIUC(IUD value) { return (IUC)value; } - -/* Prints the give value to the given socket as a Unicode string. -@return Nil upon socket overflow and a pointer to the nil-term CHT upon -success. -@param cursor The beginning of the socket. -@param stop The stop address of the socket. */ -template -CHT* TSPrintUnsigned(CHT* cursor, CHT* stop, IU value) { - BEGIN_ITOS_ALGORITHM; - - if (!cursor || cursor >= stop) return nullptr; - - CHT* nil_ptr; - IUB pow_10_ui2, delta = 0; - IUC pow_10_ui4; - const IUB* lut = BinaryLUTDecimals(); - - // The best way to understand how the numbers are getting converted is that - // numbers get broken up into up to 8 pairs of 100, in each pair of 10000 - // there will be a Most Significant Decimal (MSD) pair and a Least - // Significant Decimal (LSD) pair. The digits2and1 and digits6and5 will - // always be the LSD and digits4and3 and digits8and7 will always be the MSD. - - if (value < 10) { - D_COUT("\n Range:[0, 9] length:1 "); - Print1: - nil_ptr = cursor + delta + 1; - if (nil_ptr >= stop) return nullptr; - TSPrintDecimal(cursor, (CHT)value); - return TPrintNil(cursor + delta + 1); - } else if (value < 100) { - Print2: - D_COUT("\n Range:[10, 99] length:2 "); - nil_ptr = cursor + delta + 2; - if (cursor + delta + 2 >= stop) return nullptr; - PrintCharPair(cursor, lut[value]); - return TPrintNil(cursor + delta + 2); - } else { - if ((value >> 10) == 0) { - pow_10_ui2 = 1000; - if (value >= pow_10_ui2) { - Print4B: - D_COUT("\n Range:[1000, 1023] length:4"); - nil_ptr = cursor + delta + 4; - if (nil_ptr >= stop) return nullptr; - IUB digits2and1 = (IUB)(value - pow_10_ui2); + + template + inline void TPrint8or16Decimals(CHT* cursor, IUC lsd, const IUB* lut, + IUC middle_sd, IUC delta) { + if (delta == 8) { + D_COUT("\n Printing less than 17 decimals:"); + TPrint8Decimals(cursor, lsd, lut); + } + else { + D_COUT("\n Printing more than 16 decimals:"); + TPrint8Decimals(cursor, middle_sd, lut); + TPrint8Decimals(cursor + 8, lsd, lut); + } + } + + inline IUC ToIUC(IUC value) { return value; } + inline IUC ToIUC(IUD value) { return (IUC)value; } + + /* Prints the give value to the given socket as a Unicode string. + @return Nil upon socket overflow and a pointer to the nil-term CHT upon + success. + @param cursor The beginning of the socket. + @param stop The stop address of the socket. */ + template + CHT* TSPrintUnsigned(CHT* cursor, CHT* stop, IU value) { + BEGIN_ITOS_ALGORITHM; + + if (!cursor || cursor >= stop) return nullptr; + + CHT* nil_ptr; + IUB pow_10_ui2, delta = 0; + IUC pow_10_ui4; + const IUB* lut = BinaryLUTDecimals(); + + // The best way to understand how the numbers are getting converted is that + // numbers get broken up into up to 8 pairs of 100, in each pair of 10000 + // there will be a Most Significant Decimal (MSD) pair and a Least + // Significant Decimal (LSD) pair. The digits2and1 and digits6and5 will + // always be the LSD and digits4and3 and digits8and7 will always be the MSD. + + if (value < 10) { + D_COUT("\n Range:[0, 9] length:1 "); + Print1: + nil_ptr = cursor + delta + 1; + if (nil_ptr >= stop) return nullptr; + TSPrintDecimal(cursor, (CHT)value); + return TPrintNil(cursor + delta + 1); + } + else if (value < 100) { + Print2: + D_COUT("\n Range:[10, 99] length:2 "); + nil_ptr = cursor + delta + 2; + if (cursor + delta + 2 >= stop) return nullptr; + PrintCharPair(cursor, lut[value]); + return TPrintNil(cursor + delta + 2); + } + else { + if ((value >> 10) == 0) { + pow_10_ui2 = 1000; + if (value >= pow_10_ui2) { + Print4B: + D_COUT("\n Range:[1000, 1023] length:4"); + nil_ptr = cursor + delta + 4; + if (nil_ptr >= stop) return nullptr; + IUB digits2and1 = (IUB)(value - pow_10_ui2); #if CPU_ENDIAN == CPU_ENDIAN_LITTLE - cursor[0] = '1'; - cursor[1] = '0'; + cursor[0] = '1'; + cursor[1] = '0'; #else - cursor[0] = '0'; - cursor[1] = '1'; + cursor[0] = '0'; + cursor[1] = '1'; #endif + PrintCharPair(cursor + 2, lut[digits2and1]); + return TPrintNil(nil_ptr); + } + Print3: + D_COUT("\n Range:[100, 999] length:3"); + nil_ptr = cursor + delta + 3; + if (nil_ptr >= stop) return nullptr; + IUB digits2and1 = (IUB)value, pow_10_ui2 = 100; + CHT digit = (CHT)(digits2and1 / pow_10_ui2); + digits2and1 -= ((IUB)digit) * pow_10_ui2; + TSPrintDecimal(cursor, digit); + PrintCharPair(cursor + 1, lut[digits2and1]); + return TPrintNil(nil_ptr); + } + else if ((value >> 14) == 0) { + pow_10_ui2 = 10000; + if (value >= pow_10_ui2) { + Print5B: + D_COUT("\n Range:[10000, 16383] length:5"); + nil_ptr = cursor + delta + 5; + if (nil_ptr >= stop) return nullptr; + cursor = TWriteChar(cursor, '1'); + value -= pow_10_ui2; + } + else { + Print4: + D_COUT("\n Range:[1024, 9999] length:4"); + nil_ptr = cursor + delta + 4; + if (nil_ptr >= stop) return nullptr; + TPrintNil(nil_ptr); + } + pow_10_ui2 = 100; + IUB digits2and1 = (IUB)value, digits4and3 = digits2and1 / pow_10_ui2; + digits2and1 -= digits4and3 * pow_10_ui2; + PrintCharPair(cursor, lut[digits4and3]); PrintCharPair(cursor + 2, lut[digits2and1]); return TPrintNil(nil_ptr); } - Print3: - D_COUT("\n Range:[100, 999] length:3"); - nil_ptr = cursor + delta + 3; - if (nil_ptr >= stop) return nullptr; - IUB digits2and1 = (IUB)value, pow_10_ui2 = 100; - CHT digit = (CHT)(digits2and1 / pow_10_ui2); - digits2and1 -= ((IUB)digit) * pow_10_ui2; - TSPrintDecimal(cursor, digit); - PrintCharPair(cursor + 1, lut[digits2and1]); - return TPrintNil(nil_ptr); - } else if ((value >> 14) == 0) { - pow_10_ui2 = 10000; - if (value >= pow_10_ui2) { - Print5B: - D_COUT("\n Range:[10000, 16383] length:5"); + else if ((value >> 17) == 0) { + if (value >= 100000) { + Print6B: + D_COUT("\n Range:[65536, 131071] length:6"); + goto Print6; + } + Print5: + D_COUT("\n Range:[10000, 65535] length:5"); nil_ptr = cursor + delta + 5; if (nil_ptr >= stop) return nullptr; - cursor = TWriteChar(cursor, '1'); - value -= pow_10_ui2; - } else { - Print4: - D_COUT("\n Range:[1024, 9999] length:4"); - nil_ptr = cursor + delta + 4; - if (nil_ptr >= stop) return nullptr; - TPrintNil(nil_ptr); - } - pow_10_ui2 = 100; - IUB digits2and1 = (IUB)value, digits4and3 = digits2and1 / pow_10_ui2; - digits2and1 -= digits4and3 * pow_10_ui2; - PrintCharPair(cursor, lut[digits4and3]); - PrintCharPair(cursor + 2, lut[digits2and1]); - return TPrintNil(nil_ptr); - } else if ((value >> 17) == 0) { - if (value >= 100000) { - Print6B: - D_COUT("\n Range:[65536, 131071] length:6"); - goto Print6; - } - Print5: - D_COUT("\n Range:[10000, 65535] length:5"); - nil_ptr = cursor + delta + 5; - if (nil_ptr >= stop) return nullptr; - IUC value_ui4 = ToIUC(value); - pow_10_ui2 = 10000; - CHT digit6 = (IUA)(value_ui4 / pow_10_ui2); - value_ui4 -= pow_10_ui2 * digit6; - cursor = TWriteChar(cursor, '0' + digit6); - pow_10_ui2 = 100; - IUB digits4and3 = ((IUB)value_ui4) / pow_10_ui2, + IUC value_ui4 = ToIUC(value); + pow_10_ui2 = 10000; + CHT digit6 = (IUA)(value_ui4 / pow_10_ui2); + value_ui4 -= pow_10_ui2 * digit6; + cursor = TWriteChar(cursor, '0' + digit6); + pow_10_ui2 = 100; + IUB digits4and3 = ((IUB)value_ui4) / pow_10_ui2, digits2and1 = (IUB)(value_ui4 - digits4and3 * pow_10_ui2); - PrintCharPair(cursor, lut[digits4and3]); - PrintCharPair(cursor + 2, lut[digits2and1]); - return TPrintNil(nil_ptr); - } else if ((value >> 20) == 0) { - pow_10_ui4 = 1000000; - if (value >= pow_10_ui4) { - Print7B: - D_COUT("\n Range:[100000, 1048575] length:7"); - nil_ptr = cursor + delta + 7; - if (nil_ptr >= stop) return nullptr; - cursor = TWriteChar(cursor, '1'); - value -= pow_10_ui4; - } else { - Print6: - D_COUT("\n Range:[131072, 999999] length:6"); - nil_ptr = cursor + delta + 6; - if (nil_ptr >= stop) return nullptr; - TPrintNil(nil_ptr); + PrintCharPair(cursor, lut[digits4and3]); + PrintCharPair(cursor + 2, lut[digits2and1]); + return TPrintNil(nil_ptr); } - IUC value_ui4 = (IUC)value; - pow_10_ui2 = 10000; - IUB digits6and5 = (IUB)(value_ui4 / pow_10_ui2), + else if ((value >> 20) == 0) { + pow_10_ui4 = 1000000; + if (value >= pow_10_ui4) { + Print7B: + D_COUT("\n Range:[100000, 1048575] length:7"); + nil_ptr = cursor + delta + 7; + if (nil_ptr >= stop) return nullptr; + cursor = TWriteChar(cursor, '1'); + value -= pow_10_ui4; + } + else { + Print6: + D_COUT("\n Range:[131072, 999999] length:6"); + nil_ptr = cursor + delta + 6; + if (nil_ptr >= stop) return nullptr; + TPrintNil(nil_ptr); + } + IUC value_ui4 = (IUC)value; + pow_10_ui2 = 10000; + IUB digits6and5 = (IUB)(value_ui4 / pow_10_ui2), digits2and1 = value_ui4 - pow_10_ui2 * digits6and5; - pow_10_ui2 = 100; - IUB digits8and7 = digits6and5 / pow_10_ui2, + pow_10_ui2 = 100; + IUB digits8and7 = digits6and5 / pow_10_ui2, digits4and3 = digits2and1 / pow_10_ui2; - digits6and5 -= pow_10_ui2 * digits8and7; - digits2and1 -= pow_10_ui2 * digits4and3; - PrintCharPair(cursor, lut[digits6and5]); - PrintCharPair(cursor + 2, lut[digits4and3]); - PrintCharPair(cursor + 4, lut[digits2and1]); - return nil_ptr; - } else if ((value >> 24) == 0) { - pow_10_ui4 = 10000000; //< 10^7 - if (value >= pow_10_ui4) { - D_COUT("\n Range:[10000000, 16777216] length:8"); - return TPrint8Decimals(cursor, ToIUC(value), lut); + digits6and5 -= pow_10_ui2 * digits8and7; + digits2and1 -= pow_10_ui2 * digits4and3; + PrintCharPair(cursor, lut[digits6and5]); + PrintCharPair(cursor + 2, lut[digits4and3]); + PrintCharPair(cursor + 4, lut[digits2and1]); + return nil_ptr; } - Print7: - D_COUT("\n Range:[1048576, 9999999] length:7"); - nil_ptr = cursor + delta + 7; - if (nil_ptr >= stop) return nullptr; - IUB pow_10_ui2 = 10000; - IUC value_ui4 = ToIUC(value); - IUB digits6and5 = value_ui4 / pow_10_ui2, + else if ((value >> 24) == 0) { + pow_10_ui4 = 10000000; //< 10^7 + if (value >= pow_10_ui4) { + D_COUT("\n Range:[10000000, 16777216] length:8"); + return TPrint8Decimals(cursor, ToIUC(value), lut); + } + Print7: + D_COUT("\n Range:[1048576, 9999999] length:7"); + nil_ptr = cursor + delta + 7; + if (nil_ptr >= stop) return nullptr; + IUB pow_10_ui2 = 10000; + IUC value_ui4 = ToIUC(value); + IUB digits6and5 = value_ui4 / pow_10_ui2, digits2and1 = value_ui4 - pow_10_ui2 * digits6and5; - pow_10_ui2 = 100; - IUB digit7 = digits6and5 / pow_10_ui2, + pow_10_ui2 = 100; + IUB digit7 = digits6and5 / pow_10_ui2, digits4and3 = digits2and1 / pow_10_ui2; - digits6and5 -= pow_10_ui2 * digit7; - digits2and1 -= pow_10_ui2 * digits4and3; - TSPrintDecimal(cursor, (CHT)(digit7)); - PrintCharPair(cursor + 1, lut[digits6and5]); - PrintCharPair(cursor + 3, lut[digits4and3]); - PrintCharPair(cursor + 5, lut[digits2and1]); - return TPrintNil(nil_ptr); - } else { - IUC comparator = 100000000; // 10^8 - IU msd = - (value >= (~(IUC)0)) ? value / comparator : ToIUC(value) / comparator; - IUC lsd = (IUC)(value - comparator * msd), middle_sd; - if (msd >= comparator) { - delta = 16; - value = msd / comparator; - middle_sd = ToIUC(msd - value * comparator); - D_COUT("\n Printing " << value << '_' << middle_sd << '_' << lsd); - } else { - value = msd; - middle_sd = 0; - delta = 8; - D_COUT("\n Printing " << value << '_' << lsd); + digits6and5 -= pow_10_ui2 * digit7; + digits2and1 -= pow_10_ui2 * digits4and3; + TSPrintDecimal(cursor, (CHT)(digit7)); + PrintCharPair(cursor + 1, lut[digits6and5]); + PrintCharPair(cursor + 3, lut[digits4and3]); + PrintCharPair(cursor + 5, lut[digits2and1]); + return TPrintNil(nil_ptr); } - if (value == 0) { - D_COUT("\n Length:8"); - TPrint8or16Decimals(cursor, lsd, lut, middle_sd, delta); - return TPrintNil(cursor + 8); - } else if (value < 10) { - D_COUT("\n Length:9"); - TPrint8or16Decimals(cursor + 1, lsd, lut, middle_sd, delta); - goto Print1; - } else if (value < 100) { - D_COUT("\n Length:10"); - TPrint8or16Decimals(cursor + 2, lsd, lut, middle_sd, delta); - goto Print2; - } else if ((value >> 10) == 0) { - pow_10_ui2 = 1000; - if (value >= pow_10_ui2) { - D_COUT("\n Length:12B"); + else { + IUC comparator = 100000000; // 10^8 + IU msd = + (value >= (~(IUC)0)) ? value / comparator : ToIUC(value) / comparator; + IUC lsd = (IUC)(value - comparator * msd), middle_sd; + if (msd >= comparator) { + delta = 16; + value = msd / comparator; + middle_sd = ToIUC(msd - value * comparator); + D_COUT("\n Printing " << value << '_' << middle_sd << '_' << lsd); + } + else { + value = msd; + middle_sd = 0; + delta = 8; + D_COUT("\n Printing " << value << '_' << lsd); + } + if (value == 0) { + D_COUT("\n Length:8"); + TPrint8or16Decimals(cursor, lsd, lut, middle_sd, delta); + return TPrintNil(cursor + 8); + } + else if (value < 10) { + D_COUT("\n Length:9"); + TPrint8or16Decimals(cursor + 1, lsd, lut, middle_sd, delta); + goto Print1; + } + else if (value < 100) { + D_COUT("\n Length:10"); + TPrint8or16Decimals(cursor + 2, lsd, lut, middle_sd, delta); + goto Print2; + } + else if ((value >> 10) == 0) { + pow_10_ui2 = 1000; + if (value >= pow_10_ui2) { + D_COUT("\n Length:12B"); + TPrint8or16Decimals(cursor + 4, lsd, lut, middle_sd, delta); + goto Print4B; + } + D_COUT("\n Length:11"); + TPrint8or16Decimals(cursor + 3, lsd, lut, middle_sd, delta); + goto Print3; + } + else if ((value >> 14) == 0) { + pow_10_ui2 = 10000; + if (value >= pow_10_ui2) { + D_COUT("\n Length:13B"); + TPrint8or16Decimals(cursor + 5, lsd, lut, middle_sd, delta); + goto Print5B; + } + D_COUT("\n Length:12"); TPrint8or16Decimals(cursor + 4, lsd, lut, middle_sd, delta); - goto Print4B; + goto Print4; } - D_COUT("\n Length:11"); - TPrint8or16Decimals(cursor + 3, lsd, lut, middle_sd, delta); - goto Print3; - } else if ((value >> 14) == 0) { - pow_10_ui2 = 10000; - if (value >= pow_10_ui2) { - D_COUT("\n Length:13B"); + else if ((value >> 17) == 0) { + pow_10_ui4 = 100000; + if (value >= pow_10_ui4) { + D_COUT("\n Length:14B"); + TPrint8or16Decimals(cursor + 6, lsd, lut, middle_sd, delta); + goto Print6B; + } + D_COUT("\n Length:13"); TPrint8or16Decimals(cursor + 5, lsd, lut, middle_sd, delta); - goto Print5B; + goto Print5; } - D_COUT("\n Length:12"); - TPrint8or16Decimals(cursor + 4, lsd, lut, middle_sd, delta); - goto Print4; - } else if ((value >> 17) == 0) { - pow_10_ui4 = 100000; - if (value >= pow_10_ui4) { - D_COUT("\n Length:14B"); + else if ((value >> 20) == 0) { + pow_10_ui4 = 1000000; + if (value >= pow_10_ui4) { + D_COUT("\n Length:15B"); + TPrint8or16Decimals(cursor + 7, lsd, lut, middle_sd, delta); + goto Print7B; + } + D_COUT("\n Length:14"); TPrint8or16Decimals(cursor + 6, lsd, lut, middle_sd, delta); - goto Print6B; + goto Print6; } - D_COUT("\n Length:13"); - TPrint8or16Decimals(cursor + 5, lsd, lut, middle_sd, delta); - goto Print5; - } else if ((value >> 20) == 0) { - pow_10_ui4 = 1000000; - if (value >= pow_10_ui4) { - D_COUT("\n Length:15B"); + else { + comparator = 10000000; + if (value >= comparator) { + D_COUT("\n Length:16"); + TPrint8Decimals(cursor, ToIUC(value), lut); + TPrint8Decimals(cursor + 8, lsd, lut); + return TPrintNil(cursor + 16); + } + D_COUT("\n Length:15"); TPrint8or16Decimals(cursor + 7, lsd, lut, middle_sd, delta); - goto Print7B; - } - D_COUT("\n Length:14"); - TPrint8or16Decimals(cursor + 6, lsd, lut, middle_sd, delta); - goto Print6; - } else { - comparator = 10000000; - if (value >= comparator) { - D_COUT("\n Length:16"); - TPrint8Decimals(cursor, ToIUC(value), lut); - TPrint8Decimals(cursor + 8, lsd, lut); - return TPrintNil(cursor + 16); + goto Print7; } - D_COUT("\n Length:15"); - TPrint8or16Decimals(cursor + 7, lsd, lut, middle_sd, delta); - goto Print7; } } + return nullptr; //< Unreachable. } - return nullptr; //< Unreachable. -} -template -inline CHT* TSPrintUnsigned(CHT* socket, ISW size, IU value) { - return TSPrintUnsigned(socket, socket + size - 1, value); -} + template + inline CHT* TSPrintUnsigned(CHT* socket, ISW size, IU value) { + return TSPrintUnsigned(socket, socket + size - 1, value); + } -template -inline CHT* TSPrint(CHT* start, CHT* stop, IUD value) { - return TSPrintUnsigned(start, stop, value); -} + template + inline CHT* TSPrint(CHT* start, CHT* stop, IUD value) { + return TSPrintUnsigned(start, stop, value); + } -template -inline CHT* TSPrint(CHT* start, ISW size, IUD value) { - return TSPrintUnsigned(start, size, value); -} + template + inline CHT* TSPrint(CHT* start, ISW size, IUD value) { + return TSPrintUnsigned(start, size, value); + } #if CPU_SIZE < 64 -template -inline CHT* TSPrint(CHT* start, CHT* stop, IUC value) { - return TSPrintUnsigned(start, stop, value); -} - -template -inline CHT* TSPrint(CHT* start, ISW size, IUC value) { - return TSPrintUnsigned(start, size, value); -} + template + inline CHT* TSPrint(CHT* start, CHT* stop, IUC value) { + return TSPrintUnsigned(start, stop, value); + } + + template + inline CHT* TSPrint(CHT* start, ISW size, IUC value) { + return TSPrintUnsigned(start, size, value); + } #else -template -inline CHT* TSPrint(CHT* start, CHT* stop, IUC value) { - return TSPrint(start, stop, (IUD)value); -} - -template -inline CHT* TSPrint(CHT* start, ISW size, IUC value) { - return TSPrint(start, size, (IUD)value); -} + template + inline CHT* TSPrint(CHT* start, CHT* stop, IUC value) { + return TSPrint(start, stop, (IUD)value); + } + + template + inline CHT* TSPrint(CHT* start, ISW size, IUC value) { + return TSPrint(start, size, (IUD)value); + } #endif -/* Writes the give value to the given socket as an ASCII string. -@return Nil upon socket overflow and a pointer to the nil-term CHT upon -success. -@param utf The text formatter to utf to. -@param value The value to write. */ -template -inline CHT* TSPrintSigned(CHT* start, CHT* stop, IS value) { - if (value >= 0) { - return TSPrintUnsigned(start, stop, (IU)value); + /* Writes the give value to the given socket as an ASCII string. + @return Nil upon socket overflow and a pointer to the nil-term CHT upon + success. + @param utf The text formatter to utf to. + @param value The value to write. */ + template + inline CHT* TSPrintSigned(CHT* start, CHT* stop, IS value) { + if (value >= 0) { + return TSPrintUnsigned(start, stop, (IU)value); + } + *start++ = '-'; + return TSPrintUnsigned(start, stop, (IU)(-(IS)value)); + } + + /* Writes the give value to the given socket as an ASCII string. + @return Nil upon socket overflow and a pointer to the nil-term CHT upon + success. + @param utf The text formatter to utf to. + @param value The value to write. */ + template + inline CHT* TSPrintSigned(CHT* start, ISW size, IS value) { + return TSPrintSigned(start, start + size - 1, value); + } + + template + inline CHT* TSPrint(CHT* start, CHT* stop, ISD value) { + return TSPrintSigned(start, stop, value); + } + template + inline CHT* TSPrint(CHT* start, ISW size, ISD value) { + return TSPrintSigned(start, size, value); } - *start++ = '-'; - return TSPrintUnsigned(start, stop, (IU)(-(IS)value)); -} - -/* Writes the give value to the given socket as an ASCII string. -@return Nil upon socket overflow and a pointer to the nil-term CHT upon -success. -@param utf The text formatter to utf to. -@param value The value to write. */ -template -inline CHT* TSPrintSigned(CHT* start, ISW size, IS value) { - return TSPrintSigned(start, start + size - 1, value); -} - -template -inline CHT* TSPrint(CHT* start, CHT* stop, ISD value) { - return TSPrintSigned(start, stop, value); -} -template -inline CHT* TSPrint(CHT* start, ISW size, ISD value) { - return TSPrintSigned(start, size, value); -} #if CPU_SIZE < 64 -template -inline CHT* TSPrint(CHT* start, CHT* stop, ISC value) { - return TSPrintSigned(start, stop, value); -} -template -inline CHT* TSPrint(CHT* start, ISW size, ISC value) { - return TSPrintSigned(start, size, value); -} + template + inline CHT* TSPrint(CHT* start, CHT* stop, ISC value) { + return TSPrintSigned(start, stop, value); + } + template + inline CHT* TSPrint(CHT* start, ISW size, ISC value) { + return TSPrintSigned(start, size, value); + } #else -template -inline CHT* TSPrint(CHT* start, CHT* stop, ISC value) { - return TSPrint(start, stop, (ISD)value); -} -template -inline CHT* TSPrint(CHT* start, ISW size, ISC value) { - return TSPrint(start, size, (ISD)value); -} + template + inline CHT* TSPrint(CHT* start, CHT* stop, ISC value) { + return TSPrint(start, stop, (ISD)value); + } + template + inline CHT* TSPrint(CHT* start, ISW size, ISC value) { + return TSPrint(start, size, (ISD)value); + } #endif } //< namespace _ #endif @@ -500,509 +518,525 @@ inline CHT* TSPrint(CHT* start, ISW size, ISC value) { namespace _ { -inline void FloatBytes(FPC value, CHA& byte_0, CHA& byte_1, CHA& byte_2, - CHA& byte_3) { - IUC ui_value = *TPtr(&value); - byte_0 = (CHA)(ui_value); - byte_1 = (CHA)(ui_value >> 8); - byte_2 = (CHA)(ui_value >> 16); - byte_3 = (CHA)(ui_value >> 24); -} - -inline void FloatBytes(FPD value, CHA& byte_0, CHA& byte_1, CHA& byte_2, - CHA& byte_3, CHA& byte_4, CHA& byte_5, CHA& byte_6, - CHA& byte_7) { - IUD ui_value = *TPtr(&value); - byte_0 = (CHA)(ui_value); - byte_1 = (CHA)(ui_value >> 8); - byte_2 = (CHA)(ui_value >> 16); - byte_3 = (CHA)(ui_value >> 24); - byte_4 = (CHA)(ui_value >> 32); - byte_5 = (CHA)(ui_value >> 40); - byte_6 = (CHA)(ui_value >> 48); - byte_7 = (CHA)(ui_value >> 56); -} - -template -CHT* TPrint3(CHT* string, CHT* stop, CHT a, CHT b, CHT c) { - if (!string || string + 3 >= stop) return nullptr; - *string++ = a; - *string++ = b; - *string++ = c; - return string; -} - -/* Masks off the given bits starting at b0. */ -template -IS TMiddleBits(IS value) { - // The goal is to not allow for undefined shifting behavior and not pay for - // the error checking. - // b15 ---vv--- b8 - // Example: TMiddleBits (0xff00) - // Expecting 0xff - // right_shift_count = 32 - 16 = 16 - enum { - cSize = sizeof(IS) * 8, - cMSbNatural = (cMSb_ < 0) ? 0 : cMSb_, - cLSbLNatural = (cLSb_ < 0) ? 0 : cLSb_, - cRightShiftTemp1 = cSize - cMSbNatural + 1, - cRightShiftTemp2 = (cRightShiftTemp1 >= cSize) ? 0 : cRightShiftTemp1, - cLeftShift = (cRightShiftTemp2 < cLSb_) ? 0 : cRightShiftTemp2, - cRightShift = (cRightShiftTemp2 < cLSb_) ? 0 : cRightShiftTemp2, - }; - return (value << cRightShift) >> cLeftShift; -} - -/* Searches for the highest MSb asserted. -@return -1 */ -template -ISC TMSbAssertedReverse(IU value) { - for (ISC i = sizeof(IU) * 8 - 1; i > 0; --i) - if ((value >> i) != 0) return i; - return -1; -} - -/* A decimal number in floating-point format. -To use this class the sizeof (Float) must equal the sizeof (IU) and sizeof -(IS). -*/ -template -class TBinary { - IU f; - IS e; - - public: - enum { - cSizeMax = 8, - cSize = sizeof(Float) >= cSizeMax ? 0 : sizeof(Float), - cSizeBits = cSize * 8, - cMSb = cSizeBits - 1, - cStringLengthMax = 24, - cExponentSizeBits = - (sizeof(Float) == 2) - ? 5 - : (sizeof(Float) == 4) ? 8 : (sizeof(Float) == 8) ? 11 : 15, - cCoefficientSize = cSizeBits - cExponentSizeBits - 1, - cMantissaSize = cSizeBits - cExponentSizeBits - 1, - cExponentMaskUnshifted = - (sizeof(cSize) == 2) - ? 0xf - : (sizeof(cSize) == 4) ? 0x7f : (sizeof(cSize) == 8) ? 0x3FF : 0, - cExponentBias = cExponentMaskUnshifted + cCoefficientSize, - cExponentMin = -cExponentBias, - }; - - // Constructs an uninitialized floating-point number_. - TBinary() : f(0), e(0) {} + inline void FloatBytes(FPC value, CHA& byte_0, CHA& byte_1, CHA& byte_2, + CHA& byte_3) { + IUC ui_value = *TPtr(&value); + byte_0 = (CHA)(ui_value); + byte_1 = (CHA)(ui_value >> 8); + byte_2 = (CHA)(ui_value >> 16); + byte_3 = (CHA)(ui_value >> 24); + } - inline static IU Coefficient(IU decimal) { - return (decimal << (cExponentSizeBits + 1)) >> (cExponentSizeBits + 1); + inline void FloatBytes(FPD value, CHA& byte_0, CHA& byte_1, CHA& byte_2, + CHA& byte_3, CHA& byte_4, CHA& byte_5, CHA& byte_6, + CHA& byte_7) { + IUD ui_value = *TPtr(&value); + byte_0 = (CHA)(ui_value); + byte_1 = (CHA)(ui_value >> 8); + byte_2 = (CHA)(ui_value >> 16); + byte_3 = (CHA)(ui_value >> 24); + byte_4 = (CHA)(ui_value >> 32); + byte_5 = (CHA)(ui_value >> 40); + byte_6 = (CHA)(ui_value >> 48); + byte_7 = (CHA)(ui_value >> 56); } - // Converts a Float to a TBinary - TBinary(Float value) { - IU ui = *TPtr(&value); - - IU biased_e = TMiddleBits(ui); - IU coefficient = Coefficient(ui); - if (biased_e != 0) { - f = coefficient + (((IU)1) << cExponentSizeBits); - e = biased_e - cExponentBias; - } else { - f = coefficient; - e = cExponentMin + 1; - } + template + CHT* TPrint3(CHT* string, CHT* stop, CHT a, CHT b, CHT c) { + if (!string || string + 3 >= stop) return nullptr; + *string++ = a; + *string++ = b; + *string++ = c; + return string; } - TBinary(IU f, IS e) : f(f), e(e) {} + /* Masks off the given bits starting at b0. */ + template + IS TMiddleBits(IS value) { + // The goal is to not allow for undefined shifting behavior and not pay for + // the error checking. + // b15 ---vv--- b8 + // Example: TMiddleBits (0xff00) + // Expecting 0xff + // right_shift_count = 32 - 16 = 16 + enum { + cSize = sizeof(IS) * 8, + cMSbNatural = (cMSb_ < 0) ? 0 : cMSb_, + cLSbLNatural = (cLSb_ < 0) ? 0 : cLSb_, + cRightShiftTemp1 = cSize - cMSbNatural + 1, + cRightShiftTemp2 = (cRightShiftTemp1 >= cSize) ? 0 : cRightShiftTemp1, + cLeftShift = (cRightShiftTemp2 < cLSb_) ? 0 : cRightShiftTemp2, + cRightShift = (cRightShiftTemp2 < cLSb_) ? 0 : cRightShiftTemp2, + }; + return (value << cRightShift) >> cLeftShift; + } - inline static IU Exponent(IU decimal) { - return (decimal << (cExponentSizeBits + 1)) >> (cExponentSizeBits + 1); + /* Searches for the highest MSb asserted. + @return -1 */ + template + ISC TMSbAssertedReverse(IU value) { + for (ISC i = sizeof(IU) * 8 - 1; i > 0; --i) + if ((value >> i) != 0) return i; + return -1; } - template - static CHT* Print(CHT* socket, CHT* stop, Float value) { - // Not handling NaN and inf - - if (IsNaN(value)) { - if (stop - socket < 4) return nullptr; - socket[0] = 'N'; - socket[1] = 'a'; - socket[2] = 'N'; - socket[3] = 0; - return socket + 4; + /* A decimal number in floating-point format. + To use this class the sizeof (Float) must equal the sizeof (IU) and sizeof + (IS). + */ + template + class TBinary { + IU f; + IS e; + + public: + enum { + cSizeMax = 8, + cSize = sizeof(Float) >= cSizeMax ? 0 : sizeof(Float), + cSizeBits = cSize * 8, + cMSb = cSizeBits - 1, + cStringLengthMax = 24, + cExponentSizeBits = + (sizeof(Float) == 2) + ? 5 + : (sizeof(Float) == 4) ? 8 : (sizeof(Float) == 8) ? 11 : 15, + cCoefficientSize = cSizeBits - cExponentSizeBits - 1, + cMantissaSize = cSizeBits - cExponentSizeBits - 1, + cExponentMaskUnshifted = + (sizeof(cSize) == 2) + ? 0xf + : (sizeof(cSize) == 4) ? 0x7f : (sizeof(cSize) == 8) ? 0x3FF : 0, + cExponentBias = cExponentMaskUnshifted + cCoefficientSize, + cExponentMin = -cExponentBias, + }; + + // Constructs an uninitialized floating-point number_. + TBinary() : f(0), e(0) {} + + inline static IU Coefficient(IU decimal) { + return (decimal << (cExponentSizeBits + 1)) >> (cExponentSizeBits + 1); } - if (IsInfinite(value)) { - if (stop - socket < 4) return nullptr; - IU f = *TPtr(&value); - socket[0] = (f >> (sizeof(IU) * 8 - 1)) ? '-' : '+'; - socket[1] = 'i'; - socket[2] = 'n'; - socket[3] = 'f'; - socket[4] = 0; - return socket + 5; + + // Converts a Float to a TBinary + TBinary(Float value) { + IU ui = *TPtr(&value); + + IU biased_e = TMiddleBits(ui); + IU coefficient = Coefficient(ui); + if (biased_e != 0) { + f = coefficient + (((IU)1) << cExponentSizeBits); + e = biased_e - cExponentBias; + } + else { + f = coefficient; + e = cExponentMin + 1; + } } - if (value == 0) { - return TPrint3(socket, stop, (CHT)'0', (CHT)'.', (CHT)'0'); + TBinary(IU f, IS e) : f(f), e(e) {} + + inline static IU Exponent(IU decimal) { + return (decimal << (cExponentSizeBits + 1)) >> (cExponentSizeBits + 1); } - if (value < 0) { - *socket++ = '-'; - value = -value; + + template + static CHT* Print(CHT* socket, CHT* stop, Float value) { + // Not handling NaN and inf + + if (IsNaN(value)) { + if (stop - socket < 4) return nullptr; + socket[0] = 'N'; + socket[1] = 'a'; + socket[2] = 'N'; + socket[3] = 0; + return socket + 4; + } + if (IsInfinite(value)) { + if (stop - socket < 4) return nullptr; + IU f = *TPtr(&value); + socket[0] = (f >> (sizeof(IU) * 8 - 1)) ? '-' : '+'; + socket[1] = 'i'; + socket[2] = 'n'; + socket[3] = 'f'; + socket[4] = 0; + return socket + 5; + } + + if (value == 0) { + return TPrint3(socket, stop, (CHT)'0', (CHT)'.', (CHT)'0'); + } + if (value < 0) { + *socket++ = '-'; + value = -value; + } + IS k; + CHT* cursor = Print(socket, stop, value, k); + if (!cursor) return cursor; + return Standardize(socket, stop, cursor - socket, k); } - IS k; - CHT* cursor = Print(socket, stop, value, k); - if (!cursor) return cursor; - return Standardize(socket, stop, cursor - socket, k); - } - static TBinary IEEE754Pow10(IS e, IS& k) { - // IS k = static_cast(ceil((-61 - e) * - // 0.30102999566398114)) + static TBinary IEEE754Pow10(IS e, IS& k) { + // IS k = static_cast(ceil((-61 - e) * + // 0.30102999566398114)) - // + 374; dk must be positive to perform ceiling function on positive - // values. - Float scalar = sizeof(Float) == 8 ? 0.30102999566398114 : 0.301029995f, - dk = (-61 - e) * scalar + 347; - k = static_cast(dk); - if (k != dk) ++k; + // + 374; dk must be positive to perform ceiling function on positive + // values. + Float scalar = sizeof(Float) == 8 ? 0.30102999566398114 : 0.301029995f, + dk = (-61 - e) * scalar + 347; + k = static_cast(dk); + if (k != dk) ++k; - IS index = (k >> 3) + 1; + IS index = (k >> 3) + 1; - k = -(-((IS)348) + (index << 3)); - // decimal exponent no need lookup table. + k = -(-((IS)348) + (index << 3)); + // decimal exponent no need lookup table. - D_ASSERT(index < 87); + D_ASSERT(index < 87); - const IU* f_lut = Pow10IntegralLUT(); - const ISB* e_lut = TPtr(BinaryPow10Exponents()); - return TBinary(f_lut[index], e_lut[index]); - } + const IU* f_lut = Pow10IntegralLUT(); + const ISB* e_lut = TPtr(BinaryPow10Exponents()); + return TBinary(f_lut[index], e_lut[index]); + } - TBinary Minus(const TBinary& value) const { - D_ASSERT(e == value.e); - D_ASSERT(f >= value.f); - return TBinary(f - value.f, e); - } + TBinary Minus(const TBinary& value) const { + D_ASSERT(e == value.e); + D_ASSERT(f >= value.f); + return TBinary(f - value.f, e); + } #if D_THIS - static void PrintDebugInfo() { - D_COUT("\nkSize:" << cSize << " cSizeBits:" << cSizeBits << " cMSbIndex:" - << cMSb << " cStringLengthMax:" << cStringLengthMax - << "\nkExponentSizeBits:" << cExponentSizeBits - << " cCoefficientSize:" << cCoefficientSize - << " cMantissaSize:" << cMantissaSize - << "\nkExponentMaskUnshifted:" << cExponentMaskUnshifted - << " cExponentBias:" << cExponentBias - << " ExponentMin ():" << cExponentMin << "\n\n"); - } + static void PrintDebugInfo() { + D_COUT("\nkSize:" << cSize << " cSizeBits:" << cSizeBits << " cMSbIndex:" + << cMSb << " cStringLengthMax:" << cStringLengthMax + << "\nkExponentSizeBits:" << cExponentSizeBits + << " cCoefficientSize:" << cCoefficientSize + << " cMantissaSize:" << cMantissaSize + << "\nkExponentMaskUnshifted:" << cExponentMaskUnshifted + << " cExponentBias:" << cExponentBias + << " ExponentMin ():" << cExponentMin << "\n\n"); + } #endif - inline TBinary Multiply(IUB rhs_f, ISB rhs_e) const { - IUC p = IUC(f) * IUC(rhs_f); - IUB h = p >> 16; - IUB l = IUB(p); - if (l & (IUB(1) << 15)) // rounding - h++; - return TBinary(h, e + rhs_e + 16); - } + inline TBinary Multiply(IUB rhs_f, ISB rhs_e) const { + IUC p = IUC(f) * IUC(rhs_f); + IUB h = p >> 16; + IUB l = IUB(p); + if (l & (IUB(1) << 15)) // rounding + h++; + return TBinary(h, e + rhs_e + 16); + } - inline TBinary Multiply(IUC rhs_f, ISC rhs_e) const { - IUD p = IUD(f) * IUD(rhs_f); - IUC h = p >> 32; - IUC l = IUC(p); - if (l & (IUC(1) << 31)) // rounding - h++; - return TBinary(h, e + rhs_e + 32); - } + inline TBinary Multiply(IUC rhs_f, ISC rhs_e) const { + IUD p = IUD(f) * IUD(rhs_f); + IUC h = p >> 32; + IUC l = IUC(p); + if (l & (IUC(1) << 31)) // rounding + h++; + return TBinary(h, e + rhs_e + 32); + } - inline TBinary Multiply(IUD rhs_f, ISD rhs_e) const { + inline TBinary Multiply(IUD rhs_f, ISD rhs_e) const { #if USING_VISUAL_CPP_X64 - IUD h; - IUD l = _umul128(f, rhs_f, &h); - if (l & (IUD(1) << 63)) // rounding - h++; - return TBinary(h, e + rhs_e + 64); + IUD h; + IUD l = _umul128(f, rhs_f, &h); + if (l & (IUD(1) << 63)) // rounding + h++; + return TBinary(h, e + rhs_e + 64); #elif USING_GCC - IUE p = static_cast(f) * static_cast(rhs_f); - IUD h = p >> 64; - IUD l = static_cast(p); - if (l & (IUD(1) << 63)) // rounding - h++; - return TBinary(h, e + rhs_e + 64); + IUE p = static_cast(f) * static_cast(rhs_f); + IUD h = p >> 64; + IUD l = static_cast(p); + if (l & (IUD(1) << 63)) // rounding + h++; + return TBinary(h, e + rhs_e + 64); #else - const IUD M32 = 0xFFFFFFFF; - const IUD a = f >> 32; - const IUD b = f & M32; - const IUD c = rhs_f >> 32; - const IUD d = rhs_f & M32; - const IUD ac = a * c; - const IUD bc = b * c; - const IUD ad = a * d; - const IUD bd = b * d; - IUD tmp = (bd >> 32) + (ad & M32) + (bc & M32); - tmp += 1U << 31; /// mult_round - return TBinary(ac + (ad >> 32) + (bc >> 32) + (tmp >> 32), e + rhs_e + 64); + const IUD M32 = 0xFFFFFFFF; + const IUD a = f >> 32; + const IUD b = f & M32; + const IUD c = rhs_f >> 32; + const IUD d = rhs_f & M32; + const IUD ac = a * c; + const IUD bc = b * c; + const IUD ad = a * d; + const IUD bd = b * d; + IUD tmp = (bd >> 32) + (ad & M32) + (bc & M32); + tmp += 1U << 31; /// mult_round + return TBinary(ac + (ad >> 32) + (bc >> 32) + (tmp >> 32), e + rhs_e + 64); #endif - } + } - TBinary operator*(const TBinary& rhs) const { return Multiply(rhs.f, rhs.e); } + TBinary operator*(const TBinary& rhs) const { return Multiply(rhs.f, rhs.e); } - TBinary operator-(const TBinary& rhs) const { - D_ASSERT(e == rhs.e); - D_ASSERT(f >= rhs.f); - return TBinary(f - rhs.f, e); - } + TBinary operator-(const TBinary& rhs) const { + D_ASSERT(e == rhs.e); + D_ASSERT(f >= rhs.f); + return TBinary(f - rhs.f, e); + } - private: - static inline void Multiply(TBinary& result, TBinary& a, TBinary& b) {} + private: + static inline void Multiply(TBinary& result, TBinary& a, TBinary& b) {} - static constexpr ISW LUTCount() { - // @todo Figure out the LUT sizes for Half and Single precision FP - // numbers. - return (sizeof(Float) == 4) ? 83 : (sizeof(Float) == 8) ? 83 : 0; - } + static constexpr ISW LUTCount() { + // @todo Figure out the LUT sizes for Half and Single precision FP + // numbers. + return (sizeof(Float) == 4) ? 83 : (sizeof(Float) == 8) ? 83 : 0; + } - static const IU* Pow10IntegralLUT() { - const void* ptr = + static const IU* Pow10IntegralLUT() { + const void* ptr = (sizeof(IU) == 4) - ? Binary32Pow10IntegralPortions() - : (sizeof(IU) == 8) ? Binary64Pow10IntegralPortions() : nullptr; - return TPtr(ptr); - } + ? Binary32Pow10IntegralPortions() + : (sizeof(IU) == 8) ? Binary64Pow10IntegralPortions() : nullptr; + return TPtr(ptr); + } - static void AlignLUT(CHA* origin, ISW size) { - D_ASSERT(size); - ISW lut_count = LUTCount(); - if (size != ((100 + lut_count) * 2 + lut_count * 8)) return; - IUB* iub_ptr = TPtr(origin); + static void AlignLUT(CHA* origin, ISW size) { + D_ASSERT(size); + ISW lut_count = LUTCount(); + if (size != ((100 + lut_count) * 2 + lut_count * 8)) return; + IUB* iub_ptr = TPtr(origin); - for (CHA tens = '0'; tens <= '9'; ++tens) - for (ISN ones = '0'; ones <= '9'; ++ones) + for (CHA tens = '0'; tens <= '9'; ++tens) + for (ISN ones = '0'; ones <= '9'; ++ones) #if ENDIAN == LITTLE - *iub_ptr++ = (tens << 8) | ones; + * iub_ptr++ = (tens << 8) | ones; #else - *iub_ptr++ = (ones << 8) | tens; + * iub_ptr++ = (ones << 8) | tens; #endif - const IUB* e_lut = BinaryPow10Exponents(); - for (ISC i = 0; i < 87; ++i) *iub_ptr = e_lut[i]; + const IUB* e_lut = BinaryPow10Exponents(); + for (ISC i = 0; i < 87; ++i) *iub_ptr = e_lut[i]; - IUD* iud_ptr = TPtr(iub_ptr); - const IU* f_lut = Pow10IntegralLUT(); - for (ISC i = 0; i < 87; ++i) *iud_ptr = f_lut[i]; - } + IUD* iud_ptr = TPtr(iub_ptr); + const IU* f_lut = Pow10IntegralLUT(); + for (ISC i = 0; i < 87; ++i) *iud_ptr = f_lut[i]; + } - template - static CHT* Print(CHT* socket, CHT* stop, Float value, IS& k) { - TBinary v(value); - TBinary lower_estimate, upper_estimate; - v.NormalizedBoundaries(lower_estimate, upper_estimate); + template + static CHT* Print(CHT* socket, CHT* stop, Float value, IS& k) { + TBinary v(value); + TBinary lower_estimate, upper_estimate; + v.NormalizedBoundaries(lower_estimate, upper_estimate); - TBinary cmk = IEEE754Pow10(upper_estimate.e, k); + TBinary cmk = IEEE754Pow10(upper_estimate.e, k); - TBinary W = v.NormalizeBoundary() * cmk, // + TBinary W = v.NormalizeBoundary() * cmk, // w_plus = upper_estimate * cmk, // w_minus = lower_estimate * cmk; - w_minus.f++; - w_plus.f--; - return DigitGen(socket, stop, W, w_plus, w_plus.f - w_minus.f, k); - } + w_minus.f++; + w_plus.f--; + return DigitGen(socket, stop, W, w_plus, w_plus.f - w_minus.f, k); + } - TBinary NormalizeBoundary() const { - // IS msba = MSbAsserted(0); + TBinary NormalizeBoundary() const { + // IS msba = MSbAsserted(0); #if defined(_MSC_VER) && defined(_M_AMD64) - unsigned long index; //< This is Microsoft's fault. - _BitScanReverse64(&index, f); - unsigned long msb_minus_index = cMSb - index; - return TBinary(f << (cMSb - index), e - msb_minus_index); + unsigned long index; //< This is Microsoft's fault. + _BitScanReverse64(&index, f); + unsigned long msb_minus_index = cMSb - index; + return TBinary(f << (cMSb - index), e - msb_minus_index); #else - TBinary res = *this; - IU cDpHiddenBit = ((IU)1) << cMantissaSize; // 0x0010000000000000; - while (!(res.f & (kDpHiddenBit << 1))) { - res.f <<= 1; - --res.e; - } - res.f <<= (kDiySignificandSize - cCoefficientSize - 2); - res.e = res.e - (kDiySignificandSize - cCoefficientSize - 2); - return res; + TBinary res = *this; + IU cDpHiddenBit = ((IU)1) << cMantissaSize; // 0x0010000000000000; + while (!(res.f & (kDpHiddenBit << 1))) { + res.f <<= 1; + --res.e; + } + res.f <<= (kDiySignificandSize - cCoefficientSize - 2); + res.e = res.e - (kDiySignificandSize - cCoefficientSize - 2); + return res; #endif - } + } - // static const IU cDpExponentMask = 0x7FF0000000000000, - // cDpSignificandMask = 0x000FFFFFFFFFFFFF, + // static const IU cDpExponentMask = 0x7FF0000000000000, + // cDpSignificandMask = 0x000FFFFFFFFFFFFF, - // Normalizes the boundaries. - void NormalizedBoundaries(TBinary& m_minus, TBinary& m_plus) const { - IU l_f = f, //< Local copy of f. + // Normalizes the boundaries. + void NormalizedBoundaries(TBinary& m_minus, TBinary& m_plus) const { + IU l_f = f, //< Local copy of f. l_e = e; //< Local copy of e. - TBinary pl = TBinary((l_f << 1) + 1, ((IS)l_e) - 1).NormalizeBoundary(); - ISC cShiftCount = (cMantissaSize >= 8) ? 0 : cMantissaSize; - const IU cHiddenBit = ((IU)1) << cShiftCount; - TBinary mi = (f == cHiddenBit) ? TBinary((l_f << 2) - 1, e - 2) - : TBinary((l_f << 1) - 1, e - 1); - mi.f <<= mi.e - pl.e; - mi.e = pl.e; - m_plus = pl; - m_minus = mi; - } - - // Rounds the Grisu estimation closer to the inside of the squeeze. - static IUC Round(IUC lsd, IU delta, IU rest, IU ten_kappa, IU wp_w) { - while (rest < wp_w && (delta - rest) >= ten_kappa && - (rest + ten_kappa < wp_w || /// closer - (wp_w - rest) > (rest + ten_kappa - wp_w))) { - --lsd; - rest += ten_kappa; + TBinary pl = TBinary((l_f << 1) + 1, ((IS)l_e) - 1).NormalizeBoundary(); + ISC cShiftCount = (cMantissaSize >= 8) ? 0 : cMantissaSize; + const IU cHiddenBit = ((IU)1) << cShiftCount; + TBinary mi = (f == cHiddenBit) ? TBinary((l_f << 2) - 1, e - 2) + : TBinary((l_f << 1) - 1, e - 1); + mi.f <<= mi.e - pl.e; + mi.e = pl.e; + m_plus = pl; + m_minus = mi; } - return lsd; - } - static inline IUC Pow10(IUC p_1, ISC& kappa) { - IUC pow_10 = 10; - if (p_1 < pow_10) { - kappa = 1; - return pow_10; - } else if (p_1 < (pow_10 = 100)) { - kappa = 2; - return pow_10; - } else if ((p_1 >> 10) == 0) { - pow_10 = 1000; - if (p_1 >= pow_10) goto Kappa4; - kappa = 3; - return pow_10; - } else if (!(p_1 >> 13)) { - Kappa4: - pow_10 = 10000; - if (p_1 >= pow_10) goto Kappa5; - kappa = 4; - return pow_10; - } else if (!(p_1 >> 17)) { - Kappa5: - pow_10 = 100000; - if (p_1 >= pow_10) goto Kappa6; - kappa = 5; - return pow_10; - } else if (!(p_1 >> 20)) { - Kappa6: - pow_10 = 1000000; - if (p_1 >= pow_10) goto Kappa7; - kappa = 6; - return pow_10; - } else if (!(p_1 >> 24)) { - Kappa7: - pow_10 = 10000000; - if (p_1 >= pow_10) goto Kappa8; - kappa = 7; - return pow_10; - } else if (!(p_1 >> 27)) { - Kappa8: - pow_10 = 100000000; - if (p_1 >= pow_10) goto Kappa9; - kappa = 8; - pow_10 = pow_10; - } else { // if (!(p_1 >> 30)) { - Kappa9: - pow_10 = 1000000000; - kappa = 9; - return pow_10; + // Rounds the Grisu estimation closer to the inside of the squeeze. + static IUC Round(IUC lsd, IU delta, IU rest, IU ten_kappa, IU wp_w) { + while (rest < wp_w && (delta - rest) >= ten_kappa && + (rest + ten_kappa < wp_w || /// closer + (wp_w - rest) >(rest + ten_kappa - wp_w))) { + --lsd; + rest += ten_kappa; + } + return lsd; } - return 0; - } - static inline IUC Pow10(IUC p_1, ISD& kappa) { - IUC pow_10 = 10; - if (p_1 < pow_10) { - kappa = 1; - return pow_10; - } else if (p_1 < (pow_10 = 100)) { - kappa = 2; - return pow_10; - } else if ((p_1 >> 10) == 0) { - pow_10 = 1000; - if (p_1 >= pow_10) goto Kappa4; - kappa = 3; - return pow_10; - } else if (!(p_1 >> 13)) { - Kappa4: - pow_10 = 10000; - if (p_1 >= pow_10) goto Kappa5; - kappa = 4; - return pow_10; - } else if (!(p_1 >> 17)) { - Kappa5: - pow_10 = 100000; - if (p_1 >= pow_10) goto Kappa6; - kappa = 5; - return pow_10; - } else if (!(p_1 >> 20)) { - Kappa6: - pow_10 = 1000000; - if (p_1 >= pow_10) goto Kappa7; - kappa = 6; - return pow_10; - } else if (!(p_1 >> 24)) { - Kappa7: - pow_10 = 10000000; - if (p_1 >= pow_10) goto Kappa8; - kappa = 7; - return pow_10; - } else { // if (!(p_1 >> 27)) { - Kappa8: - pow_10 = 100000000; - kappa = 8; - pow_10 = pow_10; + static inline IUC Pow10(IUC p_1, ISC& kappa) { + IUC pow_10 = 10; + if (p_1 < pow_10) { + kappa = 1; + return pow_10; + } + else if (p_1 < (pow_10 = 100)) { + kappa = 2; + return pow_10; + } + else if ((p_1 >> 10) == 0) { + pow_10 = 1000; + if (p_1 >= pow_10) goto Kappa4; + kappa = 3; + return pow_10; + } + else if (!(p_1 >> 13)) { + Kappa4: + pow_10 = 10000; + if (p_1 >= pow_10) goto Kappa5; + kappa = 4; + return pow_10; + } + else if (!(p_1 >> 17)) { + Kappa5: + pow_10 = 100000; + if (p_1 >= pow_10) goto Kappa6; + kappa = 5; + return pow_10; + } + else if (!(p_1 >> 20)) { + Kappa6: + pow_10 = 1000000; + if (p_1 >= pow_10) goto Kappa7; + kappa = 6; + return pow_10; + } + else if (!(p_1 >> 24)) { + Kappa7: + pow_10 = 10000000; + if (p_1 >= pow_10) goto Kappa8; + kappa = 7; + return pow_10; + } + else if (!(p_1 >> 27)) { + Kappa8: + pow_10 = 100000000; + if (p_1 >= pow_10) goto Kappa9; + kappa = 8; + pow_10 = pow_10; + } + else { // if (!(p_1 >> 30)) { + Kappa9: + pow_10 = 1000000000; + kappa = 9; + return pow_10; + } + return 0; } - return 0; - } - /* Prints the integer portion of the floating-point number_. - @return Nil upon failure or a pointer to the nil-term CHT upon success. */ - template - static CHT* DigitGen(CHT* start, CHT* stop, const TBinary& w, - const TBinary& m_plus, IU delta, IS& k) { - TBinary one(((IU)1) << (-m_plus.e), m_plus.e), wp_w = m_plus.Minus(w); - IUC d, pow_10, p_1 = static_cast(m_plus.f >> -one.e); - IU p_2 = m_plus.f & (one.f - 1); - IS kappa; - pow_10 = Pow10(p_1, kappa); - const IU* f_lut = Pow10IntegralLUT(); - while (kappa > 0) { - IUC d; - d = p_1 / pow_10; - p_1 -= d * pow_10; - - if (start >= stop) return nullptr; - - if (d) start = TSPrintDecimal(start, d); - - --kappa; - IU tmp = (static_cast(p_1) << -one.e) + p_2; - - if (tmp <= delta) { - k += kappa; - IU pow_10_f = f_lut[kappa]; - d = Round(d, delta, tmp, pow_10_f << -one.e, wp_w.f); - return start; + static inline IUC Pow10(IUC p_1, ISD& kappa) { + IUC pow_10 = 10; + if (p_1 < pow_10) { + kappa = 1; + return pow_10; } + else if (p_1 < (pow_10 = 100)) { + kappa = 2; + return pow_10; + } + else if ((p_1 >> 10) == 0) { + pow_10 = 1000; + if (p_1 >= pow_10) goto Kappa4; + kappa = 3; + return pow_10; + } + else if (!(p_1 >> 13)) { + Kappa4: + pow_10 = 10000; + if (p_1 >= pow_10) goto Kappa5; + kappa = 4; + return pow_10; + } + else if (!(p_1 >> 17)) { + Kappa5: + pow_10 = 100000; + if (p_1 >= pow_10) goto Kappa6; + kappa = 5; + return pow_10; + } + else if (!(p_1 >> 20)) { + Kappa6: + pow_10 = 1000000; + if (p_1 >= pow_10) goto Kappa7; + kappa = 6; + return pow_10; + } + else if (!(p_1 >> 24)) { + Kappa7: + pow_10 = 10000000; + if (p_1 >= pow_10) goto Kappa8; + kappa = 7; + return pow_10; + } + else { // if (!(p_1 >> 27)) { + Kappa8: + pow_10 = 100000000; + kappa = 8; + pow_10 = pow_10; + } + return 0; } - for (;;) { // kappa = 0 - p_2 *= 10; - delta *= 10; - d = static_cast(p_2 >> -one.e); - if (start >= stop) return nullptr; - if (d) *start++ = '0' + d; - p_2 &= one.f - 1; - --kappa; - if (p_2 < delta) { - k += kappa; - IU pow_10_f = f_lut[-kappa]; - d = Round(d, delta, p_2, one.f, wp_w.f * pow_10_f); - return start; + /* Prints the integer portion of the floating-point number_. + @return Nil upon failure or a pointer to the nil-term CHT upon success. */ + template + static CHT* DigitGen(CHT* start, CHT* stop, const TBinary& w, + const TBinary& m_plus, IU delta, IS& k) { + TBinary one(((IU)1) << (-m_plus.e), m_plus.e), wp_w = m_plus.Minus(w); + IUC d, pow_10, p_1 = static_cast(m_plus.f >> -one.e); + IU p_2 = m_plus.f & (one.f - 1); + IS kappa; + pow_10 = Pow10(p_1, kappa); + const IU* f_lut = Pow10IntegralLUT(); + while (kappa > 0) { + IUC d; + d = p_1 / pow_10; + p_1 -= d * pow_10; + + if (start >= stop) return nullptr; + + if (d) start = TSPrintDecimal(start, d); + + --kappa; + IU tmp = (static_cast(p_1) << -one.e) + p_2; + + if (tmp <= delta) { + k += kappa; + IU pow_10_f = f_lut[kappa]; + d = Round(d, delta, tmp, pow_10_f << -one.e, wp_w.f); + return start; + } + } + + for (;;) { // kappa = 0 + p_2 *= 10; + delta *= 10; + d = static_cast(p_2 >> -one.e); + if (start >= stop) return nullptr; + if (d) *start++ = '0' + d; + p_2 &= one.f - 1; + --kappa; + if (p_2 < delta) { + k += kappa; + IU pow_10_f = f_lut[-kappa]; + d = Round(d, delta, p_2, one.f, wp_w.f * pow_10_f); + return start; + } } - } - switch (kappa) { // Load integer pow_10 from the i-cache. + switch (kappa) { // Load integer pow_10 from the i-cache. case 1: d = p_1; p_1 = 0; @@ -1034,97 +1068,100 @@ class TBinary { case 10: pow_10 = 1000000000; return start; + } + return start; } - return start; - } - /* Shifts the given string up by given char_count. */ + /* Shifts the given string up by given char_count. */ + template + static void ShiftUp(CHT* start, ISW char_count) { + CHT* stop = start + char_count; + while (char_count) *stop++ = *start++; + } + + /* Converts the Grisu2 output to a standardized/easier-to-read format. */ + template + static CHT* Standardize(CHT* start, CHT* stop, ISW length, IS k) { + const ISW kk = length + k; // 10^(kk-1) <= v < 10^kk + CHT* nil_term_char; + if (length <= kk && kk <= 21) { // 1234e7 -> 12340000000 + for (ISW i = length; i < kk; i++) start[i] = '0'; + start[kk] = '.'; + start[kk + 1] = '0'; + nil_term_char = &start[kk + 2]; + *nil_term_char = NIL; + return nil_term_char; + } + else if (0 < kk && kk <= 21) { // 1234e-2 -> 12.34 + ShiftUp(&start[kk + 1], length - kk); + start[kk] = '.'; + nil_term_char = &start[length + 1]; + *nil_term_char = NIL; + return nil_term_char; + } + else if (-6 < kk && kk <= 0) { // 1234e-6 -> 0.001234 + const ISW offset = 2 - kk; + ShiftUp(&start[offset], length); + start[0] = '0'; + start[1] = '.'; + for (ISW i = 2; i < offset; i++) start[i] = '0'; + nil_term_char = &start[length + offset]; + *nil_term_char = 0; + return nil_term_char; + } + else if (length == 1) { + // 1e30 + start[1] = 'e'; + return TSPrintSigned(start + 2, stop, kk - 1); + } + // else 1234e30 -> 1.234e33 + ShiftUp(&start[2], length - 1); + + *(++start)++ = '.'; + *start++ = 'e'; + return TSPrintSigned(start + length + 2, stop, kk - 1); + } + }; + + using Binary32 = TBinary; + using Binary64 = TBinary; + template - static void ShiftUp(CHT* start, ISW char_count) { - CHT* stop = start + char_count; - while (char_count) *stop++ = *start++; + CHT* TSPrint(CHT* start, CHT* stop, FPC value) { + return TBinary::template Print(start, stop, value); } - - /* Converts the Grisu2 output to a standardized/easier-to-read format. */ template - static CHT* Standardize(CHT* start, CHT* stop, ISW length, IS k) { - const ISW kk = length + k; // 10^(kk-1) <= v < 10^kk - CHT* nil_term_char; - if (length <= kk && kk <= 21) { // 1234e7 -> 12340000000 - for (ISW i = length; i < kk; i++) start[i] = '0'; - start[kk] = '.'; - start[kk + 1] = '0'; - nil_term_char = &start[kk + 2]; - *nil_term_char = NIL; - return nil_term_char; - } else if (0 < kk && kk <= 21) { // 1234e-2 -> 12.34 - ShiftUp(&start[kk + 1], length - kk); - start[kk] = '.'; - nil_term_char = &start[length + 1]; - *nil_term_char = NIL; - return nil_term_char; - } else if (-6 < kk && kk <= 0) { // 1234e-6 -> 0.001234 - const ISW offset = 2 - kk; - ShiftUp(&start[offset], length); - start[0] = '0'; - start[1] = '.'; - for (ISW i = 2; i < offset; i++) start[i] = '0'; - nil_term_char = &start[length + offset]; - *nil_term_char = 0; - return nil_term_char; - } else if (length == 1) { - // 1e30 - start[1] = 'e'; - return TSPrintSigned(start + 2, stop, kk - 1); - } - // else 1234e30 -> 1.234e33 - ShiftUp(&start[2], length - 1); + CHT* TSPrint(CHT* start, ISW size, FPC value) { + return TSPrint(start, start + size - 1, value); + } - *(++start)++ = '.'; - *start++ = 'e'; - return TSPrintSigned(start + length + 2, stop, kk - 1); + template + CHT* TSPrint(CHT* start, CHT* stop, FPD value) { + return TBinary::template Print(start, stop, value); + } + template + CHT* TSPrint(CHT* start, ISW size, FPD value) { + return TSPrint(start, start + size - 1, value); } -}; - -using Binary32 = TBinary; -using Binary64 = TBinary; - -template -CHT* TSPrint(CHT* start, CHT* stop, FPC value) { - return TBinary::template Print(start, stop, value); -} -template -CHT* TSPrint(CHT* start, ISW size, FPC value) { - return TSPrint(start, start + size - 1, value); -} - -template -CHT* TSPrint(CHT* start, CHT* stop, FPD value) { - return TBinary::template Print(start, stop, value); -} -template -CHT* TSPrint(CHT* start, ISW size, FPD value) { - return TSPrint(start, start + size - 1, value); -} #if USING_FPC == YES_0 -inline CHB* SPrint(CHB* string, CHB* stop, FPC item) { - return TBinary::template Print(string, stop, item); -} + inline CHB* SPrint(CHB* string, CHB* stop, FPC item) { + return TBinary::template Print(string, stop, item); + } #endif #if USING_FPD == YES_0 -inline CHB* SPrint(CHB* string, CHB* stop, FPD item) { - return TBinary::template Print(string, stop, item); -} + inline CHB* SPrint(CHB* string, CHB* stop, FPD item) { + return TBinary::template Print(string, stop, item); + } #endif #if USING_FPC == YES_0 -inline CHC* SPrint(CHC* string, CHC* stop, FPC value) { - return TBinary::template Print(string, stop, value); -} + inline CHC* SPrint(CHC* string, CHC* stop, FPC value) { + return TBinary::template Print(string, stop, value); + } #endif #if USING_FPD == YES_0 -inline CHC* SPrint(CHC* string, CHC* stop, FPD value) { - return TBinary::template Print(string, stop, value); -} + inline CHC* SPrint(CHC* string, CHC* stop, FPD value) { + return TBinary::template Print(string, stop, value); + } #endif } //< namespace _ diff --git a/Slot.inl b/Slot.inl index 2b0e4a5..e28701a 100644 --- a/Slot.inl +++ b/Slot.inl @@ -132,12 +132,12 @@ BOL Slot::IsReadable() { return origin != stop; } ISW top_chunk = stop - stop; size -= top_chunk; - ArrayCopy (target, target_end, origin, top_chunk); - ArrayCopy (TPtr(target) + top_chunk, size, + RAMCopy (target, target_end, origin, top_chunk); + RAMCopy (TPtr(target) + top_chunk, size, origin); return origin + size; } - ArrayCopy (target, target_end, stop, size); + RAMCopy (target, target_end, stop, size); return origin + size; }*/ @@ -193,13 +193,13 @@ const Op* Slot::Read(const ISC* params, void** args) { case cNIL: return ReturnError(this, cErrorInvalidType); case cADR: //< _R_e_a_d__S_t_r_i_n_g_-_1_______________ - case cSTR: + case STR_: // Load buffered-type argument length and increment the // index. count = *param; ++param; - // std::cout << "\nReading CHA with max length " << count; + // StdOut() << "\nReading CHA with max length " << count; // Load next pointer and increment args. iua_ptr = TPtr(args[index]); diff --git a/Stack.hpp b/Stack.hpp index 38ed22b..f179ad4 100644 --- a/Stack.hpp +++ b/Stack.hpp @@ -52,14 +52,27 @@ struct TStack { /* Returns the first element in the Stack TMatrix. */ template -inline T* TStackStart(TStack* stack) { +inline const T* TStackStart(const TStack* stack) { return TPtr(TPtr(stack) + sizeof(TStack)); } +/* Returns the first element in the Stack TMatrix. */ +template +inline T* TStackStart(TStack* stack) { + return CPtr(TStackStart(CPtr>(stack))); +} + +/* Returns the first empty element of the stack. */ +template +inline const T* TStackTop(const TStack* stack) { + return TStackStart(stack) + stack->count; +} + /* Returns the first empty element of the stack. */ template inline T* TStackTop(TStack* stack) { - return &TStackStart(stack) + stack->count; + return CPtr(TStackStart(CPtr>(stack))) + + stack->count; } template @@ -69,14 +82,14 @@ inline IS TStackSizeOf(IS count) { /* Prints the given obj to the console. */ template -Printer& TStackPrint(Printer& o, TStack* stack) { +Printer& TStackPrint(Printer& o, const TStack* stack) { IS count_max = stack->count_max, count = stack->count; o << Linef("\n+---\n| TStack: size_bytes:" << TStackSizeOf(count_max) << " count_max: " << count_max << " count:" << count << Linef("\n+---"); - T* elements = TStackStart(stack); + const T* elements = TStackStart(stack); for (ISC i = 0; i < count; ++i) o << "\n| " << i << ".) " << elements[i]; if (count == 0) o << "\n| Empty"; #if D_THIS @@ -89,16 +102,16 @@ Printer& TStackPrint(Printer& o, TStack* stack) { /* Copies an ASCII Stack from the origin to the destination. */ template -inline CHA* TStackCopy(TStack* destination, TStack* source) { - return ArrayCopy(destination, TStackTop(destination), source, +inline CHA* TStackCopy(TStack* destination, const TStack* source) { + return RAMCopy(destination, TStackTop(destination), source, TStackTop(source)); } /* Copies an ASCII Stack from the origin to the destination. */ template inline CHA* TStackCopy(TStack* destination, IS destination_size, - TStack* source) { - return ArrayCopy(destination, destination_size, source, + const TStack* source) { + return RAMCopy(destination, destination_size, source, TStackTop(source)); } @@ -114,6 +127,12 @@ inline TStack* TStackPtr(IUW* buffer) { return TPtr>(buffer); } +// Utility to cast Autoject origin to TStack*. +template +inline const TStack* TStackPtr(const IUW* buffer) { + return TPtr>(buffer); +} + // Utility to cast Autoject origin to TStack*. template inline TStack* TStackPtr(Autoject* adj) { @@ -137,7 +156,7 @@ TStack* TStackClone(Autoject& adj, IS count_delta) { D_ASSERT(count_max >= 0); #if D_THIS D_COUT("\nAuto-growing Stack...\nBefore:"); - TStackPrint(COut().Star(), stack); + TStackPrint(StdOut(), stack); #endif IS count_max_new = count_max + count_delta; if (count_max_new < 0) return nullptr; @@ -155,11 +174,11 @@ TStack* TStackClone(Autoject& adj, IS count_delta) { "\nsize_new: " << size_new << "\nTStackStart(stack): " << Hexf(TStackStart(stack))); size_old -= sizeof(TStack); - ArrayCopy(TStackStart(stack_new), size_old, + RAMCopy(TStackStart(stack_new), size_old, TStackStart(stack), size_old); #if D_THIS D_COUT("\nResult:"); - TStackPrint(COut().Star(), stack_new); + TStackPrint(StdOut(), stack_new); #endif return stack_new; } @@ -192,18 +211,18 @@ constexpr DT TStackType() { return (TBitCode() << ATypeVTBit0) | (_STK << TBitCode()) | Type; } -/* RamFactoryStack function for the TStack. */ +/* RAMFactoryStack function for the TStack. */ template IUW* TStackFactoryStack(IUW* origin, ISW size_bytes) { if (size_bytes <= 0) return TPtr(TStackType()); - return RamFactoryStack(origin, size_bytes); + return RAMFactoryStack(origin, size_bytes); } -/* RamFactoryHeap function for the TStack. */ +/* RAMFactoryHeap function for the TStack. */ template IUW* TStackFactoryHeap(IUW* origin, ISW size_bytes) { if (size_bytes <= 0) return TPtr(TStackType()); - return RamFactoryHeap(origin, size_bytes); + return RAMFactoryHeap(origin, size_bytes); } /* Gets the size of a Stack with the given count_max. */ @@ -228,7 +247,7 @@ inline IS TStackSizeMin() { width. */ template inline IS TStackSizeMax() { - return (IS)((((~(IS)0) - WordLSbMask) - (IS)sizeof(TStack)) / + return (IS)((((~(IS)0) - ACPUAlignMask) - (IS)sizeof(TStack)) / (IS)sizeof(T)); } @@ -357,7 +376,7 @@ inline void TStackPushUnchecked(TStack* stack, T item, IS count) { @param stack The Ascii Object base poiner. @param item The item to push onto the obj. */ template -IS TStackInsert(TStack* stack, T item, IS index = STKPush) { +IS TStackInsert(TStack* stack, T item, IS index = PSH) { D_ASSERT(stack); IS count = stack->count, count_max = stack->count_max; @@ -376,7 +395,7 @@ IS TStackInsert(TStack* stack, T item, IS index = STKPush) { @param stack The Ascii Object base poiner. @param item The item to push onto the obj. */ template -IS TStackInsert(AArray& obj, T item, IS index = STKPush) { +IS TStackInsert(AArray& obj, T item, IS index = PSH) { auto stack = obj.OriginAs*>(); Insert: IS result = TStackInsert(stack, item, index); @@ -513,8 +532,8 @@ class AStack { AArray obj_; //< An Auto-Array. constexpr RAMFactory InitRamFactory() { - return sizeof(BUF) == 0 ? TRamFactory::StackHeap - : TRamFactory::StackStack; + return sizeof(BUF) == 0 ? TRAMFactory::StackHeap + : TRAMFactory::StackStack; } inline RAMFactory InitRamFactory(RAMFactory factory) { @@ -662,7 +681,7 @@ class AStack { } /* Prints this object to the given UTF. */ - inline void CPrint() { PrintTo<_::COut>(_::COut().Star()); } + inline void CPrint() { PrintTo<_::COut>(_::StdOut()); } /* Gets a reference to the given element index. */ inline T& operator[](IS index) { return Start()[index]; } @@ -739,7 +758,7 @@ IUW* TStackClone(Autoject& obj) { ISZ count = o->count; IUW* clone = TArrayNew>(count); ISW size_bytes = (ISW)TStackSizeOf(count); - if (!ArrayCopy(clone, count, origin, size_bytes)) return nullptr; + if (!RAMCopy(clone, count, origin, size_bytes)) return nullptr; TSizeSet(origin, count); return clone; } */ diff --git a/String.hpp b/String.hpp index a32cf06..ce783f3 100644 --- a/String.hpp +++ b/String.hpp @@ -12,12 +12,12 @@ one at . */ #define SCRIPT2_STRING_TEMPLATES #include "Array.hpp" #if SEAM >= SCRIPT2_STRING -#include "Stringf.hpp" +#include "Uniprinter.hpp" #include "Types.h" #if SEAM == SCRIPT2_STRING #include "_Debug.inl" #define D_COUT_STRING(string) \ - TStringPrint(COut().Star(), string) + TStringPrint(StdOut(), string) #else #include "_Release.inl" #define D_COUT_STRING(string) @@ -54,21 +54,21 @@ inline ISZ TSizeWords(TString* string) { } /* Gets the first character in the string. */ -template +template inline CHT* TSTRStart(TString* string) { return TPtr(string, sizeof(TString)); } -template +template inline const CHT* TSTRStart(const TString* string) { return TPtr(string, sizeof(TString)); } -template +template inline CHT* TSTRStart(IUW* origin) { return TSTRStart(TPtr>(origin)); } /* Searches for the stop of the string. */ -template +template inline CHT* TSTRStop(void* origin) { ISZ size = TPtr>(origin)->size; CHT* start = TSTRStart(TPtr>(origin)); @@ -76,13 +76,13 @@ inline CHT* TSTRStop(void* origin) { } /* Gets the stop char of the string. */ -template +template inline CHT* TSTRStop(void* origin, ISW size) { CHT* ptr = TPtr(TSTRStart(origin)); return ptr + size - 1; } -template +template inline CHT* TStringReset(TString* string) { CHT* start = TSTRStart(string); *start = 0; @@ -90,7 +90,7 @@ inline CHT* TStringReset(TString* string) { } /* Initializes an ASCII String. */ -template +template inline TString* TStringInit(TString* string, ISZ size) { if (!string || size < 1) return string; string->size = size; @@ -99,19 +99,19 @@ inline TString* TStringInit(TString* string, ISZ size) { } /* Initializes an ASCII String. */ -template +template inline CHT* TStringInit(IUW* obj, ISZ size) { return TStringInit(TPtr>(obj), size); } /* Prints this object to the given printer. */ -template -Printer& TStringPrint(Printer& o, TString* string) { +template +Printer& TStringPrint(Printer& o, const TString* string) { if (!string) return o; - CHT* start = TSTRStart(string); + const CHT* start = TSTRStart(string); ISZ size = string->size; - o << Linef("\n+---\n| TString size:" << size << Linef("\n+---\n| \""); + o << Linef("\n+---\n| TString() << ",IS" + << TSizef() << "> size:" << size << Linef("\n+---\n| \""); ISW column_count = AConsoleWidth; ISZ length = 0; CHL c = 0; @@ -130,17 +130,16 @@ Printer& TStringPrint(Printer& o, TString* string) { return o << "\"\n| length:" << TSTRLength(start) << Linef("\n+---"); } -template +template inline Printer& TStringPrint(Printer& o, Autoject autoject) { - return TStringPrint( - o, TPtr>(autoject.origin)); + return TStringPrint(o, TPtr>(autoject.origin)); } -template +template IUW* TStringClone(Autoject& obj) { - IUW* origin = obj.origin; // + IUW* origin = obj.origin; ISZ size = TSize(origin); - IUW* new_begin = TArrayNew>(size); + IUW* new_begin = TRAMFactoryNew>(size); D_COUT(" new size:" << TSize(new_begin)); TSPrinter new_utf(new_begin); CHT* start = TSTRStart(origin); @@ -151,43 +150,53 @@ IUW* TStringClone(Autoject& obj) { } /* Gets the size from the string at the given origin address. */ -template +template inline ISZ TStringSize(IUW* origin) { - return TPtr>(origin)->size; + return *TPtr(origin); } -template -BOL TStringGrow(Autoject& obj, TSPrinter& utf) { +template +BOL TStringGrow(Autoject& obj, TSPrinter& sprinter) { IUW* origin = obj.origin; - ISZ size = TStringSize(origin), new_size = size << 1, - new_size_bytes = TSizeBytes>(new_size); - if (!TCanGrow(new_size_bytes)) return false; + ISZ size = TStringSize(origin), // + new_size = size << 1; + #if SEAM == SCRIPT2_STRING + COut("\nsize: ").Star() << size << + "\nnew_size: " << new_size; + #endif + ISZ new_size_bytes = TSizeBytes>(new_size); + if (!TCanGrow(new_size_bytes)) + return false; size = new_size; D_COUT(" new_size:" << new_size << " new_size_bytes:" << new_size_bytes); - IUW* new_begin = TArrayNew>(obj.ram, size); + IUW* new_begin = TRAMFactoryNew>(obj.ram, size); if (!new_begin) return false; D_COUT(" new size:" << new_size_bytes); TSPrinter new_sprinter(TSTRStart(new_begin), size); CHT* start = TSTRStart(origin); new_sprinter << start; - utf.Set(new_sprinter); + sprinter.Set(new_sprinter); D_COUT("\nCopying \"" << start << "\" with result:\"" - << TSTRStart(new_begin) << '\"'); + << TSTRStart(new_begin) << '\"'); Delete(obj); obj.origin = new_begin; return true; } -template -void TStringSPrint(Autoject& obj, TSPrinter& sprinter, T item) { +template +void TStringPrint(Autoject& obj, TSPrinter& sprinter, T item) { CHT *start = sprinter.start, // *stop = sprinter.stop; - D_COUT("\ncount:" << stop - start << " start:0x" << Hexf(start) << " stop:0x" - << Hexf(stop)); + D_COUT("\ndelta_origin_start: " << TDelta<>(obj.origin, start) << + " delta_origin_stop: " << TDelta<>(obj.origin, stop) << + " delta_start_stop: " << TDelta<>(start, stop) << + "\nobj.Size() before: " << *TPtr(obj.origin) << + "\norigin_hex:0x" << Hexf(TPtr(obj.origin))); auto cursor = _::TSPrint(start, stop, item); + D_COUT("\nobj.Size() after : " << *TPtr(obj.origin)); if (!cursor) { *start = 0; //< Replace the delimiter so we can copy the string. do { @@ -246,33 +255,33 @@ Strings that use dynamic memory use the TC: AString> () << "Hello world!"; @endcode */ -template>> +template>> class AString { AArray obj_; //< AutoArray of CHT(s). - TSPrinter sprinter_; //< UTF for the string. + TSPrinter sprinter_; //< String Printer. public: static constexpr DTB Type() { - return CTypeVector(CTypeChar(), _ARY, CTypeSize()); + return CTypeVector(CTypeChar(), _ARY, CATypeSize()); } /* Constructs a String that auto-grows from stack to heap. @param factory RAMFactory to call when the String overflows. */ - AString() : obj_(cSize_, TRamFactory().Init()) { + AString() : obj_(Size_, TRAMFactory().Init()) { sprinter_.stop = TSTRStop(This()); Reset(); } /* Constructs a String and prints the given item. */ - AString(CHA item) : obj_(cSize_, TRamFactory().Init()) { + AString(CHA item) : obj_(Size_, TRAMFactory().Init()) { sprinter_.stop = TSTRStop(This()); Reset(); Print(item); } /* Constructs a String and prints the given item. */ - AString(const CHA* item) : obj_(cSize_, TRamFactory().Init()) { + AString(const CHA* item) : obj_(Size_, TRAMFactory().Init()) { sprinter_.stop = TSTRStop(This()); Reset(); Print(item); @@ -280,7 +289,7 @@ class AString { #if USING_UTF16 == YES_0 /* Constructs a String and prints the given item. */ - AString(const CHB* item) : obj_(cSize_, TRamFactory().Init()) { + AString(const CHB* item) : obj_(Size_, TRAMFactory().Init()) { sprinter_.stop = TSTRStop(This()); Reset(); Print(item); @@ -289,70 +298,70 @@ class AString { #if USING_UTF32 == YES_0 /* Constructs a String and prints the given item. */ - AString(CHC item) : obj_(cSize_, TRamFactory().Init()) { + AString(CHC item) : obj_(Size_, TRAMFactory().Init()) { sprinter_.stop = TSTRStop(This()); Reset(); Print(item); } #endif /* Constructs a String and prints the given item. */ - AString(const CHC* item) : obj_(cSize_, TRamFactory().Init()) { + AString(const CHC* item) : obj_(Size_, TRAMFactory().Init()) { sprinter_.stop = TSTRStop(This()); Reset(); Print(item); } /* Constructs a String and prints the given item. */ - AString(ISA item) : obj_(cSize_, TRamFactory().Init()) { + AString(ISA item) : obj_(Size_, TRAMFactory().Init()) { sprinter_.stop = TSTRStop(This()); Reset(); Print(item); } /* Constructs a String and prints the given item. */ - AString(IUA item) : obj_(cSize_, TRamFactory().Init()) { + AString(IUA item) : obj_(Size_, TRAMFactory().Init()) { sprinter_.stop = TSTRStop(This()); Reset(); Print(item); } /* Constructs a String and prints the given item. */ - AString(ISB item) : obj_(cSize_, TRamFactory().Init()) { + AString(ISB item) : obj_(Size_, TRAMFactory().Init()) { sprinter_.stop = TSTRStop(This()); Reset(); Print(item); } /* Constructs a String and prints the given item. */ - AString(IUB item) : obj_(cSize_, TRamFactory().Init()) { + AString(IUB item) : obj_(Size_, TRAMFactory().Init()) { sprinter_.stop = TSTRStop(This()); Reset(); Print(item); } /* Constructs a String and prints the given item. */ - AString(ISC item) : obj_(cSize_, TRamFactory().Init()) { + AString(ISC item) : obj_(Size_, TRAMFactory().Init()) { sprinter_.stop = TSTRStop(This()); Reset(); Print(item); } /* Constructs a String and prints the given item. */ - AString(IUC item) : obj_(cSize_, TRamFactory().Init()) { + AString(IUC item) : obj_(Size_, TRAMFactory().Init()) { sprinter_.stop = TSTRStop(This()); Reset(); Print(item); } /* Constructs a String and prints the given item. */ - AString(ISD item) : obj_(cSize_, TRamFactory().Init()) { + AString(ISD item) : obj_(Size_, TRAMFactory().Init()) { sprinter_.stop = TSTRStop(This()); Reset(); Print(item); } /* Constructs a String and prints the given item. */ - AString(IUD item) : obj_(cSize_, TRamFactory().Init()) { + AString(IUD item) : obj_(Size_, TRAMFactory().Init()) { sprinter_.stop = TSTRStop(This()); Reset(); Print(item); @@ -360,7 +369,7 @@ class AString { #if USING_FPC == YES_0 /* Constructs a String and prints the given item. */ - AString(FPC item) : obj_(cSize_, TRamFactory().Init()) { + AString(FPC item) : obj_(Size_, TRAMFactory().Init()) { sprinter_.stop = TSTRStop(This()); Reset(); Print(item); @@ -368,7 +377,7 @@ class AString { #endif #if USING_FPD == YES_0 /* Constructs a String and prints the given item. */ - AString(FPD item) : obj_(cSize_, TRamFactory().Init()) { + AString(FPD item) : obj_(Size_, TRAMFactory().Init()) { sprinter_.stop = TSTRStop(This()); Reset(); Print(item); @@ -376,14 +385,14 @@ class AString { #endif /* Constructs a String and prints the given item. */ - AString(Hexf item) : obj_(cSize_, TRamFactory().Init()) { + AString(Hexf item) : obj_(Size_, TRAMFactory().Init()) { sprinter_.stop = TSTRStop(This()); Reset(); Print(item); } /* Constructs a String and prints the given item. */ - AString(Binaryf item) : obj_(cSize_, TRamFactory().Init()) { + AString(Binaryf item) : obj_(Size_, TRAMFactory().Init()) { sprinter_.stop = TSTRStop(This()); Reset(); Print(item); @@ -468,14 +477,14 @@ class AString { inline AArray& Array() { return obj_; } /* Gets the obj of the Console obj. */ - inline Autoject& AJT() { return obj_.OBJ(); } + inline Autoject& AJT() { return obj_.AJT(); } /* Gets the obj.origin as a TString. */ inline TString* This() { return obj_.OriginAs*>(); } template inline AString& Print(T item) { - TStringSPrint(obj_.AJT(), sprinter_, item); + TStringPrint(obj_.AJT(), sprinter_, item); return *this; } @@ -485,60 +494,60 @@ class AString { return TStringPrint(o, This()); } - inline void CPrint() { PrintTo(COut().Star()); } + inline void CPrint() { PrintTo(StdOut()); } }; } //< namespace _ -template -inline _::AString& operator<<( - _::AString& obj, - _::AString& item) { - _::AString& result = obj.Print(item); +template +inline _::AString& operator<<( + _::AString& obj, + _::AString& item) { + _::AString& result = obj.Print(item); D_COUT_OBJ(obj); return obj; } -template -inline _::AString& operator<<( - _::AString& obj, const CHA* item) { - _::AString& result = obj.Print(item); +template +inline _::AString& operator<<( + _::AString& obj, const CHA* item) { + _::AString& result = obj.Print(item); D_COUT_OBJ(obj); return obj; } #if USING_UTF16 == YES_0 -template -inline _::AString& operator<<( - _::AString& obj, const CHB* item) { - _::AString& result = obj.Print(item); +template +inline _::AString& operator<<( + _::AString& obj, const CHB* item) { + _::AString& result = obj.Print(item); D_COUT_OBJ(obj); return obj; } #endif #if USING_UTF32 == YES_0 -template -inline _::AString& operator<<( - _::AString& obj, const CHC* item) { - _::AString& result = obj.Print(item); +template +inline _::AString& operator<<( + _::AString& obj, const CHC* item) { + _::AString& result = obj.Print(item); D_COUT_OBJ(obj); return obj; } -template -inline _::AString& operator<<( - _::AString& obj, CHC item) { - _::AString& result = obj.Print(item); +template +inline _::AString& operator<<( + _::AString& obj, CHC item) { + _::AString& result = obj.Print(item); D_COUT_OBJ(obj); return obj; } #endif -template -inline _::AString& operator<<( - _::AString& obj, CHA item) { - _::AString& result = obj.Print(item); +template +inline _::AString& operator<<( + _::AString& obj, CHA item) { + _::AString& result = obj.Print(item); D_COUT_OBJ(obj); return obj; } @@ -546,125 +555,125 @@ inline _::AString& operator<<( template inline _::AString& operator<<( _::AString& obj, CHB item) { - _::AString& result = obj.Print (item); + _::AString& result = obj.Print (item); D_COUT_OBJ (obj); return obj; }*/ -template -inline _::AString& operator<<( - _::AString& obj, IUA item) { - _::AString& result = obj.Print(item); +template +inline _::AString& operator<<( + _::AString& obj, IUA item) { + _::AString& result = obj.Print(item); D_COUT_OBJ(obj); return obj; } -template -inline _::AString& operator<<( - _::AString& obj, ISB item) { - _::AString& result = obj.Print(item); +template +inline _::AString& operator<<( + _::AString& obj, ISB item) { + _::AString& result = obj.Print(item); D_COUT_OBJ(obj); return obj; } -template -inline _::AString& operator<<( - _::AString& obj, IUB item) { - _::AString& result = obj.Print(item); +template +inline _::AString& operator<<( + _::AString& obj, IUB item) { + _::AString& result = obj.Print(item); D_COUT_OBJ(obj); return obj; } -template -inline _::AString& operator<<( - _::AString& obj, ISC item) { - _::AString& result = obj.Print(item); +template +inline _::AString& operator<<( + _::AString& obj, ISC item) { + _::AString& result = obj.Print(item); D_COUT_OBJ(obj); return obj; } -template -inline _::AString& operator<<( - _::AString& obj, IUC item) { - _::AString& result = obj.Print(item); +template +inline _::AString& operator<<( + _::AString& obj, IUC item) { + _::AString& result = obj.Print(item); D_COUT_OBJ(obj); return obj; } -template -inline _::AString& operator<<( - _::AString& obj, ISD item) { - _::AString& result = obj.Print(item); +template +inline _::AString& operator<<( + _::AString& obj, ISD item) { + _::AString& result = obj.Print(item); D_COUT_OBJ(obj); return obj; } -template -inline _::AString& operator<<( - _::AString& obj, IUD item) { - _::AString& result = obj.Print(item); +template +inline _::AString& operator<<( + _::AString& obj, IUD item) { + _::AString& result = obj.Print(item); D_COUT_OBJ(obj); return obj; } #if USING_FPC == YES_0 -template -inline _::AString& operator<<( - _::AString& obj, FPC item) { - _::AString& result = obj.Print(item); +template +inline _::AString& operator<<( + _::AString& obj, FPC item) { + _::AString& result = obj.Print(item); D_COUT_OBJ(obj); return obj; } #endif #if USING_FPD == YES_0 -template -inline _::AString& operator<<( - _::AString& obj, FPD item) { - _::AString& result = obj.Print(item); +template +inline _::AString& operator<<( + _::AString& obj, FPD item) { + _::AString& result = obj.Print(item); D_COUT_OBJ(obj); return obj; } #endif -template -inline _::AString& operator<<( - _::AString& obj, _::Hexf item) { +template +inline _::AString& operator<<( + _::AString& obj, _::Hexf item) { return obj.Print(item); } -template -inline _::AString& operator<<( - _::AString& obj, _::Binaryf item) { +template +inline _::AString& operator<<( + _::AString& obj, _::Binaryf item) { return obj.Print(item); } -template -inline _::AString& operator<<( - _::AString& obj, _::Centerf item) { +template +inline _::AString& operator<<( + _::AString& obj, _::Centerf item) { return obj.Print(item); } -template -inline _::AString& operator<<( - _::AString& obj, _::Rightf item) { +template +inline _::AString& operator<<( + _::AString& obj, _::Rightf item) { return obj.Print(item); } -template -inline _::AString& operator<<( - _::AString& obj, _::Linef item) { +template +inline _::AString& operator<<( + _::AString& obj, _::Linef item) { return obj.Print(item); } -template -inline _::AString& operator<<( - _::AString& obj, _::Headingf item) { +template +inline _::AString& operator<<( + _::AString& obj, _::Headingf item) { return obj.Print(item); } -template -inline _::AString& operator<<( - _::AString& obj, _::Charsf item) { +template +inline _::AString& operator<<( + _::AString& obj, _::Charsf item) { return obj.Print(item); } diff --git a/Stringf.h b/Stringf.h index 5790904..e3cc2f3 100644 --- a/Stringf.h +++ b/Stringf.h @@ -1,6 +1,6 @@ /* Script2™ @link https://github.com/KabukiStarship/Script2.git -@file /Stringf.h +@file /Uniprinter.h @author Cale McCollough @license Copyright Kabuki Starship™ ; This Source Code Form is subject to the terms of the Mozilla Public License, @@ -8,8 +8,8 @@ v. 2.0. If a copy of the MPL was not distributed with this file, You can obtain one at . */ #pragma once #include <_Config.h> -#ifndef SCRIPT2_STRINGF_CODLESS_DECL -#define SCRIPT2_STRINGF_CODLESS_DECL 1 +#ifndef SCRIPT2_STRINGF_DECL +#define SCRIPT2_STRINGF_DECL 1 namespace _ { /* Gets the header to print for PrintChars(const void*, const void*). */ @@ -233,24 +233,26 @@ struct LIB_MEMBER Charsf { }; /* Utility class for formatting text with operator<<, most commonly right and -center aligned. */ +center aligned. +@warning Stringf cannot be const because we need to write to it on the stack +frame in chained operator overloads. +*/ class LIB_MEMBER Stringf { public: enum { // Max length of the buffer in ALU words. - cBufferWordCount = - (sizeof(void*) == 2) - ? 5 - : (sizeof(void*) == 4) ? 6 : (sizeof(void*) == 8) ? 5 : 1, + BufferWordCount = (sizeof(void*) == 2) ? 5 + : (sizeof(void*) == 4) ? 6 + : (sizeof(void*) == 8) ? 5 : 1, // Max length of a string in characters. - cLengthMax = cBufferWordCount * sizeof(void*) - 1, + LengthMax = BufferWordCount * sizeof(void*) - 1, }; private: - const void* String_; // Pointer to a string or the buffer_. - ISW count_; //< The count. - DTW type_; //< The ASCII string Type, 1-3, of the String_. - IUW buffer_[cBufferWordCount]; //< String buffer for the token. + const void* string_; // Pointer to a string or the buffer_. + ISW count_; //< The character count. + DTW type_; //< The ASCII string Type, STA, STB, or STC. + IUW buffer_[BufferWordCount]; //< String buffer for the token. public: /* Default constructor sets the count but doesn't write a nil-term char @@ -306,7 +308,8 @@ class LIB_MEMBER Stringf { #if USING_FPD == YES_0 Stringf(FPD item, ISW count); #endif - Stringf(TypeValue item, ISW count = AConsoleWidth); + //Stringf(ATypef item, ISW count = AConsoleWidth); + //Stringf(TypeValue item, ISW count = AConsoleWidth); IUW Word(); @@ -322,10 +325,10 @@ class LIB_MEMBER Stringf { const CHC* STC(); /* Gets the type_. */ - ISW Type() const; + ISW Type(); /* Gets the count_. */ - ISW Count() const; + ISW Count(); /* Saves the pointer to the String_. */ void Print(const CHA* item); @@ -356,11 +359,11 @@ class LIB_MEMBER Stringf { #endif /* Prints a timestamp to the buffer_. */ - void PrintTMC(TMC item); - void PrintTME(TMC item, IUC subsecond_tick); - void PrintTMD(TMD item); + //void PrintTMC(TMC item); + //void PrintTME(TMC item, IUC subsecond_tick); + //void PrintTMD(TMD item); - void Print(TypeValue item); + //void Print(TypeValue item); /* Stores the item to the first word of the buffer and the negative of the count. */ @@ -535,6 +538,38 @@ struct LIB_MEMBER Indentf { Indentf(ISW indent_count); }; +/* Utility class for indicating the size or count of an item. */ +struct Sizef { + ISW size; //< The size of the item. + + Sizef(ISA size); + Sizef(ISB size); + Sizef(ISC size); + Sizef(ISD size); +}; + +/* Utility class for printing an ASCII type-value one-liner. */ +struct LIB_MEMBER ATypef { + DTW type, //< The item type. + count; //< The number of chars to print. + + ATypef(DTB type, Sizef count = { -1 }); + ATypef(DTC type, Sizef count = { -1 }); + ATypef(DTD type, Sizef count = { -1 }); + //Typef(DTE type, Sizef count = { -1 }); + ATypef(DTB pod, DTB vt, Sizef count = { -1 }); + ATypef(DTB pod, DTB vt, DTB sw, Sizef count = { -1 }); + ATypef(DTB pod, DTB vt, DTB sw, DTB map, Sizef count = { -1 }); + ATypef(DTB pod, DTB vt, DTB sw, DTB map, DTB mod, Sizef count = { -1 }); + + // Center aligns this to the given character count. + Centerf Center(ISW count); + + // Right aligns this to the given character count. + Rightf Right(ISW count); +}; + + } //< namespace _ #endif diff --git a/Stringf.hpp b/Stringf.hpp index 18f46a6..7b62e63 100644 --- a/Stringf.hpp +++ b/Stringf.hpp @@ -1,23 +1,64 @@ /* Script2™ @link https://github.com/KabukiStarship/Script2.git -@file /Stringf.hpp +@file /Uniprinter.hpp @author Cale McCollough @license Copyright Kabuki Starship™ ; This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed with this file, You can obtain one at . */ - -/* There is a different set of string printing utilities because it's a little -faster. */ #pragma once -#ifndef SCRIPT2_STRING_CODE -#define SCRIPT2_STRING_CODE -#include "Binary.hpp" -#include "Puff.hpp" -#include "Types.hpp" +#ifndef SCRIPT2_STRINGF_CODE +#define SCRIPT2_STRINGF_CODE #include "Stringf.h" +// +#include "Binary.hpp" namespace _ { +/* Gets the log_b of the sizeof(T). */ +template +constexpr Sizef TSizef() { + Sizef result = { 0 }; + switch (sizeof(T)) { + case 1: { + result.size = -1; + break; + } + case 2: { + result.size = -2; + break; + } + case 4: { + result.size = -3; + break; + } + case 8: { + result.size = -4; + break; + } + case 16: { + result.size = -5; + break; + } + case 32: { + result.size = -6; + break; + } + case 64: { + result.size = -7; + break; + } + case 128: { + result.size = -8; + break; + } + default: { + result.size = sizeof(T); + break; + } + } + return result; +} + template const CHA* TSTRTypesPOD(IS type) { @@ -143,8 +184,7 @@ ISN TSTRCompare(const CHT* string, const CHT* other_String, CHT delimiter = 0) { CHA. */ template inline const CHT* TSTREnd(const CHT* string) { - while (*string++) - ; + while (*string++); return string - 1; } @@ -281,7 +321,7 @@ inline BOL TIsWhitespace(CHT item) { } template -ISN TIsYesNo(const CHT* string) { +ISN TSTRIsYesNo(const CHT* string) { if (!string) return 0; CHT c = TToLower(*string++); ISN result; @@ -320,7 +360,8 @@ const CHT* TScanSigned(const CHT* string, IS& item) { if (c == '-') { c = *string++; sign = -1; - } else { + } + else { sign = 1; } if (!TIsDigit(c)) return nullptr; @@ -472,62 +513,62 @@ CHT* TSScan(CHT* string, IUD& item) { /* Prints a Unicode CHT to the given socket. @return Nil upon failure or a pointer to the nil-term CHT upon success. -@param string The beginning of the socket. -@param count The element count. -@param item The string to print. */ +@param start The start of the socket. +@param count The element count. +@param item The string to print. */ template -CHT* TSPrint(CHT* string, CHT* stop, CHA item) { - if (!string || string >= stop) return nullptr; - *string++ = item; - *string = 0; - return string; +CHT* TSPrint(CHT* start, CHT* stop, CHA item) { + if (!start || start >= stop) return nullptr; + *start++ = item; + *start = 0; + return start; } /* Prints a Unicode CHT to the given socket. @return Nil upon failure or a pointer to the nil-term CHT upon success. -@param string The beginning of the socket. +@param start The beginning of the socket. @param count The element count. @param item The string to print. */ template -CHT* TSPrint(CHT* string, ISW count, CHA item) { - return SPrint(string, string + count - 1, item); +CHT* TSPrint(CHT* start, ISW count, CHA item) { + return SPrint(start, start + count - 1, item); } /* Prints a Unicode CHT to the given socket. @return Nil upon failure or a pointer to the nil-term CHT upon success. -@param string The beginning of the socket. +@param start The beginning of the socket. @param count The element count. @param item The string to print. */ template -CHT* TSPrint(CHT* string, ISW count, CHB item) { - return TSPrint(string, string + count - 1, item); +CHT* TSPrint(CHT* start, ISW count, CHB item) { + return TSPrint(start, start + count - 1, item); } /* Prints the given item to the string. @return Nil upon failure or a pointer to the nil-term CHT upon success. -@param count The number of Chars in the string buffer. -@param item The string to print. */ +@param start Start of socket. +@param count Chars in the string buffer. +@param item Item to print. */ template -CHT* TSPrint(CHT* string, ISW count, CHC item) { - return TSPrint(string, string + count - 1, item); +CHT* TSPrint(CHT* start, ISW count, CHC item) { + return TSPrint(start, start + count - 1, item); } -inline CHA* SPrint(CHA* string, CHA* stop, CHA item) { - if (!string || string >= stop) return nullptr; - *string++ = item; - *string = 0; - return string; +inline CHA* SPrint(CHA* start, CHA* stop, CHA item) { + if (!stop || start >= stop) return nullptr; + *start++ = item; + *start = 0; + return start; } -inline CHA* SPrint(CHA* string, ISW size, CHA item) { - return SPrint(string, string + size - 1, item); +inline CHA* SPrint(CHA* start, ISW size, CHA item) { + return SPrint(start, start + size - 1, item); } + +#if USING_UTF16 == YES_0 + inline CHA* SPrint(CHA* string, ISW size, CHB item) { return SPrint(string, string + size - 1, item); } -inline CHA* SPrint(CHA* string, ISW size, CHC item) { - return SPrint(string, string + size - 1, item); -} -#if USING_UTF16 == YES_0 inline CHB* SPrint(CHB* string, CHB* stop, CHB item) { if (!string || string >= stop) return nullptr; *string++ = item; @@ -550,6 +591,10 @@ inline CHB* SPrint(CHB* string, ISW size, CHC item) { #endif // #if USING_UTF16 == YES_0 #if USING_UTF32 == YES_0 +inline CHA* SPrint(CHA* string, ISW size, CHC item) { + return SPrint(string, string + size - 1, item); +} + inline CHC* SPrint(CHC* string, CHC* stop, CHC item) { if (!string || string >= stop) return nullptr; *string++ = item; @@ -576,23 +621,22 @@ inline CHC* SPrint(CHC* string, CHC* stop, CHB item) { #endif //< USING_UTF32 == YES_0 /* Prints a Unicode item to the given socket. - @return Nil upon failure or a pointer to the nil-term CHT upon success. - @param string The beginning of the socket. - @param stop The last CHT in the socket. - @param item The item to print. */ +@return Nil upon failure or a pointer to the nil-term CHT upon success. +@param start The beginning of the socket. +@param stop The last CHT in the socket. +@param item The item to print. */ template -CHX* TSPrintString(CHX* string, CHX* stop, const CHY* item) { - if (!string || !item) return nullptr; - +CHX* TSPrintString(CHX* start, CHX* stop, const CHY* item) { + if (!start || start >= stop || !item) return nullptr; CHL c = 0; item = SScan(item, c); while (c) { - string = SPrint(string, stop, c); - if (!string) return string; + start = SPrint(start, stop, c); + if (!start) return start; item = SScan(item, c); } - *string = 0; - return string; + *start = 0; + return start; } template @@ -602,12 +646,12 @@ inline CHT* TSPrint(CHT* start, CHT* stop, const CHA* item) { #if USING_UTF16 == YES_0 /* Prints a Unicode item to the given socket. - @return Nil upon failure or a pointer to the nil-term CHT upon success. - @param string The beginning of the socket. - @param stop The last CHT in the socket. - @param item The item to print. - @warning This algorithm is designed to fail if the socket is not a valid socket - with one or more bytes in it, or if item is nil. */ +@return Nil upon failure or a pointer to the nil-term CHT upon success. +@param string The beginning of the socket. +@param stop The last CHT in the socket. +@param item The item to print. +@warning This algorithm is designed to fail if the socket is not a valid socket +with one or more bytes in it, or if item is nil. */ template CHT* TSPrintString(CHT* string, CHT* stop, const CHB* item) { return TSPrintString(string, stop, item); @@ -620,12 +664,12 @@ inline CHT* TSPrint(CHT* start, CHT* stop, const CHB* item) { #if USING_UTF32 == YES_0 /* Prints a Unicode item to the given socket. - @return Nil upon failure or a pointer to the nil-term CHT upon success. - @param start The beginning of the socket. - @param stop The last CHT in the socket. - @param item The item to print. - @warning This algorithm is designed to fail if the socket is not a valid socket - with one or more bytes in it, or if item is nil. */ +@return Nil upon failure or a pointer to the nil-term CHT upon success. +@param start The beginning of the socket. +@param stop The last CHT in the socket. +@param item The item to print. +@warning This algorithm is designed to fail if the socket is not a valid socket +with one or more bytes in it, or if item is nil. */ template CHT* TSPrintString(CHT* start, CHT* stop, const CHC* item) { return TSPrintString(start, stop, item); @@ -637,182 +681,6 @@ inline CHT* TSPrint(CHT* start, CHT* stop, const CHC* item) { } #endif -/* Prints a Unicode string to the given socket. -@return Nil upon failure or a pointer to the nil-term CHT upon success. -@param start The beginning of the socket. -@param size The size of the socket in CHT(s). -@param item The string to print. -@warning This algorithm is designed to fail if the socket is not a valid socket -with one or more bytes in it, or if string is nil. */ -template -inline CHT* TSPrint(CHT* start, ISW size, const CHA* item) { - return TSPrintString(start, start + size - 1, item); -} - -/* Prints a Unicode string to the given socket. -@return Nil upon failure or a pointer to the nil-term CHT upon success. -@param start The beginning of the socket. -@param size The size of the socket in CHT(s). -@param item The string to print. -@warning This algorithm is designed to fail if the socket is not a valid socket -with one or more bytes in it, or if string is nil. */ -template -CHT* TSPrint(CHT* start, ISW size, const CHB* item) { - return TSPrintString(start, start + size - 1, item); -} - -/* Prints a Unicode string to the given socket. -@return Nil upon failure or a pointer to the nil-term CHT upon success. -@param start The beginning of the socket. -@param size The size of the socket in CHT(s). -@param item The string to print. -@warning This algorithm is designed to fail if the socket is not a valid socket -with one or more bytes in it, or if string is nil. */ -template -CHT* TSPrint(CHT* start, ISW size, const CHC* item) { - return TSPrintString(start, start + size - 1, item); -} - -template -CHT* TSConcat(CHT* start, CHT* stop, const CHT* item) { - if (!start) return; - return TSPrint(TSTREnd(start), stop, item); - -} - -template -CHT* TSConcat(CHT* start, ISW size, const CHT* item) { - return TSConcat(start, start + size - 1, item); - -} - -/* Finds the end of a decimal number of the given string. -@return Nil if the string doesn't contain a decimal or is nil. -@param start The start of the string to search. */ -template -const CHT* TSTRDecimalEnd(const CHT* start) { - if (!start) return start; - CHT c = *start++; - if (c == '-') c = *start++; - if (c < '0' || c > '9') return nullptr; - c = *start++; - while (TIsDigit(c)) { - c = *start++; - if (c <= 0) return start - 1; - } - return start - 1; -} - -/* Skips all the chars in a given range. -@return Nil upon failure or a pointer to the CHT after the last CHT in the -given range. -@param cursor The first CHT in the buffer. -@param lower_bounds -@param upper bounds*/ -template -const CHT* TSTRSkimodulearsInRange(const CHT* cursor, CHT lower_bounds, - CHT upper_bounds) { - A_ASSERT(cursor); - A_ASSERT(lower_bounds < upper_bounds); - CHT c = *cursor; - while (c >= lower_bounds && c <= upper_bounds) c = *(++cursor); - return cursor; -} - -/* Skips all the chars in a given range. -@return Nil upon failure or a pointer to the CHT after the last CHT in the -given range. -@param cursor The first CHT in the buffer. -@param lower_bounds -@param upper bounds*/ -template -CHT* TSTRSkimodulearsInRange(CHT* cursor, CHT lower_bounds, CHT upper_bounds) { - return const_cast(TSTRSkimodulearsInRange(TPtr(cursor), - lower_bounds, upper_bounds)); -} - -/* Skips the numbers in the given range. */ -template -inline const CHT* TSTRSkipNumbers(const CHT* cursor) { - return const_cast(TSTRSkimodulearsInRange(TPtr(cursor), - '0', '9')); -} -/* Skips the numbers in the given range. */ -template -inline CHT* TSTRSkipNumbers(CHT* cursor) { - return const_cast(TSTRSkipNumbers(TPtr(cursor))); -} - -/* Finds the stop of the decimals in the s, if there are any. -@param cursor The first CHT in the buffer. */ -template -CHT* TSTRDecimalEnd(CHT* start) { - const CHT* ptr = TPtr(start); - return const_cast(TSTRDecimalEnd(ptr)); -} - -/* Finds the stop of the decimals in the s, if there are any. -@param cursor The first CHT in the buffer. -@param stop The last CHT in the buffer. */ -template -const CHT* TSTRDecimalEnd(const CHT* cursor, const CHT* stop) { - if (!cursor || cursor >= stop) return nullptr; - CHT c = *cursor++; - if (!c) return nullptr; - if (c == '-') { // It might be negative. - if (cursor >= stop) return nullptr; - c = *cursor++; - } - if (!TIsDigit(c)) return nullptr; - while (c) { - if (cursor >= stop) return nullptr; - if (!TIsDigit(c)) return cursor - 1; - c = *cursor++; - } - return cursor - 1; -} - -/* Finds the stop of the decimals in the s, if there are any. -@param cursor The first CHT in the buffer. -@param stop The last CHT in the buffer. */ -template -inline CHT* TSTRDecimalEnd(CHT* cursor, CHT* stop) { - return const_cast(TSTRDecimalEnd( - TPtr(cursor), TPtr(stop))); -} -template -const CHT* TSTRFloatStop(const CHT* start) { - const CHA* stop = TSTRDecimalEnd(start); - if (!stop) return stop; - CHA c = *stop++; - if (c == '.') { - stop = TSTRDecimalEnd(start); - c = *stop++; - } - if (c == 'e' || c != 'E') { - if (c == '-') c = *stop++; - return TSTRDecimalEnd(start); - } - return stop; -} - -/* Skips the given CHT in a s if there are any. -@param cursor The first CHT in the buffer. */ -template -const CHT* TSTRSkimodulear(const CHT* cursor, CHT skip_char) { - if (cursor == nullptr) return nullptr; - CHT c = *cursor, d; - if (c != skip_char) return cursor; - d = *cursor; - // We know the first CHT is a skip_char so just loop till c and d aren't - // the skip_char. - while (c == d) { - c = d; - d = *(++cursor); - } - return cursor; -} - /* Converts the given hex nibble to lowercase hex. */ inline CHA HexNibbleToLowerCase(IUA b) { b = b & 0xf; @@ -879,7 +747,7 @@ inline ISN HexToByte(IUB h) { template inline CHT* TSTRSkimodulear(CHT* cursor, CHT skip_char) { return const_cast( - TSTRSkimodulear(TPtr(cursor), skip_char)); + TSTRSkimodulear(TPtr(cursor), skip_char)); } template @@ -922,7 +790,7 @@ CHT* TSPrintHex(CHT* start, CHT* stop, IU value) { *start++ = 'x'; auto v = ToUnsigned(value); for (ISC num_bits_shift = sizeof(IU) * 8 - 4; num_bits_shift >= 0; - num_bits_shift -= 4) { + num_bits_shift -= 4) { *start++ = HexNibbleToUpperCase((IUA)(v >> num_bits_shift)); } *start = 0; @@ -988,6 +856,7 @@ inline CHT* TSPrintHex(CHT* start, CHT* stop, const void* ptr) { return TSPrintHex(start, stop, ToUnsigned(ptr)); } + /* Prints the given value to Binary. */ template CHT* TPrintBinary(CHT* start, CHT* stop, IU value) { @@ -1067,80 +936,363 @@ CHT* TPrintBinary(CHT* start, CHT* stop, FPD value) { /* Prints the given value to Binary. */ template -CHT* TPrintBinary(CHT* start, CHT* stop, const void* ptr) { - IUW address = *TPtr(&ptr); +CHT* TPrintBinary(CHT* start, CHT* stop, const void* item) { + IUW address = *TPtr(&item); return TPrintBinary(start, stop, address); } -template -CHT* TSScan(const CHT* start, FPC& result) { - return nullptr; -} - -template -CHT* TSScan(const CHT* start, FPD& result) { - return nullptr; -} -/* Prints the given socket to the COut. +/* Prints the given item aligned right the given column_count. +@return Nil if any of the pointers are nil or if column_count < 1, and a +pointer to the nil-term CHA upon success. +@param cursor The first CHT in the buffer. +@param stop The last CHT in the buffer. +@param item The item to printer. +@param column_count The token_ of columns to align right to. */ template -CHT* TPrintChars(CHT* start, CHT* stop, const void* origin, const void* end) -{ const CHT *read = TPtr(origin), *read_end = - TPtr(end); - if (!start || start >= stop || !origin || read > read_end) return nullptr; - - CHT* buffer_begin = start; - ISW size = read_end - read, num_rows = size / 64 + (size % 64 != 0) ? 1 : 0; - - ISW num_bytes = 81 * (num_rows + 2); - if ((stop - start) <= num_bytes) { +CHT* TPrintRight(CHT* cursor, CHT* stop, const CHT* item, + ISC column_count = AConsoleWidth) { + if (!cursor || cursor + column_count > stop) { return nullptr; } - size += num_bytes; - start = TSPrintString(start, stop, STRPrintCharsHeader()); - start = TSPrintString(start, stop, STRPrintCharsBorder()); - start = TSPrintHex(start, stop, read); - - CHT c; - while (read < read_end) { - *start++ = '\n'; - *start++ = '|'; - for (ISC i = 0; i < 64; ++i) { - c = *read++; - if (read > read_end) - c = 'x'; - else if (!c || c == kTAB) - c = ' '; - else if (c < ' ') - c = cDEL; - *start++ = c; - } - *start++ = '|'; - *start++ = ' '; - start = TSPrintHex(start, stop, read); - } - start = TSPrintString(start, stop, STRPrintCharsBorder()); - return TSPrintHex(start, stop, read + size); -} */ - -/* An empty string. */ -template -const CHT* TSTREmpty() { - static const CHT kString[] = ""; - return kString; -} -// A string that contains only a new line char. -template -const CHT* TSTRNL() { - static const CHT kString[] = {'\n'}; - return kString; -} + auto item_end = TSTREnd(item); + CHT c; //< Temp variable. + if (item == item_end) return cursor; + ISW length = item_end - item; -// String the reads "Error:". -template + // If the length is less than the column_count we need to print ".", "..", + // "..." or nothing and chop off some of the item. + ISW count = column_count - length; + if (count < 0) { + ISW dot_count = length + count; + if (dot_count <= 3) { + while (dot_count-- > 0) { + *cursor++ = '.'; + } + *cursor = 0; + return cursor; + } + stop = cursor + column_count; + *stop-- = 0; + *stop-- = '.'; + *stop-- = '.'; + *stop-- = '.'; + item_end = item + column_count - 4; + while (item_end > item) { + c = *item_end--; + *stop-- = c; + } + c = *item_end--; + *stop-- = c; + return cursor + column_count; + } + // In order to keep the current cache lines we're going to printer + // backwards back from the token_end. + stop = cursor + column_count; + --item_end; //< This is pointed at the nil-term CHA + *stop-- = 0; //< and there is no need to load a 0. + while (item_end >= item) { + c = *item_end--; + *stop-- = c; + } + while (stop >= cursor) { + *stop-- = ' '; + } + return cursor + column_count; +} + +/* Prints the given cursor center aligned to the given column_count. */ +template +CHT* TPrintCenter(CHT* cursor, CHT* stop, const CHT* string, + ISC column_count = AConsoleWidth) { + if (!cursor || cursor >= stop) return nullptr; + + // We need to leave at least one space to the left and right of + ISC length = TSTRLength(string); + ISC delta; + if (length <= column_count) { + delta = (column_count - length) >> 1; //< >> 1 to /2 + length = column_count - length - delta; + + if (length != column_count) + while (delta-- > 0) *cursor++ = ' '; + + CHT c = *string++; + while (c) { + *cursor++ = c; + c = *string++; + } + if (length != column_count) + while (length-- > 0) *cursor++ = ' '; + *cursor = 0; + return cursor; + } + + if (column_count <= 3) { + while (column_count-- > 0) *cursor++ = '.'; + *cursor = 0; + return cursor; + } + delta = column_count - 3; + while (delta-- > 0) *cursor++ = *string++; + *cursor++ = '.'; + *cursor++ = '.'; + *cursor++ = '.'; + *cursor = 0; + return cursor; +} + +// A string that contains only a new line char. +template +const CHT* TSTRNL() { + static const CHT String[] = { '\n' }; + return String; +} + +template +const CHT* TSTRLinef() { + static const CHT kString[] = { '\n', '\n', '-', '-', '-', '\n', NIL }; + return kString; +} + +/* Prints a line of the given column_count the given start. */ +template +CHT* TPrintLinef(CHT* start, CHT* stop, CHT item, ISW count = AConsoleWidth, + const CHT* header = TSTRNL(), + const CHT* footer = nullptr) { + if (header) start = SPrint(start, stop, header); + if (!start || start + count <= stop) return nullptr; + + while (count-- > 0) *start++ = item; + + if (footer) + return SPrint(start, stop, footer); + else + *start = 0; + return start; +} + +/* Prints the given cursor repeated to make a line. */ +template +CHT* TPrintLinef(CHT* start, CHT* stop, const CHT* item, + ISW count = AConsoleWidth, const CHT* header = TSTRNL(), + const CHT* footer = nullptr) { + if (header) start = SPrint(start, stop, header); + if (!start || start <= stop || (start + count >= stop)) return nullptr; + + const CHT* cursor = item; + while (count-- > 0) { + CHT c = *cursor++; + if (!c) { + cursor = item; + c = *cursor++; + } + *start++ = c; + } + if (footer) + return SPrint(start, stop, footer); + else + *start = 0; + return start; +} + +/* Prints a Unicode string to the given socket. +@return Nil upon failure or a pointer to the nil-term CHT upon success. +@param start The beginning of the socket. +@param size The size of the socket in CHT(s). +@param item The string to print. +@warning This algorithm is designed to fail if the socket is not a valid socket +with one or more bytes in it, or if string is nil. */ +template +inline CHT* TSPrint(CHT* start, ISW size, const CHA* item) { + return TSPrintString(start, start + size - 1, item); +} + +/* Prints a Unicode string to the given socket. +@return Nil upon failure or a pointer to the nil-term CHT upon success. +@param start The beginning of the socket. +@param size The size of the socket in CHT(s). +@param item The string to print. +@warning This algorithm is designed to fail if the socket is not a valid socket +with one or more bytes in it, or if string is nil. */ +template +CHT* TSPrint(CHT* start, ISW size, const CHB* item) { + return TSPrintString(start, start + size - 1, item); +} + +/* Prints a Unicode string to the given socket. +@return Nil upon failure or a pointer to the nil-term CHT upon success. +@param start The beginning of the socket. +@param size The size of the socket in CHT(s). +@param item The string to print. +@warning This algorithm is designed to fail if the socket is not a valid socket +with one or more bytes in it, or if string is nil. */ +template +CHT* TSPrint(CHT* start, ISW size, const CHC* item) { + return TSPrintString(start, start + size - 1, item); +} + +template +CHT* TSConcat(CHT* start, CHT* stop, const CHT* item) { + if (!start) return; + return TSPrint(TSTREnd(start), stop, item); + +} + +template +CHT* TSConcat(CHT* start, ISW size, const CHT* item) { + return TSConcat(start, start + size - 1, item); + +} + +/* Finds the end of a decimal number of the given string. +@return Nil if the string doesn't contain a decimal or is nil. +@param start The start of the string to search. */ +template +const CHT* TSTRDecimalEnd(const CHT* start) { + if (!start) return start; + CHT c = *start++; + if (c == '-') c = *start++; + if (c < '0' || c > '9') return nullptr; + c = *start++; + while (TIsDigit(c)) { + c = *start++; + if (c <= 0) return start - 1; + } + return start - 1; +} + +/* Skips all the chars in a given range. +@return Nil upon failure or a pointer to the CHT after the last CHT in the +given range. +@param cursor The first CHT in the buffer. +@param lower_bounds +@param upper bounds*/ +template +const CHT* TSTRSkimodulearsInRange(const CHT* cursor, CHT lower_bounds, + CHT upper_bounds) { + if(!cursor || lower_bounds >= upper_bounds) return nullptr; + CHT c = *cursor; + while (c >= lower_bounds && c <= upper_bounds) c = *(++cursor); + return cursor; +} + +/* Skips all the chars in a given range. +@return Nil upon failure or a pointer to the CHT after the last CHT in the +given range. +@param cursor The first CHT in the buffer. +@param lower_bounds +@param upper bounds*/ +template +CHT* TSTRSkimodulearsInRange(CHT* cursor, CHT lower_bounds, CHT upper_bounds) { + return const_cast(TSTRSkimodulearsInRange(TPtr(cursor), + lower_bounds, upper_bounds)); +} + +/* Skips the numbers in the given range. */ +template +inline const CHT* TSTRSkipNumbers(const CHT* cursor) { + return const_cast(TSTRSkimodulearsInRange(TPtr(cursor), + '0', '9')); +} +/* Skips the numbers in the given range. */ +template +inline CHT* TSTRSkipNumbers(CHT* cursor) { + return const_cast(TSTRSkipNumbers(TPtr(cursor))); +} + +/* Finds the stop of the decimals in the s, if there are any. +@param cursor The first CHT in the buffer. */ +template +CHT* TSTRDecimalEnd(CHT* start) { + const CHT* ptr = TPtr(start); + return const_cast(TSTRDecimalEnd(ptr)); +} + +/* Finds the stop of the decimals in the s, if there are any. +@param cursor The first CHT in the buffer. +@param stop The last CHT in the buffer. */ +template +const CHT* TSTRDecimalEnd(const CHT* cursor, const CHT* stop) { + if (!cursor || cursor >= stop) return nullptr; + CHT c = *cursor++; + if (!c) return nullptr; + if (c == '-') { // It might be negative. + if (cursor >= stop) return nullptr; + c = *cursor++; + } + if (!TIsDigit(c)) return nullptr; + while (c) { + if (cursor >= stop) return nullptr; + if (!TIsDigit(c)) return cursor - 1; + c = *cursor++; + } + return cursor - 1; +} + +/* Finds the stop of the decimals in the s, if there are any. +@param cursor The first CHT in the buffer. +@param stop The last CHT in the buffer. */ +template +inline CHT* TSTRDecimalEnd(CHT* cursor, CHT* stop) { + return const_cast(TSTRDecimalEnd( + TPtr(cursor), TPtr(stop))); +} +template +const CHT* TSTRFloatStop(const CHT* start) { + const CHA* stop = TSTRDecimalEnd(start); + if (!stop) return stop; + CHA c = *stop++; + if (c == '.') { + stop = TSTRDecimalEnd(start); + c = *stop++; + } + if (c == 'e' || c != 'E') { + if (c == '-') c = *stop++; + return TSTRDecimalEnd(start); + } + return stop; +} + +/* Skips the given CHT in a s if there are any. +@param cursor The first CHT in the buffer. */ +template +const CHT* TSTRSkimodulear(const CHT* cursor, CHT skip_char) { + if (cursor == nullptr) return nullptr; + CHT c = *cursor, d; + if (c != skip_char) return cursor; + d = *cursor; + // We know the first CHT is a skip_char so just loop till c and d aren't + // the skip_char. + while (c == d) { + c = d; + d = *(++cursor); + } + return cursor; +} + +template +CHT* TSScan(const CHT* start, FPC& result) { + return nullptr; +} + +template +CHT* TSScan(const CHT* start, FPD& result) { + return nullptr; +} + +/* An empty string. */ +template +const CHT* TSTREmpty() { + static const CHT kString[] = ""; + return kString; +} + +// String the reads "Error:". +template const CHT* TSTRError() { - static const CHT kString[] = {'\n', 'E', 'r', 'r', 'o', 'r', ':', NIL}; + static const CHT kString[] = { '\n', 'E', 'r', 'r', 'o', 'r', ':', NIL }; return kString; } @@ -1168,7 +1320,7 @@ const CHT* TSTRLineEnd(const CHT* cursor, ISC column_count = AConsoleWidth) { c = *cursor++; while (c) { if (column_count-- < 0) { // We've reached the stop. - // Scroll left till we hit whitespace (if any). + // Scroll left till we hit whitespace (if any). while (!TIsWhitespace(c)) c = *(--cursor); // Then scroll past the whitespace. while (TIsWhitespace(c)) c = *(--cursor); @@ -1194,9 +1346,8 @@ CHT* TSTRLineEnd(CHT* cursor, ISC column_count = AConsoleWidth) { @param column_count In characters. */ template const CHT* TSTRLineEnd(const CHT* cursor, const CHT* stop, - ISC column_count = AConsoleWidth) { - if (!cursor) return nullptr; - A_ASSERT(cursor < stop); + ISC column_count = AConsoleWidth) { + if (!cursor || cursor >= stop) return nullptr; CHT c; // Scroll to the stop of the line. c = *cursor++; @@ -1221,9 +1372,9 @@ const CHT* TSTRLineEnd(const CHT* cursor, const CHT* stop, @param column_coun In characters. */ template inline CHT* TSTRLineEnd(CHT* cursor, CHT* stop, - ISC column_count = AConsoleWidth) { + ISC column_count = AConsoleWidth) { return const_cast( - TSTRLineEnd(TPtr(cursor), TPtr(stop), column_count)); + TSTRLineEnd(TPtr(cursor), TPtr(stop), column_count)); } /* Scrolls over any whitespace. @@ -1253,21 +1404,18 @@ CHT* TSTRSkipSpaces(CHT* cursor) { @param query A query string. */ template const CHT* TSTRFind(const CHT* start, const CHT* query) { - A_ASSERT(start); - A_ASSERT(query); - CHT s = *start, //< Current s CHT. - t = *query, //< Current query CHT. - c = t; //< The first CHT of the query we're searching for. + t = *query, //< Current query CHT. + c = t; //< The first CHT of the query we're searching for. if (!c) //< We're not allowing empty queries. return nullptr; - const CHT *start_of_query, *cursor = start; + const CHT* start_of_query, * cursor = start; query = TSTRSkipSpaces(query); // Scroll through each CHT and match it to the query CHT. while (s) { if (s == c) { // The first CHT matches: - // Setup to compare the Strings; + // Setup to compare the Strings; start_of_query = start; cursor = query; t = c; @@ -1318,7 +1466,7 @@ const CHT* TSTRSkipSpaces(const CHT* cursor, const CHT* stop) { template inline CHT* TSTRSkipSpaces(CHT* cursor, CHT* stop) { return const_cast(TSTRSkipSpaces( - TPtr(cursor), TPtr(stop))); + TPtr(cursor), TPtr(stop))); } /* Checks if the two Strings are the same. @@ -1328,9 +1476,6 @@ equivalent s upon success. @param String_b A cursor to compare to String_a. */ template const CHT* TSTREquals(const CHT* String_a, const CHT* String_b) { - A_ASSERT(String_a); - A_ASSERT(String_b); - CHT a = *String_a, b = *String_b; while (a) { if (a != b) return nullptr; @@ -1350,7 +1495,7 @@ equivalent s upon success. template inline CHT* TSTREquals(CHT* String_a, const CHT* String_b) { return const_cast(TSTREquals( - TPtr(String_a), TPtr(String_b))); + TPtr(String_a), TPtr(String_b))); } /* Compares the two Strings to see if the are equal. @@ -1358,8 +1503,7 @@ inline CHT* TSTREquals(CHT* String_a, const CHT* String_b) { s upon success. */ template const CHT* TSTREquals(const CHT* cursor, const CHT* stop, const CHT* query) { - if (!cursor) return nullptr; - A_ASSERT(cursor < stop); + if (!cursor || cursor >= stop) return nullptr; if (!query) return nullptr; CHT a = *cursor, b = *query; @@ -1368,241 +1512,85 @@ const CHT* TSTREquals(const CHT* cursor, const CHT* stop, const CHT* query) { if (b == 0) return cursor; if (cursor > stop) { return nullptr; - } - a = *(++cursor); - b = *(++query); - } - if (b) return nullptr; - return cursor; -} - -/* Compares the two Strings to see if the are equal. -@return Nil of the two Strings aren't equal or a pointer to the stop of the -s upon success. */ -template -CHT* TSTREquals(CHT* cursor, CHT* stop, const CHT* query) { - return const_cast(TSTREquals( - TPtr(cursor), TPtr(stop), query)); -} - -/* Checks if the given s isn't empty. -@return False if the s is empty and true otherwise. -@param cursor The first CHT in the buffer. -@desc A s is defined as empty if it is NIL or all whitespace. */ -template -BOL TSTRIsntEmpty(const CHT* cursor) { - if (!cursor) return false; - CHT c = *cursor; - while (c) { - if (!TIsWhitespace(c)) return true; - c = *(++cursor); - } - return false; -} - -/* Checks if the given s isn't empty. -@return False if the s is empty and true otherwise. -@param cursor The first CHT in the buffer. -@desc A s is defined as empty if it is NIL or all whitespace. */ -template -BOL TSTRIsntEmpty(CHT* cursor) { - return TSTRIsntEmpty(TPtr(cursor)); -} - -/* Checks to see if the cursor isn't empty or whitespace. -@return False if the s is empty and true otherwise. -@param cursor The first CHT in the buffer. -@param stop The last CHT in the buffer. */ -template -BOL TSTRIsntEmpty(const CHT* cursor, const CHT* stop) { - if (!cursor) return false; - if (cursor > stop) return false; - CHT c = *cursor; - while (c) { - if (!TIsWhitespace(c)) { - // The text must stop at or before the target_end. - do { - if (++cursor >= stop) return false; - c = *cursor; - if (!TIsWhitespace(c)) return true; - } while (c); - return true; - } - if (++cursor >= stop) return false; - c = *cursor; - } - return false; -} - -/* Checks to see if the cursor isn't empty or whitespace. -@return False if the s is empty and true otherwise. -@param cursor The first CHT in the buffer. -@param stop The last CHT in the buffer. */ -template -BOL TSTRIsntEmpty(CHT* cursor, const CHT* stop) { - return TSTRIsntEmpty(TPtr(cursor), TPtr(stop)); -} - -/* Prints the given item aligned right the given column_count. -@return Nil if any of the pointers are nil or if column_count < 1, and a -pointer to the nil-term CHA upon success. -@param cursor The first CHT in the buffer. -@param stop The last CHT in the buffer. -@param item The item to printer. -@param column_count The token_ of columns to align right to. */ -template -CHT* TPrintRight(CHT* cursor, CHT* stop, const CHT* item, - ISC column_count = AConsoleWidth) { - if (!cursor || cursor + column_count > stop) { - return nullptr; - } - - auto item_end = TSTREnd(item); - CHT c; //< Temp variable. - if (item == item_end) return cursor; - ISW length = item_end - item; - - // If the length is less than the column_count we need to print ".", "..", - // "..." or nothing and chop off some of the item. - ISW count = column_count - length; - if (count < 0) { - ISW dot_count = length + count; - if (dot_count <= 3) { - while (dot_count-- > 0) { - *cursor++ = '.'; - } - *cursor = 0; - return cursor; - } - stop = cursor + column_count; - *stop-- = 0; - *stop-- = '.'; - *stop-- = '.'; - *stop-- = '.'; - item_end = item + column_count - 4; - while (item_end > item) { - c = *item_end--; - *stop-- = c; - } - c = *item_end--; - *stop-- = c; - return cursor + column_count; - } - // In order to keep the current cache lines we're going to printer - // backwards back from the token_end. - stop = cursor + column_count; - --item_end; //< This is pointed at the nil-term CHA - *stop-- = 0; //< and there is no need to load a 0. - while (item_end >= item) { - c = *item_end--; - *stop-- = c; - } - while (stop >= cursor) { - *stop-- = ' '; - } - return cursor + column_count; -} - -/* Prints the given cursor center aligned to the given column_count. */ -template -CHT* TPrintCenter(CHT* cursor, CHT* stop, const CHT* string, - ISC column_count = AConsoleWidth) { - if (!cursor || cursor >= stop) return nullptr; - - // We need to leave at least one space to the left and right of - ISC length = TSTRLength(string); - ISC delta; - if (length <= column_count) { - delta = (column_count - length) >> 1; //< >> 1 to /2 - length = column_count - length - delta; - - if (length != column_count) - while (delta-- > 0) *cursor++ = ' '; - - CHT c = *string++; - while (c) { - *cursor++ = c; - c = *string++; - } - if (length != column_count) - while (length-- > 0) *cursor++ = ' '; - *cursor = 0; - return cursor; - } - - if (column_count <= 3) { - while (column_count-- > 0) *cursor++ = '.'; - *cursor = 0; - return cursor; - } - delta = column_count - 3; - while (delta-- > 0) *cursor++ = *string++; - *cursor++ = '.'; - *cursor++ = '.'; - *cursor++ = '.'; - *cursor = 0; + } + a = *(++cursor); + b = *(++query); + } + if (b) return nullptr; return cursor; } -/* Prints a line of the given column_count the given start. */ +/* Compares the two Strings to see if the are equal. +@return Nil of the two Strings aren't equal or a pointer to the stop of the +s upon success. */ template -CHT* TPrintLinef(CHT* start, CHT* stop, CHT item, ISW count = AConsoleWidth, - const CHT* header = TSTRNL(), - const CHT* footer = nullptr) { - if (header) start = SPrint(start, stop, header); - if (!start || start + count <= stop) return nullptr; - - while (count-- > 0) *start++ = item; - - if (footer) - return SPrint(start, stop, footer); - else - *start = 0; - return start; +CHT* TSTREquals(CHT* cursor, CHT* stop, const CHT* query) { + return const_cast(TSTREquals( + TPtr(cursor), TPtr(stop), query)); } -/* Prints the given cursor repeated to make a line. */ +/* Checks if the given s isn't empty. +@return False if the s is empty and true otherwise. +@param cursor The first CHT in the buffer. +@desc A s is defined as empty if it is NIL or all whitespace. */ template -CHT* TPrintLinef(CHT* start, CHT* stop, const CHT* item, - ISW count = AConsoleWidth, const CHT* header = TSTRNL(), - const CHT* footer = nullptr) { - if (header) start = SPrint(start, stop, header); - if (!start || start <= stop || (start + count >= stop)) return nullptr; - - const CHT* cursor = item; - while (count-- > 0) { - CHT c = *cursor++; - if (!c) { - cursor = item; - c = *cursor++; - } - *start++ = c; +BOL TSTRIsntEmpty(const CHT* cursor) { + if (!cursor) return false; + CHT c = *cursor; + while (c) { + if (!TIsWhitespace(c)) return true; + c = *(++cursor); } - if (footer) - return SPrint(start, stop, footer); - else - *start = 0; - return start; + return false; } -/* Prints the given cursor repeated to make a line. */ +/* Checks if the given s isn't empty. +@return False if the s is empty and true otherwise. +@param cursor The first CHT in the buffer. +@desc A s is defined as empty if it is NIL or all whitespace. */ template -CHT* TPrintHeadingf(CHT* start, CHT* stop, CHT item, - ISW count = AConsoleWidth) { - return TPrintLinef(start, stop, item, count, nullptr, nullptr); +BOL TSTRIsntEmpty(CHT* cursor) { + return TSTRIsntEmpty(TPtr(cursor)); } -/* Prints the given cursor repeated to make a line. */ +/* Checks to see if the cursor isn't empty or whitespace. +@return False if the s is empty and true otherwise. +@param cursor The first CHT in the buffer. +@param stop The last CHT in the buffer. */ +template +BOL TSTRIsntEmpty(const CHT* cursor, const CHT* stop) { + if (!cursor) return false; + if (cursor > stop) return false; + CHT c = *cursor; + while (c) { + if (!TIsWhitespace(c)) { + // The text must stop at or before the target_end. + do { + if (++cursor >= stop) return false; + c = *cursor; + if (!TIsWhitespace(c)) return true; + } while (c); + return true; + } + if (++cursor >= stop) return false; + c = *cursor; + } + return false; +} + +/* Checks to see if the cursor isn't empty or whitespace. +@return False if the s is empty and true otherwise. +@param cursor The first CHT in the buffer. +@param stop The last CHT in the buffer. */ template -CHT* TPrintHeadingf(CHT* start, CHT* stop, const CHT* item, - ISW count = AConsoleWidth) { - return TPrintLinef(start, stop, item, count, nullptr, nullptr); +BOL TSTRIsntEmpty(CHT* cursor, const CHT* stop) { + return TSTRIsntEmpty(TPtr(cursor), TPtr(stop)); } /* Prints a cursor to the given buffer without */ template CHT* TPrintWrap(CHT* cursor, CHT* stop, const CHT* string, - ISW column_count = AConsoleWidth) { + ISW column_count = AConsoleWidth) { if (!cursor || cursor <= stop || !string) return nullptr; if (column_count < 2) return cursor; @@ -1627,227 +1615,6 @@ CHT* TPrintWrap(CHT* cursor, CHT* stop, const CHT* string, return cursor; } -/* Templated string Printer. */ -template -struct TSPrinter { - CHT *start, //< Start address. - *stop; //< Stop address. - - /* Default constructor does nothing. */ - TSPrinter() : start(0), stop(0) {} - - /* Initializes the UTF& from the given origin pointers. - @param start The origin of the origin. - @param count The number of CHT(s) in the buffer. */ - TSPrinter(CHT* start, IS size) : start(start), stop(start + size - 1) { - Reset(); - } - - /* Initializes the array pointers from the given start and stop pointers. - @param start The start of the array. - @param stop The stop of the array. */ - TSPrinter(CHT* start, CHT* stop) : start(start), stop(stop) { Reset(); } - - /* Clones the other printer. */ - TSPrinter(const TSPrinter& other) - : start(other.start), stop(other.stop) { // Nothing to do here!. - } - - IUA* End() { return TPtr(start) + (sizeof(CHT) - 1); } - - IS SizeBytes() { return (IS)(stop - start + sizeof(CHT)); } - - void Wipe() { ArrayFill(start, stop); } - - /* Writes a nil-term CHA at the start of the string. */ - inline CHT* Reset() { - *start = 0; - return start; - } - - /* Sets the start pointer to the new_pointer. */ - inline TSPrinter& Set(CHT* cursor) { - start = cursor; - return *this; - } - - /* Sets the start pointer to the new_pointer. */ - inline TSPrinter& Set(IUW* buffer) { - IS size = *TPtr(buffer); - IUW ptr = IUW(buffer) + sizeof(IS); - CHT* start_ptr = TPtr(ptr); - start = start_ptr; - stop = start_ptr + size - 1; - return *this; - } - - /* Sets the start pointer to the new_pointer. */ - inline void Set(TSPrinter other) { - start = other.start; - stop = other.stop; - } - - /* Finds the length of the STR in Chars. */ - inline IS SpaceLeft() { return (IS)(stop - start); } - - /* Calculates the max length of the string in Chars. */ - inline IS LengthMax() { return stop - start; } - - /* Prints a item to the string. */ - inline TSPrinter& PrintChar(CHA item) { - return Set(_::TSPrint(start, stop, item)); - } - inline TSPrinter& PrintChar(CHB item) { - return Set(_::TSPrint(start, stop, item)); - } - inline TSPrinter& PrintChar(CHC item) { - return Set(_::TSPrint(start, stop, item)); - } - inline TSPrinter& Print(CHA item) { return PrintChar(item); } - inline TSPrinter& Print(CHB item) { return PrintChar(item); } - inline TSPrinter& Print(CHC item) { return PrintChar(item); } - inline TSPrinter& Print(const CHA* item) { - return Set(_::TSPrintString(start, stop, item)); - } - inline TSPrinter& Print(const CHB* item) { - return Set(_::TSPrintString(start, stop, item)); - } - inline TSPrinter& Print(const CHC* item) { - return Set(_::TSPrintString(start, stop, item)); - } - inline TSPrinter& Print(ISC item) { - return Set(_::TSPrint(start, stop, item)); - } - inline TSPrinter& Print(IUC item) { - return Set(_::TSPrint(start, stop, item)); - } - inline TSPrinter& Print(ISD item) { - return Set(_::TSPrint(start, stop, item)); - } - inline TSPrinter& Print(IUD item) { - return Set(_::TSPrint(start, stop, item)); - } -#if USING_FPC == YES_0 - inline TSPrinter& Print(FPC item) { - return Set(_::TSPrint(start, stop, item)); - } -#endif -#if USING_FPD == YES_0 - inline TSPrinter& Print(FPD item) { - return Set(_::TSPrint(start, stop, item)); - } -#endif - inline TSPrinter& Print(Hexf item) { - return TSPrintHex(*this, item.element); - } - inline TSPrinter& Print(Rightf item) { - return TPrintRight(*this, item.element); - } - inline TSPrinter& Print(Centerf item) { - return TPrintCenter(*this, item.element); - } - inline TSPrinter& Print(Linef item) { - return TPrintLinef(*this, item); - } - inline TSPrinter& Print(Headingf item) { - return TPrintHeadingf(*this, item); - } - - /* Prints the given pointer as hex. */ - inline TSPrinter& Hex(Hexf item) { - return TSPrintHex(*this, item.element.ToPtr(), item.element.count); - } - inline TSPrinter& Hex(ISA item) { - return Set(TSPrintHex(start, stop, item)); - } - inline TSPrinter& Hex(IUA item) { - return Set(TSPrintHex(start, stop, item)); - } - inline TSPrinter& Hex(ISB item) { - return Set(TSPrintHex(start, stop, item)); - } - inline TSPrinter& Hex(IUB item) { - return Set(TSPrintHex(start, stop, item)); - } - inline TSPrinter& Hex(ISC item) { - return Set(TSPrintHex(start, stop, item)); - } - inline TSPrinter& Hex(IUC item) { - return Set(TSPrintHex(start, stop, item)); - } - inline TSPrinter& Hex(ISD item) { - return Set(TSPrintHex(start, stop, item)); - } - inline TSPrinter& Hex(IUD item) { - return Set(TSPrintHex(start, stop, item)); - } -#if USING_FPC == YES_0 - inline TSPrinter& Hex(FPC item) { - return Set(TSPrintHex(start, stop, item)); - } -#endif -#if USING_FPD == YES_0 - inline TSPrinter& Hex(FPD item) { - return Set(TSPrintHex(start, stop, item)); - } -#endif - inline TSPrinter& Hex(const void* ptr) { - return Set(TSPrintHex(start, stop, ptr)); - } - inline TSPrinter& Binary(ISA item) { - return Set(Binary(start, stop, item)); - } - inline TSPrinter& Binary(IUA item) { - return Set(Binary(start, stop, item)); - } - inline TSPrinter& Binary(ISB item) { - return Set(Binary(start, stop, item)); - } - inline TSPrinter& Binary(IUB item) { - return Set(Binary(start, stop, item)); - } - inline TSPrinter& Binary(ISC item) { - return Set(Binary(start, stop, item)); - } - inline TSPrinter& Binary(IUC item) { - return Set(Binary(start, stop, item)); - } - inline TSPrinter& Binary(ISD item) { - return Set(Binary(start, stop, item)); - } - inline TSPrinter& Binary(IUD item) { - return Set(Binary(start, stop, item)); - } -#if USING_FPC == YES_0 - inline TSPrinter& Binary(FPC item) { - return Set(Binary(start, stop, item)); - } -#endif -#if USING_FPD == YES_0 - inline TSPrinter& Binary(FPD item) { - return Set(Binary(start, stop, item)); - } -#endif - /* Prints the given pointer as binary. */ - inline TSPrinter& Binary(const void* ptr) { - IUW address = IUW(ptr); - return Set(Binary(start, stop, address)); - } - - template - inline Printer& PrintTo(Printer& o) { - o << "\nTUTF{ start:"; - TSPrintHex(o, start); - o << " stop:"; - TSPrintHex(o, stop); - return o << " }\n"; - -#if D_THIS - // return TPrintChars(o, start, stop); -#endif - } -}; - /* Queries the given s for the given query. */ template ISC TSTRQuery(const CHT* cursor, const CHT* stop, const CHT* query) { @@ -1893,163 +1660,6 @@ ISC TSTRQuery(const CHT* cursor, const CHT* stop, const CHT* query) { return 0; } -/* Prints the given sizef to the printer. */ -template -Printer& TPrintSizef(Printer& printer, Sizef item) { - auto value = item.size; - if (value < 0) return printer << CHA('@' + (-value)); - return printer << value; -} - -} //< namespace _ - -/* Prints the given item to the UTF. -@return The printer. -@param printer The printer. -@param item The item to printer. */ -template -inline _::TSPrinter& operator<<(_::TSPrinter& printer, CHA item) { - return printer.Print(item); -} - -template -inline _::TSPrinter& operator<<(_::TSPrinter& printer, const CHA* item) { - return printer.Print(item); -} - -#if USING_UTF16 == YES_0 -template -inline _::TSPrinter& operator<<(_::TSPrinter& printer, CHB item) { - return printer.Print(item); -} - -template -inline _::TSPrinter& operator<<(_::TSPrinter& printer, const CHB* item) { - return printer.Print(item); -} -#endif -#if USING_UTF32 == YES_0 -template -inline _::TSPrinter& operator<<(_::TSPrinter& printer, CHC item) { - return printer.Print(item); -} - -template -inline _::TSPrinter& operator<<(_::TSPrinter& printer, const CHC* item) { - return printer.Print(item); -} -#endif - -template -inline _::TSPrinter& operator<<(_::TSPrinter& printer, ISA item) { - return printer.Print(item); -} - -template -inline _::TSPrinter& operator<<(_::TSPrinter& printer, IUA item) { - return printer.Print(item); -} - -template -inline _::TSPrinter& operator<<(_::TSPrinter& printer, ISB item) { - return printer.Print(item); -} - -template -inline _::TSPrinter& operator<<(_::TSPrinter& printer, IUB item) { - return printer.Print(item); -} - -template -inline _::TSPrinter& operator<<(_::TSPrinter& printer, ISC item) { - return printer.Print(item); -} - -template -inline _::TSPrinter& operator<<(_::TSPrinter& printer, IUC item) { - return printer.Print(item); -} - -template -inline _::TSPrinter& operator<<(_::TSPrinter& printer, ISD item) { - return printer.Print(item); -} - -template -inline _::TSPrinter& operator<<(_::TSPrinter& printer, IUD item) { - return printer.Print(item); -} - -#if USING_FPC == YES_0 -template -inline _::TSPrinter& operator<<(_::TSPrinter& printer, FPC item) { - return printer.Print(item); -} -#endif - -#if USING_FPD == YES_0 -template -inline _::TSPrinter& operator<<(_::TSPrinter& printer, FPD item) { - return printer.Print(item); -} -#endif - -template -inline _::TSPrinter& operator<<(_::TSPrinter& printer, _::Centerf item) { - return printer.Print(item); -} -template -inline _::TSPrinter& operator<<(_::TSPrinter& printer, _::Centerf& item) { - return printer.Print(item); -} - -template -inline _::TSPrinter& operator<<(_::TSPrinter& printer, _::Rightf item) { - return printer.Print(item); -} -template -inline _::TSPrinter& operator<<(_::TSPrinter& printer, _::Rightf& item) { - return printer.Print(item); -} - -template -inline _::TSPrinter& operator<<(_::TSPrinter& printer, _::Linef item) { - return printer.Print(item); -} -template -inline _::TSPrinter& operator<<(_::TSPrinter& printer, _::Linef& item) { - return printer.Print(item); -} - -template -inline _::TSPrinter& operator<<(_::TSPrinter& printer, _::Headingf item) { - return printer.Print(item); -} -template -inline _::TSPrinter& operator<<(_::TSPrinter& printer, - _::Headingf& item) { - return printer.Print(item); -} - -template -inline _::TSPrinter& operator<<(_::TSPrinter& printer, _::Hexf item) { - return printer.Print(item); -} -template -inline _::TSPrinter& operator<<(_::TSPrinter& printer, _::Hexf& item) { - return printer.Print(item); -} +} // namesapce _ -template -inline _::TSPrinter& operator<<(_::TSPrinter& printer, _::Charsf item) { - return printer.Print(item); -} -template -inline _::TSPrinter& operator<<(_::TSPrinter& printer, _::Charsf& item) { - return printer.Print(item); -} -template -inline _::TSPrinter& operator<<(_::TSPrinter& printer, _::Sizef& item) { - return _::TPrintSizef<_::TSPrinter>(printer, item); -} #endif diff --git a/Stringf.inl b/Stringf.inl index 24de89a..8fd9882 100644 --- a/Stringf.inl +++ b/Stringf.inl @@ -1,13 +1,13 @@ /* Script2™ @link https://github.com/KabukiStarship/Script2.git -@file /Stringf.inl +@file /Uniprinter.inl @author Cale McCollough @license Copyright Kabuki Starship™ ; This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed with this file, You can obtain one at . */ -#include <_Config.h> #include "Stringf.hpp" +#include "Binary.hpp" namespace _ { const CHA* STRPrintCharsHeader() { return "\n|0 8 16 24 32 40 48 56 |" @@ -248,8 +248,8 @@ const CHA* STRError(ISA error_number) { } //< namespace _ -#if SEAM >= SCRIPT2_CORE -#if SEAM == SCRIPT2_CORE +#if SEAM >= SCRIPT2_COUT +#if SEAM == SCRIPT2_COUT #include "_Debug.inl" #else #include "_Release.inl" @@ -437,10 +437,42 @@ const CHB* SScan(const CHB* string, CHC& item) { } #endif -} //< namespace _ -#endif +ATypef::ATypef(DTB type, Sizef count) : count(count.size), type(type) {} +ATypef::ATypef(DTC type, Sizef count) : count(count.size), type(type) {} +ATypef::ATypef(DTD type, Sizef count) : count(count.size), type(type) {} -namespace _ { +ATypef::ATypef(DTB pod, DTB vt, Sizef count) : + count(count.size), + type(ATypePack(pod, vt)) +{} + +ATypef::ATypef(DTB pod, DTB vt, DTB sw, Sizef count) : + count(count.size), + type(ATypePack(pod, vt, sw)) +{} + +ATypef::ATypef(DTB pod, DTB vt, DTB sw, DTB map, Sizef count) : + count(count.size), + type(ATypePack(pod, vt, sw, map)) +{} + +ATypef::ATypef(DTB pod, DTB vt, DTB sw, DTB map, DTB mod, Sizef count) : + count(count.size), + type(ATypePack(pod, vt, sw, map, mod)) +{} + + +Centerf ATypef::Center(ISW count) { + Centerf result; + + return result; +} + +Rightf ATypef::Right(ISW count) { + Rightf result; + + return result; +} Valuef::Valuef() : count(0), value() {} @@ -562,78 +594,75 @@ Binaryf::Binaryf(FPD item) : valuef(item, sizeof(FPD)) {} // Stringf::Stringf () {} Stringf::Stringf() : type_(_NIL), count_(0), buffer_() { - String_ = &buffer_[0]; + string_ = &buffer_[0]; *buffer_ = 0; } //< Visual C++ is complaining about unitialized members. I think it's a bug. -Stringf::Stringf(const CHA* item) : String_(item), count_(0) { Print(item); } +Stringf::Stringf(const CHA* item) : string_(item), count_(0) { Print(item); } #if USING_UTF16 == YES_0 -Stringf::Stringf(const CHB* item) : String_(item), count_(0) { Print(item); } +Stringf::Stringf(const CHB* item) : string_(item), count_(0) { Print(item); } #endif #if USING_UTF32 == YES_0 -Stringf::Stringf(const CHC* item) : String_(item), count_(0) { Print(item); } -#endif -Stringf::Stringf(CHA item) : String_(buffer_), count_(0) { Print(item); } -Stringf::Stringf(CHB item) : String_(buffer_), count_(0) { Print(item); } -Stringf::Stringf(CHC item) : String_(buffer_), count_(0) { Print(item); } -Stringf::Stringf(ISC item) : String_(buffer_), count_(0) { Print(item); } -Stringf::Stringf(IUC item) : String_(buffer_), count_(0) { Print(item); } -Stringf::Stringf(ISD item) : String_(buffer_), count_(0) { Print(item); } -Stringf::Stringf(IUD item) : String_(buffer_), count_(0) { Print(item); } +Stringf::Stringf(const CHC* item) : string_(item), count_(0) { Print(item); } +#endif +Stringf::Stringf(CHA item) : string_(buffer_), count_(0) { Print(item); } +Stringf::Stringf(CHB item) : string_(buffer_), count_(0) { Print(item); } +Stringf::Stringf(CHC item) : string_(buffer_), count_(0) { Print(item); } +Stringf::Stringf(ISC item) : string_(buffer_), count_(0) { Print(item); } +Stringf::Stringf(IUC item) : string_(buffer_), count_(0) { Print(item); } +Stringf::Stringf(ISD item) : string_(buffer_), count_(0) { Print(item); } +Stringf::Stringf(IUD item) : string_(buffer_), count_(0) { Print(item); } #if USING_FPC == YES_0 -Stringf::Stringf(FPC item) : String_(buffer_), count_(0) { Print(item); } +Stringf::Stringf(FPC item) : string_(buffer_), count_(0) { Print(item); } #endif #if USING_FPD == YES_0 -Stringf::Stringf(FPD item) : String_(buffer_), count_(0) { Print(item); } +Stringf::Stringf(FPD item) : string_(buffer_), count_(0) { Print(item); } #endif -Stringf::Stringf(const CHA* item, ISW count) : String_(item), count_(count) { +Stringf::Stringf(const CHA* item, ISW count) : string_(item), count_(count) { Print(item); } #if USING_UTF16 == YES_0 -Stringf::Stringf(const CHB* item, ISW count) : String_(item), count_(count) { +Stringf::Stringf(const CHB* item, ISW count) : string_(item), count_(count) { Print(item); } #endif #if USING_UTF32 == YES_0 -Stringf::Stringf(const CHC* item, ISW count) : String_(item), count_(count) { +Stringf::Stringf(const CHC* item, ISW count) : string_(item), count_(count) { Print(item); } #endif -Stringf::Stringf(CHA item, ISW count) : String_(buffer_), count_(count) { +Stringf::Stringf(CHA item, ISW count) : string_(buffer_), count_(count) { Print(item); } -Stringf::Stringf(CHB item, ISW count) : String_(buffer_), count_(count) { +Stringf::Stringf(CHB item, ISW count) : string_(buffer_), count_(count) { Print(item); } -Stringf::Stringf(CHC item, ISW count) : String_(buffer_), count_(count) { +Stringf::Stringf(CHC item, ISW count) : string_(buffer_), count_(count) { Print(item); } -Stringf::Stringf(ISC item, ISW count) : String_(buffer_), count_(count) { +Stringf::Stringf(ISC item, ISW count) : string_(buffer_), count_(count) { Print(item); } -Stringf::Stringf(IUC item, ISW count) : String_(buffer_), count_(count) { +Stringf::Stringf(IUC item, ISW count) : string_(buffer_), count_(count) { Print(item); } -Stringf::Stringf(ISD item, ISW count) : String_(buffer_), count_(count) { +Stringf::Stringf(ISD item, ISW count) : string_(buffer_), count_(count) { Print(item); } -Stringf::Stringf(IUD item, ISW count) : String_(buffer_), count_(count) { +Stringf::Stringf(IUD item, ISW count) : string_(buffer_), count_(count) { Print(item); } #if USING_FPC == YES_0 -Stringf::Stringf(FPC item, ISW count) : String_(buffer_), count_(count) { +Stringf::Stringf(FPC item, ISW count) : string_(buffer_), count_(count) { Print(item); } #endif #if USING_FPD == YES_0 -Stringf::Stringf(FPD item, ISW count) : String_(buffer_), count_(count) { +Stringf::Stringf(FPD item, ISW count) : string_(buffer_), count_(count) { Print(item); } #endif -Stringf::Stringf(TypeValue item, ISW count) : String_(buffer_), count_(count) { - Print(item); -} IUW Stringf::Word() { return buffer_[0]; } @@ -641,117 +670,127 @@ void* Stringf::Value() { return buffer_; } void* Stringf::Ptr() { return TPtr(buffer_[0]); } -const CHA* Stringf::STA() { return TPtr(String_); } -const CHB* Stringf::STB() { return TPtr(String_); } -const CHC* Stringf::STC() { return TPtr(String_); } +const CHA* Stringf::STA() { return TPtr(string_); } +const CHB* Stringf::STB() { return TPtr(string_); } +const CHC* Stringf::STC() { return TPtr(string_); } -ISW Stringf::Type() const { return type_; } +ISW Stringf::Type() { return type_; } -ISW Stringf::Count() const { return count_; } +ISW Stringf::Count() { return count_; } void Stringf::Print(const CHA* item) { type_ = _STA; - String_ = item; + string_ = item; } #if USING_UTF16 == YES_0 void Stringf::Print(const CHB* item) { type_ = _STB; - String_ = item; + string_ = item; } #endif #if USING_UTF32 == YES_0 void Stringf::Print(const CHC* item) { type_ = _STC; - String_ = item; + string_ = item; } #endif void Stringf::Print(CHA item) { CHA* buffer = TPtr(buffer_); - _::SPrint(buffer, buffer + cLengthMax, item); + _::SPrint(buffer, buffer + LengthMax, item); type_ = _STA; - String_ = buffer_; + string_ = buffer_; } #if USING_UTF16 == YES_0 void Stringf::Print(CHB item) { CHA* buffer = TPtr(buffer_); - _::SPrint(buffer, buffer + cLengthMax, item); + _::SPrint(buffer, buffer + LengthMax, item); type_ = _STA; - String_ = buffer_; + string_ = buffer_; } #endif #if USING_UTF32 == YES_0 void Stringf::Print(CHC item) { CHA* buffer = TPtr(buffer_); - _::SPrint(buffer, buffer + cLengthMax, item); + _::SPrint(buffer, buffer + LengthMax, item); type_ = _STA; - String_ = buffer; + string_ = buffer; } #endif void Stringf::Print(ISC item) { CHA* buffer = TPtr(buffer_); #if SEAM >= SCRIPT2_ITOS - _::TSPrint(buffer, buffer + cLengthMax, item); + _::TSPrint(buffer, buffer + LengthMax, item); #endif type_ = _STA; - String_ = buffer; + string_ = buffer; } void Stringf::Print(IUC item) { CHA* buffer = TPtr(buffer_); #if SEAM >= SCRIPT2_ITOS - _::TSPrint(buffer, buffer + cLengthMax, item); + _::TSPrint(buffer, buffer + LengthMax, item); #endif type_ = _STA; - String_ = buffer; + string_ = buffer; } void Stringf::Print(ISD item) { CHA* buffer = TPtr(buffer_); #if SEAM >= SCRIPT2_ITOS - _::TSPrint(buffer, buffer + cLengthMax, item); + _::TSPrint(buffer, buffer + LengthMax, item); #endif type_ = _STA; - String_ = buffer; + string_ = buffer; } void Stringf::Print(IUD item) { CHA* buffer = TPtr(buffer_); #if SEAM >= SCRIPT2_ITOS - _::TSPrint(buffer, buffer + cLengthMax, item); + _::TSPrint(buffer, buffer + LengthMax, item); #endif type_ = _STA; - String_ = buffer; + string_ = buffer; } #if USING_FPC == YES_0 void Stringf::Print(FPC item) { CHA* buffer = TPtr(buffer_); - _::TSPrint(buffer, buffer + cLengthMax, item); + _::TSPrint(buffer, buffer + LengthMax, item); type_ = _STA; - String_ = buffer; + string_ = buffer; } #endif #if USING_FPD == YES_0 void Stringf::Print(FPD item) { CHA* buffer = TPtr(buffer_); - _::TSPrint(buffer, buffer + cLengthMax, item); + _::TSPrint(buffer, buffer + LengthMax, item); type_ = _STA; - String_ = buffer; + string_ = buffer; } #endif +/* void Stringf::PrintTMC(TMC item) {} void Stringf::PrintTME(TMC item, IUC subsecond_tick) {} void Stringf::PrintTMD(TMD item) {} +void Stringf::Print(ATypef item) { + CHA* buffer = TPtr(buffer_); +#if SEAM >= SCRIPT2_ITOS + _::TSPrint(buffer, buffer + LengthMax, item); +#endif + type_ = item.type; + string_ = buffer; +} + void Stringf::Print(TypeValue item) { DTW type = item.Type(); type_ = type; - static const CHA kNotSupported[] = "Not supported\0"; + static const CHA NotSupported[] = "Not supported\0"; DTW pod_type = type & ATypePODMask; if (type != pod_type) { // It's not a POD type. } @@ -808,9 +847,16 @@ void Stringf::Print(TypeValue item) { #endif return; } - String_ = kNotSupported; + string_ = NotSupported; } +Stringf::Stringf(ATypef item, ISW count) : string_(buffer_), count_(count) { + Print(item); +} +Stringf::Stringf(TypeValue item, ISW count) : string_(buffer_), count_(count) { + Print(item); +}*/ + void Stringf::Hex(CHA item, ISW count) { *TPtr(buffer_) = item; type_ = _CHA; @@ -916,6 +962,7 @@ Centerf::Centerf(FPC item, ISW count) : element(item, count) {} Centerf::Centerf(FPD item, ISW count) : element(item, count) {} #endif Centerf::Centerf(IUD item, ISW count) : element(item, count) {} +//Centerf::Centerf(Typef item, ISW count) : element(item, count) {} Centerf& Centerf::Hex(CHA item, ISW count) { element.Hex(item, count); @@ -1109,6 +1156,11 @@ Charsf::Charsf(const CHC* start, ISW count) : element(start, count) {} Indentf::Indentf(ISW indent_count) : indent_count(indent_count) {} +Sizef::Sizef(ISA size) : size(size) {} +Sizef::Sizef(ISB size) : size(size) {} +Sizef::Sizef(ISC size) : size(size) {} +Sizef::Sizef(ISD size) : size(size) {} + } //< namespace _ #if SEAM >= SCRIPT2_FTOS @@ -1153,3 +1205,4 @@ const CHA* SScan(const CHA* start, FPD& value) { } } //< namespace _ #endif +#endif diff --git a/Table.hpp b/Table.hpp index d3efc1d..e5c3dde 100644 --- a/Table.hpp +++ b/Table.hpp @@ -579,7 +579,7 @@ class ATable { return TTablePrint(o, This()); } - inline void CPrint() { PrintTo<_::COut>(_::COut().Star()); } + inline void CPrint() { PrintTo<_::COut>(_::StdOut()); } #endif }; diff --git a/Test.hpp b/Test.hpp index 0bba277..380fe22 100644 --- a/Test.hpp +++ b/Test.hpp @@ -6,13 +6,10 @@ This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed with this file, You can obtain one at . */ - #pragma once #include <_Config.h> - #ifndef SCRIPT2_TTEST #define SCRIPT2_TTEST 1 - #include "Test.h" // #include "CIn.h" diff --git a/Test.inl b/Test.inl index 1502099..bfb4bbc 100644 --- a/Test.inl +++ b/Test.inl @@ -7,6 +7,8 @@ This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed with this file, You can obtain one at . */ #include <_Config.h> +#define D_RUN(test_unit) \ + { auto result = test_unit(); if(!result) return result; } #include "Test.h" // #include "COut.h" @@ -14,8 +16,10 @@ one at . */ namespace _ { void TestFunctionLine(ISN line, const CHA* function, const CHA* file) { +#if SEAM >= SCRIPT2_COUT && USING_CONSOLE == YES_0 COut("\n Function:").Print(function) << "\n Line:" << line << " in \"" << file << '\"'; +#endif } BOL TestWarn(ISN line, const CHA* function, const CHA* file) { @@ -46,7 +50,9 @@ const CHA* TestTree(const CHA* args, TestCase* tests, ISN count) { for (ISN i = 0; i < count; ++i) { TestCase test = tests[i]; if (!test) { +#if SEAM >= SCRIPT2_COUT && USING_CONSOLE == YES_0 COut("\nError: seam node ").Print(i) << " is missing!"; +#endif return ""; } const CHA* error = test(args); @@ -57,10 +63,14 @@ const CHA* TestTree(const CHA* args, TestCase* tests, ISN count) { ISN SeamResult(const CHA* result) { if (result) { +#if SEAM >= SCRIPT2_COUT && USING_CONSOLE == YES_0 COut("\n\nError in seam ").Print(result); +#endif return APP_EXIT_FAILURE; } +#if SEAM >= SCRIPT2_COUT && USING_CONSOLE == YES_0 COut("\n\nUnit tests completed successfully! (:-)+==<\n"); +#endif return APP_EXIT_SUCCESS; } @@ -77,9 +87,11 @@ static const CHA cSTRErrorNil[] = "\nERROR: value was nil!\0"; BOL Test(const CHA* a, const CHA* b) { ISN difference = TSTRCompare(a, b); if (!difference) return true; +#if SEAM >= SCRIPT2_COUT && USING_CONSOLE == YES_0 COut("\n\nERROR: Expecting:\"").Print(a) << "\"\n Found:\"" << b << "\"\n Difference:\0" << difference; +#endif return false; } @@ -87,9 +99,11 @@ BOL Test(const CHA* a, const CHA* b) { BOL Test(const CHB* a, const CHB* b) { ISN difference = TSTRCompare(a, b); if (!difference) return true; +#if SEAM >= SCRIPT2_COUT && USING_CONSOLE == YES_0 COut("\n\nERROR: Expecting:\"").Print(a) << "\"\n Found:\"" << b << "\"\n Difference:\0" << difference; +#endif return false; } #endif @@ -97,92 +111,120 @@ BOL Test(const CHB* a, const CHB* b) { BOL Test(const CHC* a, const CHC* b) { ISN difference = TSTRCompare(a, b); if (!difference) return true; +#if SEAM >= SCRIPT2_COUT && USING_CONSOLE == YES_0 COut("\n\nERROR: Expecting:\"").Print(a) << "\"\n Found:\"" << b << "\"\n Difference:\0" << difference; +#endif return false; } #endif BOL Test(CHA a, CHA b) { if (a == b) return true; +#if SEAM >= SCRIPT2_COUT && USING_CONSOLE == YES_0 COut(STRErrorExpecting).Hex(a) << ':' << a << STRFound << Hexf(b) << ':' << b; +#endif return false; } BOL Test(CHB a, CHB b) { if (a == b) return true; +#if SEAM >= SCRIPT2_COUT && USING_CONSOLE == YES_0 COut(STRErrorExpecting).Hex(a) << ':' << a << STRFound << Hexf(b) << ':' << b; +#endif return false; } BOL Test(CHC a, CHC b) { if (a == b) return true; +#if SEAM >= SCRIPT2_COUT && USING_CONSOLE == YES_0 COut(STRErrorExpecting).Hex(a) << ':' << a << STRFound << Hexf(b) << ':' << b; +#endif return false; } BOL Test(const void* a, const void* b) { if (a == b) return true; +#if SEAM >= SCRIPT2_COUT && USING_CONSOLE == YES_0 COut(STRErrorExpecting).Hex(a) << STRFound << Hexf(b); +#endif return false; } BOL Test(IUA a, IUA b) { if (a == b) return true; +#if SEAM >= SCRIPT2_COUT && USING_CONSOLE == YES_0 COut(STRErrorExpecting).Hex(a) << ':' << a << STRFound << Hexf(b) << ':' << b; +#endif return false; } BOL Test(ISA a, ISA b) { if (a == b) return true; +#if SEAM >= SCRIPT2_COUT && USING_CONSOLE == YES_0 COut(STRErrorExpecting).Hex(a) << ':' << a << STRFound << Hexf(b) << ':' << b; +#endif return false; } BOL Test(IUB a, IUB b) { if (a == b) return true; +#if SEAM >= SCRIPT2_COUT && USING_CONSOLE == YES_0 COut(STRErrorExpecting).Hex(a) << ':' << a << STRFound << Hexf(b) << ':' << b; +#endif return false; } BOL Test(ISB a, ISB b) { if (a == b) return true; +#if SEAM >= SCRIPT2_COUT && USING_CONSOLE == YES_0 COut(STRErrorExpecting).Hex(a) << ':' << a << STRFound << Hexf(b) << ':' << b; +#endif return false; } BOL Test(IUC a, IUC b) { if (a == b) return true; +#if SEAM >= SCRIPT2_COUT && USING_CONSOLE == YES_0 COut(STRErrorExpecting).Hex(a) << ':' << a << STRFound << Hexf(b) << ':' << b; +#endif return false; } BOL Test(ISC a, ISC b) { if (a == b) return true; + +#if SEAM >= SCRIPT2_COUT && USING_CONSOLE == YES_0 COut(STRErrorExpecting).Hex(a) << ':' << a << STRFound << Hexf(b) << ':' << b; +#endif return false; } BOL Test(IUD a, IUD b) { if (a == b) return true; +#if SEAM >= SCRIPT2_COUT && USING_CONSOLE == YES_0 COut(STRErrorExpecting).Hex(a) << ':' << a << STRFound << Hexf(b) << ':' << b; +#endif return false; } BOL Test(ISD a, ISD b) { if (a == b) return true; + +#if SEAM >= SCRIPT2_COUT && USING_CONSOLE == YES_0 COut(STRErrorExpecting).Hex(a) << ':' << a << STRFound << Hexf(b) << ':' << b; +#endif return false; } diff --git a/Types.h b/Types.h index d06b547..8ba286e 100644 --- a/Types.h +++ b/Types.h @@ -12,11 +12,17 @@ one at . */ #define SCRIPT2_TYPES_DECL namespace _ { +// Packs the given ASCII Type bitfield values into a DTB. +DTB ATypePack(DTB pod, DTB vt); +DTB ATypePack(DTB pod, DTB vt, DTB sw); +DTB ATypePack(DTB pod, DTB vt, DTB sw, DTB mt); +DTB ATypePack(DTB pod, DTB vt, DTB sw, DTB mt, DTB mod); + // Returns true if the given type is CHA, CHB, or CHC. BOL ATypeIsCH(DTB type); // Returns the size of the given type in bytes. -ISA ATypeSizeBytesPOD(DTB type); +ISA ATypeSizeOfPOD(DTB type); /* Returns the size of the given type in bytes. @return the size bytes of the value. */ @@ -35,18 +41,14 @@ const ISA* ATypeCustomAlignMask(); // Returns the custom time alignment mask for the given type. ISA ATypeCustomAlignMask(DTA type); -/* Utility class for printing an ASCII type. */ -struct Typef { - DTW type; //< The item type. - CHA* string; //< The ASCII type string. -}; - /* Stores a pointer to the ASCII data type and it's value. */ struct TypeWordValue { - DTW type; //< The ASCII data type word. + DTW type; //< The ASCII data type word. void* value; //< Pointer to the value of the type. }; +inline ISA TypeTextFormat(DTW type); + /* An ASCII Type-Value tuple. An TypeValue can only work with up to two CPU ALU words because when a CPU multiplies two integers together the result is two ALU-sized words and thus the @@ -161,12 +163,6 @@ class LIB_MEMBER TypeValue { #endif }; -/* Utility class for printing the size of ASCII TypeValues. -@see CSizef */ -struct Sizef { - ISW size; //< The size of the item in ? -}; - } //< namespace _ #endif diff --git a/Types.hpp b/Types.hpp index b2ccf14..05768ba 100644 --- a/Types.hpp +++ b/Types.hpp @@ -7,8 +7,8 @@ Form is subject to the terms of the Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed with this file, You can obtain one at . */ #pragma once -#ifndef INCLUDED_TYPEVALUE_CODE -#define INCLUDED_TYPEVALUE_CODE +#ifndef INCLUDED_TYPES_CODE +#define INCLUDED_TYPES_CODE #include "Types.h" namespace _ { @@ -26,51 +26,6 @@ struct TTypeValueOffset { IS value; //< Offset to the value of the type. }; -/* Gets the log_b. */ -template -constexpr Sizef TSizef () { - Sizef result = {0}; - switch (sizeof(T)) { - case 1: { - result.size = -1; - break; - } - case 2: { - result.size = -2; - break; - } - case 4: { - result.size = -3; - break; - } - case 8: { - result.size = -4; - break; - } - case 16: { - result.size = -5; - break; - } - case 32: { - result.size = -6; - break; - } - case 64: { - result.size = -7; - break; - } - case 128: { - result.size = -8; - break; - } - default: { - result.size = sizeof(T); - break; - } - } - return result; -} - /* An 8-bit, 16-bit, or 32-bit ASCII Data Type. */ template class TType { @@ -102,6 +57,21 @@ constexpr DT CTypeMap(DTW type) { return DT((type >> 8) & 3); } +/* Copies the source to the destination. +This function is different in that it +@return nullptr if the destination does not have enough space. */ +template +void* TMapCopy(void* destination, const void* source) { + auto dst = static_cast(destination); + auto src = static_cast(source); + auto dst_count = *dst; + auto src_count = *src; + if (dst_count < src_count) return nullptr; + auto result = RAMCopy(dst, dst_count, src, src_count); + if (result <= 0) return nullptr; + return static_cast(dst); +} + /* Creates an ASCII Vector Data Type. */ template inline DT TTypeVector(DTW pod_type, DTW vector_type, DTW width_bit_count = 0) { @@ -123,9 +93,11 @@ inline DT TTypeMap(DTW pod_type, DTW map_type, DTW width_bit_count = 0) { return DT(pod_type | (map_type << 9) | (width_bit_count << 14)); } + + /* The ASCII Data Type mask for the SW (Size Width) bits. */ template -constexpr DT CTypeSize() { +constexpr DT CATypeSize() { return (sizeof(IS) == 1) ? _SWA : (sizeof(IS) == 2) ? _SWB : (sizeof(IS) == 4) ? _SWC @@ -135,13 +107,63 @@ constexpr DT CTypeSize() { /* The ASCII Data Type mask for the SW (Size Width) bits. */ template -constexpr DT CTypeSize(DT pod_type) { - return pod_type | (CTypeSize() << 7); +constexpr DT CATypeSize(DT pod_type) { + return pod_type | (CATypeSize() << 7); } template -inline DT TTypeSize(DT pod_type) { - return pod_type | (CTypeSize() << 7); +inline DT TATypeSize(DT pod_type) { + return pod_type | (CATypeSize() << 7); +} + +template +IS TATypeSizeOf(const void* value, DTB type) { + if (type < ATypePODCount) + return ATypeSizeOfPOD(type); + // | b15:b14 | b13:b9 | b8:b7 | b6:b5 | b4:b0 | + // |:-------:|:------:|:-----:|:-----:|:-----:| + // | MOD | MT | SW | VT | POD | + auto mod = type >> ATypeMODBit0; + if (mod && 1) return sizeof(void*); + type ^= mod << ATypeMODBit0; + auto mt = type >> ATypeMTBit0; + type ^= mt << ATypeMTBit0; + auto sw = type >> ATypeSWBit0; + type ^= sw << ATypeSWBit0; + auto vt = type >> ATypeVTBit0; + type ^= vt << ATypeVTBit0; + if (vt == 0) return ISW(sw) * ATypeSizeOfPOD(type); + IS size = 1; + switch (sw) { + case 0: + size = IS(*static_cast(value)); + break; + case 1: + size = IS(*static_cast(value)); + break; + case 2: + size = IS(*static_cast(value)); + break; + case 3: + size = IS(*static_cast(value)); + break; + } + return size * sw; +} + +template +IS TATypeSizeOf(void* value, DTB type) { + return TATypeSizeOf((const void*)value, type); +} +template +IS TATypeSizeOf(const void* value_base, IS size_bytes, DTB type) { + const IUA* vbase = (const IUA*)value_base; + return TATypeSizeOf(vbase + size_bytes, type); +} +template +IS TATypeSizeOf(void* value_base, IS size_bytes, DTB type) { + const void* vbase = (const void*)value_base; + return TATypeSizeOf(vbase, size_bytes, type); } /* Returns the ASCII Type for the given floating-point type FP. @@ -152,7 +174,7 @@ FPE: 16 0b10000 (0b100 << 2) | 0b00 */ template constexpr DT CTypeFP() { - return (CTypeSize() << 2); + return (CATypeSize() << 2); } /* Returns the ASCII Type for the given unsigned integer type IS. @@ -164,7 +186,7 @@ IUE: 17 0b10001 (0b100 << 2) | 0b01 */ template constexpr DT CTypeIU() { - return (CTypeSize() << 2) | 1; + return (CATypeSize() << 2) | 1; } /* Returns the ASCII Type for the given signed integer type IS. @@ -176,7 +198,7 @@ ISE: 18 0b10010 (0b100 << 2) | 0b10 */ template constexpr DT CTypeIS() { - return (CTypeSize() << 2) | 2; + return (CATypeSize() << 2) | 2; } /* Returns the ASCII Type for the given character type CH. @@ -187,16 +209,31 @@ CHE: 15 0b1111 (0b11 << 2) | 0b11 */ template constexpr DT CTypeCH() { - return (CTypeSize() << 2) | 3; + return (CATypeSize() << 2) | 3; +} + +/* Extracts the UTF type. +@return 0 if the type is not a stirng type or 1, 2, or 4 if it is. */ +inline ISA TypeTextFormat(DTW type) { + DTW core_type = type & ATypePODMask; + if (core_type == 0) return -1; //< then core_type < 32 + if (core_type <= _STC) { + if (core_type == _NIL) return -1; + return ISA(type); + } + if (core_type == type) return -1; //< then core_type < 32 + if (core_type == _CHA) return 1; + if (core_type == _CHB) return 2; + if (core_type <= _CHC) return 3; + return -1; } } //< namespace _ -#if SEAM >= SCRIPT2_CORE -#include "Binary.hpp" -#include "Stringf.hpp" +#if SEAM >= SCRIPT2_COUT +#include "Uniprinter.hpp" -#if SEAM == SCRIPT2_CORE +#if SEAM == SCRIPT2_COUT #include "_Debug.inl" #else #include "_Release.inl" @@ -218,8 +255,8 @@ inline DTW AlignmentMask(FPC item) { return 3; } inline DTW AlignmentMask(ISD item) { return 7; } inline DTW AlignmentMask(IUD item) { return 7; } inline DTW AlignmentMask(FPD item) { return 7; } -inline DTW AlignmentMask(void* item) { return WordLSbMask; } -inline DTW AlignmentMask(const void* item) { return WordLSbMask; } +inline DTW AlignmentMask(void* item) { return ACPUAlignMask; } +inline DTW AlignmentMask(const void* item) { return ACPUAlignMask; } /* Gets the type of the given item. */ inline DTW TypeOf(CHA item) { return _CHA; } @@ -245,27 +282,43 @@ inline BOL TSizeIsValid(IS size) { return (size & (sizeof(IS) - 1)) == 0; } -/* An ROM for one of the 32 types. +/* A ROM for one of the 32 types. C++11 variadic templates ensure there is only one copy in of the given in ROM. -*/ + template inline IUC T() { return ((IUC)CharA) & (((IUC)CharB) << 8) & (((IUC)CharC) << 16); -} +}*/ // Returns the memory alignment mask for this type. ISA ATypeAlignMask(DTB type) { + enum { + AlignC = sizeof(void*) == 2 ? 1 : 3, + AlignD = sizeof(void*) == 2 ? 1 + : sizeof(void*) == 4 ? 3 + : sizeof(void*) == 8 ? 7 : 0 + }; if (type <= _CHA) return 0; if (type <= _CHB) return 1; -#if CPU_SIZE == CPU_2_BYTE - if (type < _BOL) return 1; -#elif CPU_SIZE == CPU_4_BYTE - if (type < _BOL) return 3; -#elif CPU_SIZE == CPU_8_BYTE if (type <= _CHC) return 3; - if (type < _BOL) return 7; -#endif - return ATypeCustomAlignMask(type - _BOL); + if (type <= _ISE) return 7; + if (type < ATypePODCount) return ATypeCustomAlignMask()[type - _BOL]; + DTB mod = type >> ATypeMODBit0; + type ^= mod << ATypeMODBit0; + DTB mt = type >> ATypeMTBit0; + type ^= mt << ATypeMTBit0; + DTB sw = type >> ATypeSWBit0; + type ^= sw << ATypeSWBit0; + DTB vt = type >> ATypeVTBit0; + type ^= vt << ATypeVTBit0; + if (vt == 0) return sw * ATypeAlignMask(type); //< Vetor of 2 to 4 Homo-tuples + switch (sw) { + case 0: return 0; + case 1: return 0; + case 2: return AlignC; + case 3: return AlignD; + } + return ACPUAlignMask; } /* Aligns the pointer up to the word boundry required by the type. */ @@ -275,39 +328,6 @@ T* TTypeAlignUp(void* pointer, ISW type) { return TPtr(AlignUpPTR(pointer, align_mask)); } -/* Gets the size of the type in bytes. -@return A postivie size_bytes if the type is a POD type; 0 if the type is an -Object type; or -1 if the value is a STR. */ -inline ISW TypeSizeOf(DTW type) { - if (type == 0) return WordLSbMask; - if (type <= _IUA) return 0; - if (type <= _FPB) return 1; - if (type <= _TME) sizeof(ISN) - 1; - return sizeof(ISW) - 1; -} - -/* Checks if the given type is valid. @todo Possibly delete. -@return False if the given type is an 1-byte LST, MAP, BOK, or DIC. -inline BOL TypeIsSupported(DTW type) { - return true; -} */ - -/* Extracts the UTF type. -@return 0 if the type is not a stirng type or 1, 2, or 4 if it is. */ -inline ISA TypeTextFormat(DTW type) { - DTW core_type = type & ATypePODMask; - if (core_type == 0) return -1; //< then core_type < 32 - if (core_type <= _STC) { - if (core_type == _NIL) return -1; - return ISA(type); - } - if (core_type == type) return -1; //< then core_type < 32 - if (core_type == _CHA) return 1; - if (core_type == _CHB) return 2; - if (core_type <= _CHC) return 3; - return -1; -} - /* Masks off the primary type. */ inline ISA TypeMaskPOD(DTW value) { return value & 0x1f; } diff --git a/Types.inl b/Types.inl index 2b209c3..b806303 100644 --- a/Types.inl +++ b/Types.inl @@ -7,13 +7,30 @@ This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed with this file, You can obtain one at . */ #include "Types.hpp" -#if SEAM == SCRIPT2_CORE +#if SEAM == SCRIPT2_COUT #include "_Debug.inl" #else #include "_Release.inl" #endif namespace _ { +DTB ATypePack(DTB pod, DTB vt) { + return pod | vt << ATypeVTBit0; +} + +DTB ATypePack(DTB pod, DTB vt, DTB sw) { + return pod | vt << ATypeVTBit0 | sw << ATypeSWBit0; +} + +DTB ATypePack(DTB pod, DTB vt, DTB sw, DTB mt) { + return pod | vt << ATypeVTBit0 | sw << ATypeSWBit0 | mt << ATypeMTBit0; +} + +DTB ATypePack(DTB pod, DTB vt, DTB sw, DTB mt, DTB mod) { + return pod | vt << ATypeVTBit0 | sw << ATypeSWBit0 | mt << ATypeMTBit0 | + mod << ATypeMODBit0; +} + BOL ATypeIsCH(DTB type) { // CHA: 3 0b0011 // CHB: 7 0b0111 @@ -70,11 +87,11 @@ const ISA* ATypeCustomAlignMask() { } ISA ATypeCustomAlignMask(DTA type) { - if (type >= ATypePODCount) return sizeof(ISW) - 1; + if (type < _BOL || type >= ATypePODCount) return sizeof(ISW) - 1; return ATypeCustomAlignMask()[type - _BOL]; } -ISA ATypeSizeBytesPOD(DTB type) { +ISA ATypeSizeOfPOD(DTB type) { if (type == 0 || type >= ATypePODCount) return 0; if (type < _FPB) return 1; if (type < _FPC) return 2; @@ -84,39 +101,8 @@ ISA ATypeSizeBytesPOD(DTB type) { return ATypeCustomSize()[type - _BOL]; } - ISW ATypeSizeBytes(void* value, DTB type) { - if (type < ATypePODCount) - return ATypeSizeBytesPOD(type); - // | b15:b14 | b13:b9 | b8:b7 | b6:b5 | b4:b0 | - // |:-------:|:------:|:-----:|:-----:|:-----:| - // | MOD | MT | SW | VT | POD | - auto mod = type >> ATypeMODBit0; - if (mod && 1) return sizeof(void*); - type ^= mod << ATypeMODBit0; - auto mt = type >> ATypeMTBit0; - type ^= mt << ATypeMTBit0; - auto sw = type >> ATypeSWBit0; - type ^= sw << ATypeSWBit0; - auto vt = type >> ATypeVTBit0; - type ^= vt << ATypeVTBit0; - if (vt == 0) return ISW(sw) * ATypeSizeBytesPOD(type); - ISW size = 0; - switch (sw) { - case 0: - size = ISW(*TPtr(value)); - break; - case 1: - size = ISW(*TPtr(value)); - break; - case 2: - size = ISW(*TPtr(value)); - break; - case 3: - size = ISW(*TPtr(value)); - break; - } - return size * sw; + return TATypeSizeOf(value, type); } ISW ATypeSizeBytes(void* value_base, ISA size_bytes, DTB type) { diff --git a/Uniprinter.hpp b/Uniprinter.hpp index 4905846..5f3dffc 100644 --- a/Uniprinter.hpp +++ b/Uniprinter.hpp @@ -7,74 +7,77 @@ This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed with this file, You can obtain one at . */ #pragma once -#include <_Config.h> -#ifndef SCRIPT2_UNIPRINTER_TEMPLATES -#define SCRIPT2_UNIPRINTER_TEMPLATES -#include "Stringf.h" -#include "Types.hpp" +#ifndef SCRIPT2_STRING_CODE +#define SCRIPT2_STRING_CODE +#include "Stringf.hpp" +#if SEAM >= SCRIPT2_COUT +#include "Binary.hpp" +#include "Puff.hpp" + namespace _ { /* Prints the given string to the Printer. */ template -Printer& TSPrintString(Printer& o, const CHT* string) { - if (!string) return o; +Printer& TSPrintString(Printer& p, const CHT* string) { + if (!string) return p; CHL c = 0; string = SScan(string, c); while (c) { - o << c; + p << c; string = SScan(string, c); } - return o; + return p; } /* Prints the given string to the Printer and returns the count of characters printed. */ template -ISN TPrintAndCount(Printer& o, const CHT* string) { +ISN TPrintAndCount(Printer& p, const CHT* string) { if (!string) return 0; ISN print_count = 0; CHL c = 0; string = SScan(string, c); while (c) { - o << c; + p << c; ++print_count; string = SScan(string, c); } return print_count; } + /* Prints the following value to the console in Hex. */ template -Printer& TPrintHex(Printer& o, IU value) { +Printer& TPrintHex(Printer& p, IU value) { enum { cHexStringLengthSizeMax = sizeof(IU) * 2 + 3 }; auto ui = ToUnsigned(value); for (ISC num_bits_shift = sizeof(IU) * 8 - 4; num_bits_shift >= 0; - num_bits_shift -= 4) { - o << HexNibbleToUpperCase((IUA)(ui >> num_bits_shift)); + num_bits_shift -= 4) { + p << HexNibbleToUpperCase((IUA)(ui >> num_bits_shift)); } - return o; + return p; } /* Prints the following value to the console in Hex. */ template -Printer& TPrintHex(Printer& o, const void* value) { +Printer& TPrintHex(Printer& p, const void* value) { IUW ptr = IUW(value); - return TPrintHex(o, ptr); + return TPrintHex(p, ptr); } template -Printer& TPrintHex(Printer& o, IS value) { - return TPrintHex(o, IU(value)); +Printer& TPrintHex(Printer& p, IS value) { + return TPrintHex(p, IU(value)); } #if USING_FPC == YES_0 template -Printer& TPrintHex(Printer& o, FPC value) { - return TPrintHex(o, *TPtr(&value)); +Printer& TPrintHex(Printer& p, FPC value) { + return TPrintHex(p, *TPtr(&value)); } #endif #if USING_FPD == YES_0 template -Printer& TPrintHex(Printer& o, FPD value) { - return TPrintHex(o, *TPtr(&value)); +Printer& TPrintHex(Printer& p, FPD value) { + return TPrintHex(p, *TPtr(&value)); } #endif /* Prints the given hex memory block or POD value depending on the sign of the @@ -87,17 +90,18 @@ which is frutrating because of how simple the conversion code is. If the byte_count is greater than zero then the memory will be printed sequentially one byte at a time. */ template -Printer& TPrintHex(Printer& o, const void* origin, ISW byte_count) { - if (!origin) return o; +Printer& TPrintHex(Printer& p, const void* origin, ISW byte_count) { + if (!origin) return p; ISW delta; const IUA* cursor = TPtr(origin); #if CPU_ENDIAN == CPU_ENDIAN_LITTLE - // We have to print the hex value backwards. + // Print the hex value backwards. if (byte_count < 0) { byte_count = -byte_count; delta = -1; cursor += byte_count - 1; - } else { + } + else { delta = 1; } #else @@ -110,95 +114,91 @@ Printer& TPrintHex(Printer& o, const void* origin, ISW byte_count) { #else IUA byte = *cursor++; #endif - o << HexNibbleToUpperCase(byte >> 4) << HexNibbleToUpperCase(byte & 0xf); + p << HexNibbleToUpperCase(byte >> 4) << HexNibbleToUpperCase(byte & 0xf); } - return o; + return p; } template -Printer& TPrintHex(Printer& o, const void* start, const void* stop) { +Printer& TPrintHex(Printer& p, const void* start, const void* stop) { ISW delta = ISW(stop) - ISW(start); - return TPrintHex(o, start, delta); + return TPrintHex(p, start, delta); } -/* Prints the memory beginning at start to the Printer. */ template -Printer& TPrintBinary(Printer& o, const void* start, ISW byte_count) { - if (!start) return o; - const IUA* cursor = TPtr(start); -#if CPU_ENDIAN == CPU_ENDIAN_LITTLE - ISA delta; - if (byte_count < 0) { - delta = -1; - byte_count = -byte_count; - cursor += byte_count - 1; - } else { - delta = 1; - } -#endif - while (--byte_count >= 0) { - IUA c = *cursor; - cursor += delta; - for (ISW i = 8; i > 0; --i) { - o << CHA('0' + (c >> 7)); - c = c << 1; - } - } - return o; +Printer& TPrint(Printer& p, Hexf& item) { + return TPrintHex(p, item.element.Value(), item.element.count); } template -inline Printer& TPrintBinary(Printer& o, const void* start, const void* stop) { +inline Printer& TPrintBinary(Printer& p, const void* start, const void* stop) { ISW delta = ISW(stop) - ISW(start); - return TPrintBinary(o, start, TPtr(delta)); + return TPrintBinary(p, start, TPtr(delta)); } template -Printer& TPrintBinary(Printer& o, IU value) { - enum { cSize = sizeof(IU) * 8 }; +Printer& TPrintBinary(Printer& p, IU value) { + enum { Size = sizeof(IU) * 8 }; auto ui = ToUnsigned(value); - for (ISC i = cSize; i > 0; --i) { - CHA c = CHA('0' + (ui >> (cSize - 1))); - o << c; + for (ISC i = Size; i > 0; --i) { + CHA c = CHA('0' + (ui >> (Size - 1))); + p << c; ui = ui << 1; } - return o; + return p; } template -Printer& TPrintBinary(Printer& o, IS value) { - return TPrintBinary(o, (IU)value); +Printer& TPrintBinary(Printer& p, IS value) { + return TPrintBinary(p, (IU)value); } #if USING_FPC == YES_0 template -Printer& TPrintBinary(Printer& o, FPC value) { - return TPrintBinary(o, *TPtr(&value)); +Printer& TPrintBinary(Printer& p, FPC value) { + return TPrintBinary(p, *TPtr(&value)); } #endif #if USING_FPC == YES_0 template -Printer& TPrintBinary(Printer& o, FPD value) { - return TPrintBinary(o, *TPtr(&value)); +Printer& TPrintBinary(Printer& p, FPD value) { + return TPrintBinary(p, *TPtr(&value)); } #endif template -Printer& TPrintAligned(Printer& o, const CHA* string, ISW char_count, - ISW left_count, ISW dot_count, ISW right_count) { - while (--left_count > 0) o << ' '; +Printer& TPrint(Printer& p, Binaryf& item) { + return TPrintBinary(p, item.element.Value(), item.element.count); +} + +template +Printer& TPrintAligned(Printer& p, const CHA* string, ISW char_count, + ISW left_count, ISW dot_count, ISW right_count) { + while (--left_count > 0) p << ' '; while (--char_count > 0) { -#if LARGEST_CHAR == 1 || SEAM < SCRIPT2_CORE - o << *string++; +#if LARGEST_CHAR == 1 || SEAM < SCRIPT2_COUT + p << *string++; #else CHL c; string = SScan(string, c); - if (!string) return o; - o << c; + if (!string) return p; + p << c; #endif } - while (--dot_count > 0) o << ' '; - while (--right_count > 0) o << ' '; - return o; + while (--dot_count > 0) p << ' '; + while (--right_count > 0) p << ' '; + return p; +} + +template +Printer& TPrintAlignedHex(Printer& p, const void* origin, ISW byte_count, + ISW left_count, ISW dot_count, ISW right_count) { + const CHA* cursor = TPtr(origin); + while (--left_count > 0) p << ' '; + // TPrintHex(p, origin, byte_count >> 1); + TPrintHex(p, cursor, -byte_count); + while (--dot_count > 0) p << ' '; + while (--right_count > 0) p << ' '; + return p; } /* Prints the given token aligned center the given column_count. @@ -207,58 +207,48 @@ pointer to the nil-term CHA upon success. @param token The token to utf. @param column_count The number_ of columns to align right to. */ template -Printer& TPrintCenter(Printer& o, const CHT* value, ISW column_count = 80) { - if (!value || column_count < 1) return o; +Printer& TPrintCenter(Printer& p, const CHT* value, ISW column_count = 80) { + if (!value || column_count < 1) return p; const CHT* token_end = TSTREnd(value); - if (value == token_end) return o; + if (value == token_end) return p; ISW length = token_end - value, space_count = column_count - length; if (space_count > 0) { ISW half_count = space_count >> 1; space_count -= half_count; - while (half_count-- > 0) o << ' '; - o << value; - while (space_count-- > 0) o << ' '; - return o; + while (half_count-- > 0) p << ' '; + p << value; + while (space_count-- > 0) p << ' '; + return p; } length = (-length) - 3; if (length < 0) { - while (--length > 0) o << '.'; - } else { - while (length > 0) o << *value++; - o << "..."; + while (--length > 0) p << '.'; } - return o; -} - -template -Printer& TPrintAlignedHex(Printer& o, const void* origin, ISW byte_count, - ISW left_count, ISW dot_count, ISW right_count) { - const CHA* cursor = TPtr(origin); - while (--left_count > 0) o << ' '; - // TPrintHex(o, origin, byte_count >> 1); - TPrintHex(o, cursor, -byte_count); - while (--dot_count > 0) o << ' '; - while (--right_count > 0) o << ' '; - return o; + else { + while (length > 0) p << *value++; + p << "..."; + } + return p; } /* Prints th given value centered unless it's count is less then 0, in which case it will print the POD value stored in the first Word of the string. */ template -Printer& TPrintCenter(Printer& o, Stringf& value) { +Printer& TPrintCenter(Printer& p, Stringf& value) { ISW column_count = value.Count(); if (column_count < 0) { // Print hex. column_count = -column_count; - ISW byte_count = TypeSizeOf(value.Type()), left_count, dot_count; - if (byte_count < 0) return o; + ISW byte_count = ATypeSizeOfPOD(DTB(value.Type())), left_count, dot_count; + if (byte_count < 0) return p; byte_count = byte_count << 1; ISW right_count; if (byte_count > column_count) { - while (--column_count > 0) o << ' '; - return o; - } else { + while (--column_count > 0) p << ' '; + return p; + } + else { left_count = (column_count - byte_count) >> 1; dot_count = 0; right_count = column_count - left_count - byte_count; @@ -271,28 +261,34 @@ Printer& TPrintCenter(Printer& o, Stringf& value) { "\n left_count:" << left_count << "\n dot_count:" << dot_count << "\n right_count:" << right_count);*/ - return TPrintAlignedHex(o, value.Value(), byte_count >> 1, - left_count, dot_count, right_count); + return TPrintAlignedHex(p, value.Value(), byte_count >> 1, + left_count, dot_count, right_count); } ISW utf_format = _::TypeTextFormat(value.Type()); switch (utf_format) { #if USING_UTF8 == YES_0 - case 1: { - return _::TPrintCenter(o, value.STA(), column_count); - } + case 1: { + return _::TPrintCenter(p, value.STA(), column_count); + } #endif #if USING_UTF16 == YES_0 - case 2: { - return _::TPrintCenter<_::COut, CHB>(o, value.STB(), column_count); - } + case 2: { + return _::TPrintCenter(p, value.STB(), column_count); + } #endif #if USING_UTF32 == YES_0 - case 3: { - return _::TPrintCenter(o, value.STC(), column_count); - } + case 3: { + return _::TPrintCenter(p, value.STC(), column_count); + } #endif } - return o; + return p; +} + +/* Prints the given cursor center aligned to the given column_count. */ +template +inline Printer& TPrint(Printer& p, Centerf& item) { + return TPrintCenter(p, item.element); } /* Prints the given token aligned right the given column_count. @@ -301,44 +297,45 @@ pointer to the nil-term CHA upon success. @param token The token to utf. @param column_count The number_ of columns to align right to. */ template -Printer& TPrintRight(Printer& o, const CHT* value, ISW column_count = 80) { - if (!value || column_count < 1) return o; +Printer& TPrintRight(Printer& p, const CHT* value, ISW column_count = 80) { + if (!value || column_count < 1) return p; const CHT* token_end = TSTREnd(value); - if (value == token_end) return o; + if (value == token_end) return p; ISW length = token_end - value, space_count = column_count - length; if (space_count > 0) { - while (space_count-- > 0) o << ' '; - o << value; - return o; + while (space_count-- > 0) p << ' '; + p << value; + return p; } length = (-length) - 3; if (length < 0) { switch (length) { - case 1: - o << '.'; - case 2: - o << ".."; - case 3: - o << "..."; + case 1: + p << '.'; + case 2: + p << ".."; + case 3: + p << "..."; } - } else { - while (length > 0) o << *value++; - o << "..."; } - return o; + else { + while (length > 0) p << *value++; + p << "..."; + } + return p; } /* Prints the given value centered, printing it as hex if the value.Count() is less than 0. */ template -Printer& TPrintRight(Printer& o, Stringf& value) { +Printer& TPrintRight(Printer& p, Stringf& value) { ISW column_count = value.Count(); if (column_count < 0) { // Print hex. column_count = -column_count; - ISW char_count = TypeSizeOf(value.Type()); - if (char_count < 0) return o; + ISW char_count = ATypeSizeOfPOD(DTB(value.Type())); + if (char_count < 0) return p; ISW left_count, dot_count; if (char_count > column_count) { @@ -346,55 +343,49 @@ Printer& TPrintRight(Printer& o, Stringf& value) { if (column_count < 3) { char_count = 0; dot_count = column_count; - } else { + } + else { char_count = column_count - 3; dot_count = 3; } - } else { + } + else { left_count = column_count - char_count; dot_count = 0; } - return TPrintAlignedHex(o, value.STA(), char_count, left_count, - dot_count, 0); + return TPrintAlignedHex(p, value.STA(), char_count, left_count, + dot_count, 0); } ISW count = value.Count(); switch (_::TypeTextFormat(value.Type())) { #if USING_UTF8 == YES_0 - case 1: { - return _::TPrintRight(o, value.STA(), count); - } + case 1: { + return _::TPrintRight(p, value.STA(), count); + } #endif #if USING_UTF16 == YES_0 - case 2: { - return _::TPrintRight(o, value.STB(), count); - } + case 2: { + return _::TPrintRight(p, value.STB(), count); + } #endif #if USING_UTF32 == YES_0 - case 3: { - return _::TPrintRight(o, value.STC(), count); - } + case 3: { + return _::TPrintRight(p, value.STC(), count); + } #endif } - return o; + return p; } template -Printer& TPrintIndent(Printer& o, ISW indent_count) { - o << '\n'; - while (--indent_count >= 0) o << ' '; - return o; +Printer& TPrint(Printer& p, Rightf& item) { + return TPrintRight(p, item.element); } template -Printer& TPrintRepeat(Printer& o, CHT c, ISW count) { - while (--count >= 0) o << c; - return o; -} - -template -const CHT* TSTRLinef() { - static const CHT kString[] = {'\n', '\n', '-', '-', '-', '\n', NIL}; - return kString; +Printer& TPrintRepeat(Printer& p, CHT c, ISW count) { + while (--count >= 0) p << c; + return p; } /* Prints a formatted lines. @@ -424,44 +415,44 @@ TPrintBreak ("- \n---\n---\n\n Foo\n\n---\n---", 10); @endcode */ template -const CHT* TPrintLinef(Printer& o, const CHT* style = nullptr, - ISW column_count = 80) { +const CHT* TPrintLinef(Printer& p, const CHT* style = nullptr, + ISW column_count = 80) { enum { - cStateScanningDifferentChars = 0, - cStateStateDuplicateChar = 1, - cBreakCount = 3, + StateScanningDifferentChars = 0, + StateStateDuplicateChar = 1, + BreakCount = 3, }; if (!style) style = TSTRLinef(); - if (column_count < cBreakCount) return nullptr; + if (column_count < BreakCount) return nullptr; - ISW state = cStateScanningDifferentChars; + ISW state = StateScanningDifferentChars; CHT current_char = *style++, // - prev_char = ~current_char; + prev_char = ~current_char; ISC hit_count = 0, column_index = 0; while (current_char) { - o << current_char; + p << current_char; if (current_char == '\n') column_index = 0; else ++column_index; switch (state) { - case cStateScanningDifferentChars: { - if (current_char == prev_char && !TIsWhitespace(current_char)) { - state = cStateStateDuplicateChar; - hit_count = 1; - } - break; + case StateScanningDifferentChars: { + if (current_char == prev_char && !TIsWhitespace(current_char)) { + state = StateStateDuplicateChar; + hit_count = 1; } - case cStateStateDuplicateChar: { - if (current_char != prev_char) - state = cStateScanningDifferentChars; - else if (++hit_count >= cBreakCount - 1) { - TPrintRepeat(o, current_char, - column_count - column_index); - column_index = hit_count = 0; - } - break; + break; + } + case StateStateDuplicateChar: { + if (current_char != prev_char) + state = StateScanningDifferentChars; + else if (++hit_count >= BreakCount - 1) { + TPrintRepeat(p, current_char, + column_count - column_index); + column_index = hit_count = 0; } + break; + } } prev_char = current_char; current_char = *style++; @@ -470,322 +461,327 @@ const CHT* TPrintLinef(Printer& o, const CHT* style = nullptr, } template -Printer& TPrintLine(Printer& o, CHT token = '-', ISW column_count = 80) { - o << '\n'; - TPrintRepeat(o, token, column_count); - return o << '\n'; +Printer& TPrintLine(Printer& p, CHT token = '-', ISW column_count = 80) { + p << '\n'; + TPrintRepeat(p, token, column_count); + return p << '\n'; } template -Printer& TPrintLinef(Printer& o, Linef& value) { +Printer& TPrint(Printer& p, Linef& value) { ISW type = value.element.value.Type(), // - utf_format = _::TypeTextFormat(type); + utf_format = _::TypeTextFormat(type); switch (utf_format) { #if USING_UTF8 == YES_0 - case _STA: { - _::TPrintLinef(o, value.element.ToSTA(), value.element.count); - break; - } + case _STA: { + _::TPrintLinef(p, value.element.ToSTA(), value.element.count); + break; + } #endif #if USING_UTF16 == YES_0 - case _STB: { - _::TPrintLinef(o, value.element.ToSTB(), value.element.count); - break; - } + case _STB: { + _::TPrintLinef(p, value.element.ToSTB(), value.element.count); + break; + } #endif #if USING_UTF32 == YES_0 - case _STC: { - const CHC* start = TPtr(value.element.value.ToPTR()); - _::TPrintLinef(o, value.element.ToSTC(), value.element.count); - break; - } + case _STC: { + const CHC* start = TPtr(value.element.value.ToPTR()); + _::TPrintLinef(p, value.element.ToSTC(), value.element.count); + break; + } #endif - case -1: { - switch (type & ATypePODMask) { + case -1: { + switch (type & ATypePODMask) { #if USING_UTF8 == YES_0 - case _CHA: { - CHA c = (CHA)value.element.value.Word(); - _::TPrintLine(o, c, value.element.count); - break; - } + case _CHA: { + CHA c = (CHA)value.element.value.Word(); + _::TPrintLine(p, c, value.element.count); + break; + } #endif #if USING_UTF16 == YES_0 - case _CHB: { - CHB c = (CHB)value.element.value.Word(); - _::TPrintLine(o, c, value.element.count); - break; - } + case _CHB: { + CHB c = (CHB)value.element.value.Word(); + _::TPrintLine(p, c, value.element.count); + break; + } #endif #if USING_UTF32 == YES_0 - case _CHC: { - CHC c = (CHC)value.element.value.Word(); - _::TPrintLine(o, c, value.element.count); - break; - } + case _CHC: { + CHC c = (CHC)value.element.value.Word(); + _::TPrintLine(p, c, value.element.count); + break; + } #endif - } } } - return o; + } + return p; } -template +template const CHT* TSTRHeadingf() { - static const CHT kString[] = {'\n', '\n', '+', '-', '-', '-', '\n', '|', ' ', - NIL, '\n', '+', '-', '-', '-', '\n', NIL}; - return kString; + static const CHT String[] = { '\n', '\n', '+', '-', '-', '-', '\n', '|', ' ', + NIL, '\n', '+', '-', '-', '-', '\n', NIL }; + return String; } /* Prints a heading with the */ template -Printer& TPrintHeadingf(Printer& o, const CHT* element, - const CHA* style = nullptr, ISW column_count = 80, - const CHA* caption2 = nullptr, - const CHA* caption3 = nullptr) { +Printer& TPrintHeading(Printer& p, const CHT* element, + const CHA* style = nullptr, ISW column_count = 80, + const CHA* caption2 = nullptr, + const CHA* caption3 = nullptr) { if (!style) style = TSTRHeadingf(); - style = TPrintLinef(o, style, column_count); - if (!style) return o; - o << element; - if (caption2) o << caption2; - if (caption3) o << caption3; - TPrintLinef(o, style, column_count); - return o; + style = TPrintLinef(p, style, column_count); + if (!style) return p; + p << element; + if (caption2) p << caption2; + if (caption3) p << caption3; + TPrintLinef(p, style, column_count); + return p; } /* Prints the a formatted header. */ template -Printer& TPrintHeadingf(Printer& o, Headingf& value) { +Printer& TPrint(Printer& p, Headingf& value) { switch (_::TypeTextFormat(value.element.Type())) { #if USING_UTF8 == YES_0 - case 1: { - return _::TPrintHeadingf(o, value.element.STA(), value.style, - value.element.Count(), - value.caption2, value.caption3); - } + case 1: { + return _::TPrintHeading(p, value.element.STA(), value.style, + value.element.Count(), + value.caption2, value.caption3); + } #endif #if USING_UTF16 == YES_0 - case 2: { - return _::TPrintHeadingf(o, value.element.STB(), value.style, - value.element.Count(), - value.caption2, value.caption3); - } + case 2: { + return _::TPrintHeading(p, value.element.STB(), value.style, + value.element.Count(), + value.caption2, value.caption3); + } #endif #if USING_UTF32 == YES_0 - case 3: { - return _::TPrintHeadingf(o, value.element.STC(), value.style, - value.element.Count(), - value.caption2, value.caption3); - } + case 3: { + return _::TPrintHeading(p, value.element.STC(), value.style, + value.element.Count(), + value.caption2, value.caption3); + } #endif } - return o; + return p; } template -Printer& TPrintChars(Printer& o, const CHT* start, const CHT* stop) { - if (!start || start >= stop) return o; +Printer& TPrintChars(Printer& p, const CHT* start, const CHT* stop) { + if (!start || start >= stop) return p; ISW size_bytes = stop - start + 1; - o << STRPrintCharsHeader() << STRPrintCharsBorder() << Hexf(start); + p << STRPrintCharsHeader() << STRPrintCharsBorder() << Hexf(start); int i = 0; CHT c; const CHT* address_to_print = start; while (start <= stop) { - o << '\n' << '|'; + p << '\n' << '|'; for (ISC i = 0; i < 64; ++i) { c = *start; if (start++ > stop) { c = 'x'; - } else if (c < ' ') { + } + else if (c < ' ') { address_to_print = start; c += APrintC0Offset; } if (c == 127) c = ' '; - o << c; + p << c; } - o << "| " << Hexf(address_to_print - 1); + p << "| " << Hexf(address_to_print - 1); } - return o << STRPrintCharsBorder() << "Chars printed:" << size_bytes; + return p << STRPrintCharsBorder() << "Chars printed:" << size_bytes; } template -inline Printer& TPrintChars(Printer& o, const CHT* start, ISW count) { - return TPrintChars(o, start, start + count - 1); +inline Printer& TPrintChars(Printer& p, const CHT* start, ISW count) { + return TPrintChars(p, start, start + count - 1); } template -Printer& TPrintChars(Printer& o, Charsf& value) { - Valuef& element = value.element; +Printer& TPrint(Printer& p, Charsf& value) { + auto element = value.element; ISW count = element.Count(); switch (_::TypeTextFormat(element.Type())) { #if USING_UTF8 == YES_0 - case 1: { - return _::TPrintChars(o, element.ToSTA(), count); - } + case 1: { + return _::TPrintChars(p, element.ToSTA(), count); + } #endif #if USING_UTF16 == YES_0 - case 2: { - return _::TPrintChars(o, element.ToSTB(), count); - } + case 2: { + return _::TPrintChars(p, element.ToSTB(), count); + } #endif #if USING_UTF32 == YES_0 - case 3: { - return _::TPrintChars(o, element.ToSTC(), count); - } + case 3: { + return _::TPrintChars(p, element.ToSTC(), count); + } #endif } return _::TPrintChars( - o, TPtr(element.Value()), count); + p, TPtr(element.Value()), count); +} + +/* Prints the given cursor repeated to make a line. */ +template +CHT* TPrintHeading(CHT* start, CHT* stop, CHT item, + ISW count = AConsoleWidth) { + return TPrintLinef(start, stop, item, count, nullptr, nullptr); +} + +/* Prints the given cursor repeated to make a line. */ +template +CHT* TPrintHeading(CHT* start, CHT* stop, const CHT* item, + ISW count = AConsoleWidth) { + return TPrintLinef(start, stop, item, count, nullptr, nullptr); +} + +template +Printer& TPrintIndent(Printer& p, ISW indent_count) { + p << '\n'; + while (--indent_count >= 0) p << ' '; + return p; +} + +template +Printer& TPrint(Printer& p, const Indentf& item) { + return _::TPrintIndent(p, item.indent_count); } +} // namespace _ + +#if SEAM >= SCRIPT2_UNIPRINTER +namespace _ { -/* Prints a string represntation of an 8-bit ASCII Data Type to the printer. */ +/* Prints the given sizef to the printer. */ template -Printer& TPrintType(Printer& o, DTA type) { - if (type < 32) return o << STRTypePOD(type); // POD Type +Printer& TPrint(Printer& p, Sizef& item) { + auto value = item.size; + if (value < 0) return p << CHA('@' + (-value)); + return p << value; +} + +#if SEAM >= UNIPRINTER + +// Prints an ASCII POD type to the printer. +template +Printer& TPrintATypePOD(Printer& p, DT type) { + DT pod_type = type & ATypePODMask, // + vector_type = TTypeVector
(type), // + map_type = TTypeMap
(type); // +} + +/* Prints a string represntation of an 8-bit ASCII Data Type to the printer. +template +Printer& TPrintAType(Printer& p, DTA type) { + if (type < 32) return p << STRTypePOD(type); // POD Type DTW type_pod = type & 0x1f, type_vector = (type & DTVHT) >> 5; // | b7 | b6:b5 | b4:b0 | // |:----------:|:-----------:|:---------:| // | Size Width | Vector Type | POD Type | if (type >> 7) { // SW bit asserted, there is a 16-bit size_width - return o << STRTypeVector(type_vector) << 'B' << '_' + return p << STRTypeVector(type_vector) << 'B' << '_' << STRTypePOD(type_pod); } - return o << STRTypeVector(type_vector) << 'A' << '_' + return p << STRTypeVector(type_vector) << 'A' << '_' << STRTypePOD(type_pod); -} +} template -Printer& TPrintTypeVector(Printer& o, DTB type) { - if (type >> 9 != 0) return o; -} +Printer& TPrintATypeVector(Printer& p, DTB type) { + if (type >> 9 != 0) return p; +}*/ -/* Prints a string represntation of an ASCII Data Type to the printer. -16-bit ASCII Bit Pattern: -| b15:b14 | b13:b9 | b8:b7 | b6:b5 | b4:b0 | -|:-------:|:------:|:-----:|:-----:|:-----:| -| MOD | MT | SW | VT | POD | */ -template -Printer& TPrintType(Printer& o, DTB type) { - // Processing from MOD to POD/left to right. - o << "0b" << Binaryf(type) << ' '; - auto mod_bits = type >> ATypeMODBit0; - if (mod_bits != 0) { - o << STRTypeModifier(mod_bits) << '_'; - type ^= mod_bits << ATypeMODBit0; - } - auto map_type = type >> ATypeMTBit0; - if (map_type != 0) { - o << STRTypePOD(map_type) << "_"; - type ^= map_type << ATypeMTBit0; - } - if (type < ATypePODCount) return o << STRTypePOD(type); // POD Type - auto size_width = type >> ATypeSWBit0; - type ^= size_width << ATypeSWBit0; - auto vector_type = type >> ATypeVTBit0; - type ^= vector_type << ATypeVTBit0; - if (!vector_type && !size_width) // Vector of Homo-tuple. - o << STRTypeVector(vector_type) << '_'; - if (ATypeIsCH(type)) { // Then it's a string, loom, or - - } - return o << STRTypePOD(type); -} +/**/ template -Printer& TPrintType(Printer& o, DTC type) { +Printer& TPrintAType(Printer& p, DTC type) { BOL first_time = true; ISN count = sizeof(DTC) / sizeof(DTB); - while(count-- > 0) { + while (count-- > 0) { if (!first_time) { - o << ' '; + p << ' '; first_time = false; } - TPrintType(o, DTB(type)); + TPrintAType(p, DTB(type)); type = type >> 16; } - return o; + return p; } template -Printer& TPrintType(Printer& o, DTD type) { +Printer& TPrintAType(Printer& p, DTD type) { BOL first_time = true; ISN count = sizeof(DTC) / sizeof(DTB); while (count-- > 0) { if (!first_time) { - o << '-'; + p.Print('-'); first_time = false; } - TPrintType(o, DTB(type)); + TPrintAType(p, DTB(type)); type = type >> 16; } - return o; -} - -/* Prints a summary of the type-value tuple with word-sized Data Type. */ -template -Printer& TPrintType(Printer& o, TypeWordValue item) { - return TPrintType(o, item.type); -} - -// Prints an ASCII POD type to the printer. -template -Printer& TPrintTypePOD(Printer& o, DT type) { - DT pod_type = type & ATypePODMask, // - vector_type = TTypeVector
(type), // - map_type = TTypeMap
(type); // + return p; } // Prints the value of the given type-value tuple. template -Printer& TPrintValuePOD(Printer& o, DTB type, const void* value) { +Printer& TPrintValuePOD(Printer& p, DTB type, const void* value) { switch (type) { - case _NIL: - return o; - case _IUA: - return o << *TPtr(value); - case _ISA: - return o << *TPtr(value); - case _CHA: - return o << *TPtr(value); - case _FPB: - return o << *TPtr(value); - case _IUB: - return o << *TPtr(value); - case _ISB: - return o << *TPtr(value); - case _CHB: - return o << *TPtr(value); - case _FPC: - return o << *TPtr(value); - case _IUC: - return o << *TPtr(value); - case _ISC: - return o << *TPtr(value); - case _CHC: - return o << *TPtr(value); - case _FPD: - return o << *TPtr(value); - case _IUD: - return o << *TPtr(value); - case _ISD: - return o << *TPtr(value); - case _TME: - return o << "TME not implemented"; - //o << *TPtr(value); - case _FPE: - return o << "FPE not implemented"; - //o << *TPtr(value); - case _IUE: - return o << "IUE not implemented"; - //o << *TPtr(value); - case _ISE: - return o << "ISE not implemented"; - //o << *TPtr(value); - case _BOL: - return o << *TPtr(value); - } - return o; + case _NIL: + return p; + case _IUA: + return p << *TPtr(value); + case _ISA: + return p << *TPtr(value); + case _CHA: + return p << *TPtr(value); + case _FPB: + return p << *TPtr(value); + case _IUB: + return p << *TPtr(value); + case _ISB: + return p << *TPtr(value); + case _CHB: + return p << *TPtr(value); + case _FPC: + return p << *TPtr(value); + case _IUC: + return p << *TPtr(value); + case _ISC: + return p << *TPtr(value); + case _CHC: + return p << *TPtr(value); + case _FPD: + return p << *TPtr(value); + case _IUD: + return p << *TPtr(value); + case _ISD: + return p << *TPtr(value); + case _TME: + return p << "TME not implemented"; + //p << *TPtr(value); + case _FPE: + return p << "FPE not implemented"; + //p << *TPtr(value); + case _IUE: + return p << "IUE not implemented"; + //p << *TPtr(value); + case _ISE: + return p << "ISE not implemented"; + //p << *TPtr(value); + case _BOL: + return p << *TPtr(value); + } + return p; } // Prints the value of the given type-value tuple. @@ -793,92 +789,555 @@ Printer& TPrintValuePOD(Printer& o, DTB type, const void* value) { //|:-------:|:------:|:-----:|:-----:|:-----:| //| MOD | MT | SW | VTS | POD | template -Printer& TPrintValue(Printer & o, DT type, const void* value) { - if (type < ATypePODCount) return TPrintValuePOD(o, DTB(type), value); +Printer& TPrintValue(Printer & p, DT type, const void* value) { + if (type < ATypePODCount) return TPrintValuePOD(p, DTB(type), value); auto mod_bits = type >> ATypeMODBit0; type ^= mod_bits << ATypeMODBit0; auto map_type = type >> ATypeMTBit0; type ^= map_type << ATypeMTBit0; if (map_type > 0) { if (type < ATypePODCount) { // Map of one POD type to another. - return o << STRTypePOD(type); + return p << STRTypePOD(type); } } auto size_width = type >> ATypeSWBit0; type ^= size_width << ATypeSWBit0; auto vector_type = type >> ATypeVTBit0; type ^= vector_type << ATypeVTBit0; - o << "count_max:"; + p << "count_max:"; if (vector_type == _ARY) { - if (size_width == 0) o << *(ISA*)(value); - else if (size_width == 1) o << *(ISB*)(value); - else if (size_width == 2) o << *(ISC*)(value); - else if (size_width == 3) o << *(ISD*)(value); - return o; + if (size_width == 0) p << *(ISA*)(value); + else if (size_width == 1) p << *(ISB*)(value); + else if (size_width == 2) p << *(ISC*)(value); + else if (size_width == 3) p << *(ISD*)(value); + return p; } else if (vector_type == _STK) { if (size_width == 0) { auto cursor = TPtr(value); - o << *cursor++ << " count:" << *cursor; + p << *cursor++ << " count:" << *cursor; } else if (size_width == 1) { auto cursor = TPtr(value); - o << *cursor++ << " count:" << *cursor; + p << *cursor++ << " count:" << *cursor; } else if (size_width == 2) { auto cursor = TPtr(value); - o << *cursor++ << " count:" << *cursor; + p << *cursor++ << " count:" << *cursor; } else if (size_width == 3) { auto cursor = TPtr(value); - o << *cursor++ << " count:" << *cursor; + p << *cursor++ << " count:" << *cursor; } } else if (vector_type == _MAT) { if (size_width == 0) { auto cursor = TPtr(value); - o << *cursor++ << " count:" << *cursor; + p << *cursor++ << " count:" << *cursor; } else if (size_width == 1) { auto cursor = TPtr(value); - o << *cursor++ << " count:" << *cursor; + p << *cursor++ << " count:" << *cursor; } else if (size_width == 2) { auto cursor = TPtr(value); - o << *cursor++ << " count:" << *cursor; + p << *cursor++ << " count:" << *cursor; } else if (size_width == 3) { auto cursor = TPtr(value); - o << *cursor++ << " count:" << *cursor; + p << *cursor++ << " count:" << *cursor; } } - return o; + return p; } // Prints the value of the given type-value tuple. template -Printer& TPrintValue(Printer& o, DT type, const void* base_ptr, IS offset) { - return TPrintValue(o, type, TPtr(base_ptr, offset)); +Printer& TPrintValue(Printer& p, DT type, const void* base_ptr, IS offset) { + return TPrintValue(p, type, TPtr(base_ptr, offset)); } // Prints the value of the given type-value tuple. template -Printer& TPrintValue(Printer& o, TTypeValue
type_value) { - return TPrintValue(o, type_value.type, type_value.value); +Printer& TPrintValue(Printer& p, TTypeValue
type_value) { + return TPrintValue(p, type_value.type, type_value.value); } // Prints ASCII type and the value tuple. template -Printer& TPrintTypeValue(Printer& o, DT type, const void* value) { - return o << TPrintType(o, type) << ':' - << TPrintValue(o, type, value); +Printer& TPrintATypeValue(Printer& p, DT type, const void* value) { + return p << TPrintAType(p, type) << ':' + << TPrintValue(p, type, value); } // Prints ASCII type and the value tuple. template -Printer& TPrintTypeValue(Printer& o, DT type, const void* base_ptr, IS offset) { - return TPrintTypeValue(o, type, TPtr(base_ptr, offset)); +Printer& TPrintATypeValue(Printer& p, DT type, const void* base_ptr, IS offset) { + return TPrintATypeValue(p, type, TPtr(base_ptr, offset)); +} + +/* A dumb templated string Printer. */ +template +struct TSPrinter { + CH* start, //< Start address. + * stop; //< Stop address. + + /* Default constructor does nothing. */ + TSPrinter() : start(0), stop(0) {} + + /* Initializes the UTF& from the given origin pointers. + @param start The origin of the origin. + @param count The number of CHT(s) in the buffer. */ + TSPrinter(CH* start, ISA size) : start(start), stop(start + size - 1) { + Reset(); + } + + /* Initializes the UTF& from the given origin pointers. + @param start The origin of the origin. + @param count The number of CHT(s) in the buffer. */ + TSPrinter(CH* start, ISB size) : start(start), stop(start + size - 1) { + Reset(); + } + + /* Initializes the UTF& from the given origin pointers. + @param start The origin of the origin. + @param count The number of CHT(s) in the buffer. */ + TSPrinter(CH* start, ISC size) : start(start), stop(start + size - 1) { + Reset(); + } + + /* Initializes the UTF& from the given origin pointers. + @param start The origin of the origin. + @param count The number of CHT(s) in the buffer. */ + TSPrinter(CH* start, ISD size) : start(start), stop(start + size - 1) { + Reset(); + } + + /* Initializes the array pointers from the given start and stop pointers. + @param start The start of the array. + @param stop The stop of the array. */ + TSPrinter(CH* start, CH* stop) : start(start), stop(stop) { Reset(); } + + /* Clones the other printer. */ + TSPrinter(const TSPrinter& other) + : start(other.start), stop(other.stop) { // Nothing to do here!. + } + + /* Points to the end of the contiguous linear socket. */ + IUA* End() { return TPtr(start) + (sizeof(CH) - 1); } + + IS SizeBytes() { return (IS)(stop - start + sizeof(CH)); } + + void Wipe() { RAMFill(start, stop); } + + /* Writes a nil-term CHA at the start of the string. */ + inline CH* Reset() { + *start = 0; + return start; + } + + /* Sets the start pointer to the new_pointer. */ + inline TSPrinter& Set(CH* cursor) { + start = cursor; + return *this; + } + + /* Sets the start pointer to the new_pointer. */ + inline TSPrinter& Set(IUW* buffer) { + IS size = *TPtr(buffer); + IUW ptr = IUW(buffer) + sizeof(IS); + CH* start_ptr = TPtr(ptr); + start = start_ptr; + stop = start_ptr + size - 1; + return *this; + } + + /* Sets the start pointer to the new_pointer. */ + inline void Set(const TSPrinter& other) { + start = other.start; + stop = other.stop; + } + + /* Finds the length of the STR in Chars. */ + inline IS SpaceLeft() { return (IS)(stop - start); } + + /* Calculates the max length of the string in Chars. */ + inline IS LengthMax() { return stop - start; } + + /* Prints a item to the string. */ + inline TSPrinter& PrintChar(CHA item) { + return Set(_::TSPrint(start, stop, item)); + } + inline TSPrinter& PrintChar(CHB item) { + return Set(_::TSPrint(start, stop, item)); + } + inline TSPrinter& PrintChar(CHC item) { + return Set(_::TSPrint(start, stop, item)); + } + inline TSPrinter& Print(CHA item) { return PrintChar(item); } + inline TSPrinter& Print(CHB item) { return PrintChar(item); } + inline TSPrinter& Print(CHC item) { return PrintChar(item); } + inline TSPrinter& Print(const CHA* item) { + return Set(_::TSPrintString(start, stop, item)); + } + inline TSPrinter& Print(const CHB* item) { + return Set(_::TSPrintString(start, stop, item)); + } + inline TSPrinter& Print(const CHC* item) { + return Set(_::TSPrintString(start, stop, item)); + } + inline TSPrinter& Print(ISC item) { + return Set(_::TSPrint(start, stop, item)); + } + inline TSPrinter& Print(IUC item) { + return Set(_::TSPrint(start, stop, item)); + } + inline TSPrinter& Print(ISD item) { + return Set(_::TSPrint(start, stop, item)); + } + inline TSPrinter& Print(IUD item) { + return Set(_::TSPrint(start, stop, item)); + } +#if USING_FPC == YES_0 + inline TSPrinter& Print(FPC item) { + return Set(_::TSPrint(start, stop, item)); + } +#endif +#if USING_FPD == YES_0 + inline TSPrinter& Print(FPD item) { + return Set(_::TSPrint(start, stop, item)); + } +#endif + + /* Prints the given pointer as hex. */ + inline TSPrinter& Hex(ISA item) { + return Set(TSPrintHex(start, stop, item)); + } + inline TSPrinter& Hex(IUA item) { + return Set(TSPrintHex(start, stop, item)); + } + inline TSPrinter& Hex(ISB item) { + return Set(TSPrintHex(start, stop, item)); + } + inline TSPrinter& Hex(IUB item) { + return Set(TSPrintHex(start, stop, item)); + } + inline TSPrinter& Hex(ISC item) { + return Set(TSPrintHex(start, stop, item)); + } + inline TSPrinter& Hex(IUC item) { + return Set(TSPrintHex(start, stop, item)); + } + inline TSPrinter& Hex(ISD item) { + return Set(TSPrintHex(start, stop, item)); + } + inline TSPrinter& Hex(IUD item) { + return Set(TSPrintHex(start, stop, item)); + } +#if USING_FPC == YES_0 + inline TSPrinter& Hex(FPC item) { + return Set(TSPrintHex(start, stop, item)); + } +#endif +#if USING_FPD == YES_0 + inline TSPrinter& Hex(FPD item) { + return Set(TSPrintHex(start, stop, item)); + } +#endif + inline TSPrinter& Hex(const void* ptr) { + return Set(TSPrintHex(start, stop, ptr)); + } + inline TSPrinter& Binary(ISA item) { + return Set(Binary(start, stop, item)); + } + inline TSPrinter& Binary(IUA item) { + return Set(Binary(start, stop, item)); + } + inline TSPrinter& Binary(ISB item) { + return Set(Binary(start, stop, item)); + } + inline TSPrinter& Binary(IUB item) { + return Set(Binary(start, stop, item)); + } + inline TSPrinter& Binary(ISC item) { + return Set(Binary(start, stop, item)); + } + inline TSPrinter& Binary(IUC item) { + return Set(Binary(start, stop, item)); + } + inline TSPrinter& Binary(ISD item) { + return Set(Binary(start, stop, item)); + } + inline TSPrinter& Binary(IUD item) { + return Set(Binary(start, stop, item)); + } +#if USING_FPC == YES_0 + inline TSPrinter& Binary(FPC item) { + return Set(Binary(start, stop, item)); + } +#endif +#if USING_FPD == YES_0 + inline TSPrinter& Binary(FPD item) { + return Set(Binary(start, stop, item)); + } +#endif + /* Prints the given pointer as binary. */ + inline TSPrinter& Binary(const void* ptr) { + IUW address = IUW(ptr); + return Set(Binary(start, stop, address)); + } + + template + inline Printer& PrintTo(Printer& p) { + p << "\nTSPrinter{ start:"; + TPrintHex(p, start); + p << " stop:"; + TPrintHex(p, stop); + + #if D_THIS + // return TPrintChars(p, start, stop); + #else + return p << " }\n"; + #endif + } +}; + +} // namesapce _ + +/* Prints the given item to the SPrinter. +@return The printer. +@param p The printer. +@param item The item to printer. */ +template +inline _::TSPrinter& operator<<(_::TSPrinter& p, CHA item) { + return p.Print(item); +} + +template +inline _::TSPrinter& operator<<(_::TSPrinter& p, CHA* item) { + return p.Print(item); +} + +template +inline _::TSPrinter& operator<<(_::TSPrinter& p, const CHA* item) { + return p.Print(item); +} + +#if USING_UTF16 == YES_0 +template +inline _::TSPrinter& operator<<(_::TSPrinter& p, CHB item) { + return p.Print(item); +} + +template +inline _::TSPrinter& operator<<(_::TSPrinter& p, const CHB* item) { + return p.Print(item); +} +#endif +#if USING_UTF32 == YES_0 +template +inline _::TSPrinter& operator<<(_::TSPrinter& p, CHC item) { + return p.Print(item); +} + +template +inline _::TSPrinter& operator<<(_::TSPrinter& p, const CHC* item) { + return p.Print(item); +} +#endif + +template +inline _::TSPrinter& operator<<(_::TSPrinter& p, ISA item) { + return p.Print(item); +} + +template +inline _::TSPrinter& operator<<(_::TSPrinter& p, IUA item) { + return p.Print(item); +} + +template +inline _::TSPrinter& operator<<(_::TSPrinter& p, ISB item) { + return p.Print(item); +} + +template +inline _::TSPrinter& operator<<(_::TSPrinter& p, IUB item) { + return p.Print(item); +} + +template +inline _::TSPrinter& operator<<(_::TSPrinter& p, ISC item) { + return p.Print(item); +} + +template +inline _::TSPrinter& operator<<(_::TSPrinter& p, IUC item) { + return p.Print(item); +} + +template +inline _::TSPrinter& operator<<(_::TSPrinter& p, ISD item) { + return p.Print(item); +} + +template +inline _::TSPrinter& operator<<(_::TSPrinter& p, IUD item) { + return p.Print(item); } -} //< namespace _ +#if USING_FPC == YES_0 +template +inline _::TSPrinter& operator<<(_::TSPrinter& p, FPC item) { + return p.Print(item); +} +#endif + +#if USING_FPD == YES_0 +template +inline _::TSPrinter& operator<<(_::TSPrinter& p, FPD item) { + return p.Print(item); +} +#endif + +namespace _ { + +/* Prints the memory beginning at start to the Printer. */ +template +Printer& TPrintBinary(Printer& p, const void* start, ISW byte_count) { + if (!start) return p; + const IUA* cursor = TPtr(start); +#if CPU_ENDIAN == CPU_ENDIAN_LITTLE + ISA delta; + if (byte_count < 0) { + delta = -1; + byte_count = -byte_count; + cursor += byte_count - 1; + } + else { + delta = 1; + } +#endif + while (--byte_count >= 0) { + IUA c = *cursor; + cursor += delta; + for (ISW i = 8; i > 0; --i) { + p << CHA('0' + (c >> 7)); + c = c << 1; + } + } + return p; +} +} + +template +inline _::TSPrinter& operator<<(_::TSPrinter& p, + _::Binaryf item) { + return _::TPrint<_::TSPrinter>(p, item); +} + +namespace _ { + +/* Prints a string represntation of an ASCII Data Type to the printer. +16-bit ASCII Bit Pattern: +| b15:b14 | b13:b9 | b8:b7 | b6:b5 | b4:b0 | +|:-------:|:------:|:-----:|:-----:|:-----:| +| MOD | MT | SW | VT | POD | */ +template +Printer& TPrintAType(Printer& p, DTB type) { + // Processing from MOD to POD/left to right. + p << "0b"; + p << Binaryf(type) << ' '; + auto mod_bits = type >> ATypeMODBit0; + if (mod_bits != 0) { + p << STRTypeModifier(mod_bits) << '_'; + type ^= mod_bits << ATypeMODBit0; + } + auto map_type = type >> ATypeMTBit0; + if (map_type != 0) { + p << STRTypePOD(map_type) << "_"; + type ^= map_type << ATypeMTBit0; + } + if (type < ATypePODCount) return p << STRTypePOD(type); // POD Type + auto size_width = type >> ATypeSWBit0; + type ^= size_width << ATypeSWBit0; + auto vector_type = type >> ATypeVTBit0; + type ^= vector_type << ATypeVTBit0; + if (!vector_type && !size_width) // Vector of Homo-tuple. + p << STRTypeVector(vector_type) << '_'; + if (ATypeIsCH(type)) { // Then it's a string, loom, or + + } + return p << STRTypePOD(type); +} +/* Prints a summary of the type-value tuple with word-sized Data Type. */ +template +Printer& TPrint(Printer& p, TypeWordValue item) { + return TPrintAType(p, item.type); +} + +/* Prints an ASCII Type to the Printer. */ +template +Printer& TPrint(Printer& p, ATypef item) { + return TPrintAType(p, item.type); +} +} // namespace _ + +template +inline _::TSPrinter& operator<<(_::TSPrinter& p, + _::Centerf item) { + return _::TPrint<_::TSPrinter>(p, item); +} + +template +inline _::TSPrinter& operator<<(_::TSPrinter& p, + _::Rightf item) { + return _::TPrint<_::TSPrinter>(p, item); +} + +template +inline _::TSPrinter& operator<<(_::TSPrinter& p, + _::Linef item) { + return _::TPrint<_::TSPrinter>(p, item); +} + +template +inline _::TSPrinter& operator<<(_::TSPrinter& p, + _::Hexf item) { + return _::TSPrint<_::TSPrinter>(p, item); +} + +template +inline _::TSPrinter& operator<<(_::TSPrinter& p, + _::Charsf item) { + return _::TSPrint<_::TSPrinter>(p, item); +} + +template +inline _::TSPrinter& operator<<(_::TSPrinter& p, + _::Sizef item) { + return _::TPrint<_::TSPrinter>(p, item); +} + +template +inline _::TSPrinter& operator<<(_::TSPrinter& p, + _::ATypef item) { + return _::TPrint<_::TSPrinter>(p, item); +} + +template +inline _::TSPrinter& operator<<(_::TSPrinter& p, + _::TypeWordValue item) { + return _::TPrint<_::TSPrinter>(p, item); +} + +template +inline _::TSPrinter& operator<<(_::TSPrinter& p, + _::Headingf item) { + return _::TPrint<_::TSPrinter>(p, item); +} + +#endif +#endif #endif +#endif \ No newline at end of file diff --git a/Varint.h b/Varint.h index 7fbd53a..c6041ce 100644 --- a/Varint.h +++ b/Varint.h @@ -6,7 +6,6 @@ This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed with this file, You can obtain one at . */ - #pragma once #include <_Config.h> diff --git a/_ConfigFooter.inl b/_ConfigFooter.inl index 7f2676c..70d9abc 100644 Binary files a/_ConfigFooter.inl and b/_ConfigFooter.inl differ diff --git a/_ConfigHeader.inl b/_ConfigHeader.inl index e6ca008..4fbb58c 100644 Binary files a/_ConfigHeader.inl and b/_ConfigHeader.inl differ diff --git a/_Debug.inl b/_Debug.inl index 43c0a14..701255b 100644 --- a/_Debug.inl +++ b/_Debug.inl @@ -13,86 +13,86 @@ the MPL was not distributed with this file, You can obtain one at #define D_THIS 1 #define A_TEST_BEGIN \ - _::COut cout; \ + ::_::COut cout; \ cout << Headingf("Testing ", __FUNCTION__, nullptr, nullptr, 80) -#define D_COUT(item) _::CPrint().Star() << item -#define D_COUT_NL _::CPrint().Star().NL() -#define D_LINEF(item) _::CPrint().Star() << Linef(item) -#define D_PAUSE(message) _::Pausef(message) +#define D_COUT(item) ::_::StdOut() << item +#define D_COUT_NL ::_::StdOut().NL() +#define D_LINEF(item) ::_::StdOut() << Linef(item) +#define D_PAUSE(message) ::_::Pausef(message) #define D_COUT_ERROR(message) \ - _::CPrint().Star() << "\nERROR: " << message << '.'); \ - _::TestWarn(__LINE__, __FUNCTION__, __FILE__) -#define D_COUT_BSQ(item) _::TBSeqPrint(COut().Star(), item) -#define D_COUT_BIN(item) _::TBInPrint(COut().Star(), item) -#define D_COUT_BOut(item) _::TBOutPrint(COut().Star(), item) -#define D_COUT_OBJ(obj) obj.PrintTo(COut().Star()) -#define D_COUT_FUNCTION _::COut("\n", __FUNCTION__) + ::_::StdOut() << "\nERROR: " << message << '.'); \ + ::_::TestWarn(__LINE__, __FUNCTION__, __FILE__) +#define D_COUT_BSQ(item) ::_::TBSeqPrint<::_::COut>(StdOut(), item) +#define D_COUT_BIN(item) ::_::TBInPrint<::_::COut>(StdOut(), item) +#define D_COUT_BOut(item) ::_::TBOutPrint<::_::COut>(StdOut(), item) +#define D_COUT_OBJ(obj) obj.PrintTo<::_::COut>(StdOut()) +#define D_COUT_FUNCTION ::_::COut("\n", __FUNCTION__) #define D_COUT_FUNCTION_LINE \ - _::COut().NL(); \ - _::TestFunctionLine(__LINE__, __FUNCTION__, __FILE__) -#define D_COUT_ARRAY(item) _::TArrayPrint(COut().Star(), item) -#define D_COUT_STACK(item) _::TStackPrint(COut().Star(), item) -#define D_COUT_MATRIX(item) _::TMatrixPrint(COut().Star(), item) + ::_::COut().NL(); \ + ::_::TestFunctionLine(__LINE__, __FUNCTION__, __FILE__) +#define D_COUT_ARRAY(item) ::_::TArrayPrint(StdOut(), item) +#define D_COUT_STACK(item) ::_::TStackPrint(StdOut(), item) +#define D_COUT_MATRIX(item) ::_::TMatrixPrint(StdOut(), item) #define D_COUT_TABLE(item) \ - TTablePrint<_::COut, CHT, ISZ, ISY, HSH>(COut().Star(), item) -#define D_COUT_MAP(item) _::TMapPrint(COut().Star(), item) + TTablePrint<::_::COut, CHT, ISZ, ISY, HSH>(StdOut(), item) +#define D_COUT_MAP(item) ::_::TMapPrint(StdOut(), item) #define D_COUT_BOOK(item) \ - _::TBookPrint(COut().Star(), item) + ::_::TBookPrint(StdOut(), item) #define D_COUT_DICTIONARY(item) \ - _::TDicPrint<_::COut, CHT, ISZ, ISY, HSH>(COut().Star(), item) + ::_::TDicPrint<::_::COut, CHT, ISZ, ISY, HSH>(StdOut(), item) #define D_ARRAY_SAVE(origin, end_or_size) \ Socket socket_to_print(origin, end_or_size) #define D_ARRAY_FILL(origin, end_or_size, c) \ - _::ArrayFill(cursor, end_or_size, c) -#define D_ARRAY_WIPE(origin, end_or_size) _::ArrayFill(origin, end_or_size) + ::_::RAMFill(cursor, end_or_size, c) +#define D_ARRAY_WIPE(origin, end_or_size) ::_::RAMFill(origin, end_or_size) #define A_CHECK(condition) \ - if (!_::Test(condition)) _::TestWarn(__LINE__, __FUNCTION__, __FILE__) + if (!::_::Test(condition)) ::_::TestWarn(__LINE__, __FUNCTION__, __FILE__) #define A_COMPARE(a, b) \ - if (!_::Test(a, b)) { \ - _::TestWarn(__LINE__, __FUNCTION__, __FILE__); \ + if (!::_::Test(a, b)) { \ + ::_::TestWarn(__LINE__, __FUNCTION__, __FILE__); \ } #define D_ASSERT_INDEX(condition, index) \ - if (!_::Test(condition)) { \ - _::COut("\nError at index:0x").Hex(index) << ':' << index; \ - _::TestFail(__LINE__, __FUNCTION__, __FILE__); \ + if (!::_::Test(condition)) { \ + ::_::COut("\nError at index:0x").Hex(index) << ':' << index; \ + ::_::TestFail(__LINE__, __FUNCTION__, __FILE__); \ } #define A_ASSERT(condition) \ - if (!_::Test(condition)) _::TestFail(__LINE__, __FUNCTION__, __FILE__) + if (!::_::Test(condition)) ::_::TestFail(__LINE__, __FUNCTION__, __FILE__) #define D_ASSERT(condition) \ - if (!_::Test(condition)) _::TestFail(__LINE__, __FUNCTION__, __FILE__) + if (!::_::Test(condition)) ::_::TestFail(__LINE__, __FUNCTION__, __FILE__) #define R_ASSERT(condition) #define A_AVOW(a, b) \ - if (!_::Test(a, b)) { \ - _::TestFail(__LINE__, __FUNCTION__, __FILE__); \ + if (!::_::Test(a, b)) { \ + ::_::TestFail(__LINE__, __FUNCTION__, __FILE__); \ } #define D_AVOW(a, b) \ - if (!_::Test(a, b)) { \ - _::TestFail(__LINE__, __FUNCTION__, __FILE__); \ + if (!::_::Test(a, b)) { \ + ::_::TestFail(__LINE__, __FUNCTION__, __FILE__); \ } #define R_AVOW(a, b) #define R_AVOW_INDEX(a, b, index) #define D_AVOW_INDEX(a, b, index) \ - if (!_::Test(a, b)) { \ - _::COut(kSTRIndex).Print(index); \ - _::TestFail(__LINE__, __FUNCTION__, __FILE__); \ + if (!::_::Test(a, b)) { \ + ::_::COut(kSTRIndex).Print(index); \ + ::_::TestFail(__LINE__, __FUNCTION__, __FILE__); \ } #define A_AVOW_INDEX(a, b, index) \ - if (!_::Test(a, b)) { \ - _::COut("\n Index:").Print(index); \ - _::TestFail(__LINE__, __FUNCTION__, __FILE__); \ + if (!::_::Test(a, b)) { \ + ::_::COut("\n Index:").Print(index); \ + ::_::TestFail(__LINE__, __FUNCTION__, __FILE__); \ } #define A_WARN(condition) \ - if (!condition) _::TestWarn(__LINE__, __FUNCTION__, __FILE__) + if (!condition) ::_::TestWarn(__LINE__, __FUNCTION__, __FILE__) #define D_WARN(condition) \ - if (!condition) _::TestWarn(__LINE__, __FUNCTION__, __FILE__) + if (!condition) ::_::TestWarn(__LINE__, __FUNCTION__, __FILE__) #define R_WARN(condition) #define A_RETURN \ - { _::TestFunctionLine(__LINE__, __FUNCTION__, __FILE__) return; } + { ::_::TestFunctionLine(__LINE__, __FUNCTION__, __FILE__) return; } #define D_RETURN \ - { _::TestFunctionLine(__LINE__, __FUNCTION__, __FILE__) return; } + { ::_::TestFunctionLine(__LINE__, __FUNCTION__, __FILE__) return; } #define R_RETURN(value) #define A_RETURN_VALUE(value) \ - { _::TestFunctionLine(__LINE__, __FUNCTION__, __FILE__) return value; } + { ::_::TestFunctionLine(__LINE__, __FUNCTION__, __FILE__) return value; } #define D_RETURN_VALUE(value) \ - { _::TestFunctionLine(__LINE__, __FUNCTION__, __FILE__) return value; } -#define R_RETURN_VALUE(value) \ No newline at end of file + { ::_::TestFunctionLine(__LINE__, __FUNCTION__, __FILE__) return value; } +#define R_RETURN_VALUE(value) diff --git a/_Release.inl b/_Release.inl index d3f4e7b..1927ca8 100644 --- a/_Release.inl +++ b/_Release.inl @@ -33,52 +33,52 @@ the MPL was not distributed with this file, You can obtain one at #define D_ARRAY_WIPE(origin, end_or_size) #define D_ASSERT_INDEX(condition, index) #define A_ASSERT(condition) \ - if (!_::Test(condition)) _::TestFail(__LINE__, __FUNCTION__, __FILE__) + if (!::_::Test(condition)) ::_::TestFail(__LINE__, __FUNCTION__, __FILE__) #define D_ASSERT(condition) #define A_CHECK(condition) #define D_CHECK(condition) #define R_CHECK(condition) \ - if (!_::Test(condition)) _::TestWarn(__LINE__, __FUNCTION__, __FILE__) + if (!::_::Test(condition)) ::_::TestWarn(__LINE__, __FUNCTION__, __FILE__) #define A_COMPARE(a, b) #define D_COMPARE(a, b) #define R_COMPARE(a, b) \ - if (!_::Test(a, b)) { \ - _::TestWarn(__LINE__, __FUNCTION__, __FILE__) \ + if (!::_::Test(a, b)) { \ + ::_::TestWarn(__LINE__, __FUNCTION__, __FILE__) \ } #define A_AVOW(a, b) \ - if (!_::Test(a, b)) { \ - _::TestFail(__LINE__, __FUNCTION__, __FILE__); \ + if (!::_::Test(a, b)) { \ + ::_::TestFail(__LINE__, __FUNCTION__, __FILE__); \ } #define D_AVOW(a, b) #define R_AVOW(a, b) \ - if (!_::Test(a, b)) { \ - _::TestFail(__LINE__, __FUNCTION__, __FILE__) \ + if (!::_::Test(a, b)) { \ + ::_::TestFail(__LINE__, __FUNCTION__, __FILE__) \ } #define R_AVOW(a, b) \ - if (!_::Test(a, b)) { \ - _::TestFail(__LINE__, __FUNCTION__, __FILE__) \ + if (!::_::Test(a, b)) { \ + ::_::TestFail(__LINE__, __FUNCTION__, __FILE__) \ } #define A_AVOW_INDEX(a, b, index) \ - if (!_::Test(a, b)) { \ - _::COut("\n Index:").Print(index); \ - _::TestFail(__LINE__, __FUNCTION__, __FILE__); \ + if (!::_::Test(a, b)) { \ + ::_::COut("\n Index:").Print(index); \ + ::_::TestFail(__LINE__, __FUNCTION__, __FILE__); \ } #define R_AVOW_INDEX(a, b, index) \ - if (!_::Test(a, b)) { \ - _::COut("\n Index:").Print(index); \ - _::TestFail(__LINE__, __FUNCTION__, __FILE__); \ + if (!::_::Test(a, b)) { \ + ::_::COut("\n Index:").Print(index); \ + ::_::TestFail(__LINE__, __FUNCTION__, __FILE__); \ } #define D_AVOW_INDEX(a, b, index) #define A_WARN(condition) \ - if (!condition) _::TestWarn(__LINE__, __FUNCTION__, __FILE__) + if (!condition) ::_::TestWarn(__LINE__, __FUNCTION__, __FILE__) #define D_WARN(condition) #define R_WARN(condition) \ - if (!condition) _::TestWarn(__LINE__, __FUNCTION__, __FILE__) + if (!condition) ::_::TestWarn(__LINE__, __FUNCTION__, __FILE__) #define A_RETURN(value) return; #define D_RETURN(value) #define R_RETURN(value) \ - { _::TestFunctionLine(__LINE__, __FUNCTION__, __FILE__) return; } + { ::_::TestFunctionLine(__LINE__, __FUNCTION__, __FILE__) return; } #define A_RETURN_VALUE(value) return value; #define D_RETURN_VALUE(value) #define R_RETURN_VALUE(value) \ - { _::TestFunctionLine(__LINE__, __FUNCTION__, __FILE__) return; } + { ::_::TestFunctionLine(__LINE__, __FUNCTION__, __FILE__) return; } diff --git a/_Seams/00.Core.inl b/_Seams/00.COut.inl similarity index 84% rename from _Seams/00.Core.inl rename to _Seams/00.COut.inl index b43022f..fa7b1bb 100644 --- a/_Seams/00.Core.inl +++ b/_Seams/00.COut.inl @@ -6,9 +6,9 @@ Form is subject to the terms of the Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed with this file, You can obtain one at . */ -#if SEAM >= SCRIPT2_CORE -#include "../Stringf.hpp" -#if SEAM == SCRIPT2_CORE +#if SEAM >= SCRIPT2_COUT +#include "../Uniprinter.hpp" +#if SEAM == SCRIPT2_COUT #include "../_Debug.inl" #else #include "../_Release.inl" @@ -17,12 +17,13 @@ the MPL was not distributed with this file, You can obtain one at using namespace _; namespace Script2 { -inline const CHA* Core(const CHA* args) { -#if SEAM >= SCRIPT2_CORE - A_TEST_BEGIN; +inline const CHA* COut(const CHA* args) { +#if SEAM >= SCRIPT2_COUT && USING_CONSOLE == YES_0 + A_TEST_BEGIN; + D_COUT(Headingf("Testing ArgsToString")); - + CHA arg_string[48] = "C:\\Windows\0Foo\0\0Bar \0\0\0 420 \0"; D_COUT("arg_string:\""); CHA* cursor = arg_string; @@ -53,21 +54,21 @@ inline const CHA* Core(const CHA* args) { D_COUT(Headingf("Testing CHA* SPrint (CHA*,CHA*,CHC);")); enum { - cSTAEdgeCondition2 = 0x7f, - cSTAEdgeCondition3 = 0x7ff, - cSTAEdgeCondition4 = 0xffff, - cSTACount = 8 + STAEdgeCondition2 = 0x7f, + STAEdgeCondition3 = 0x7ff, + STAEdgeCondition4 = 0xffff, + STACount = 8 }; - CHA str1[cSTACount]; - CHA* str1_cursor = SPrint(str1, cSTACount, CHC(0)); + CHA str1[STACount]; + CHA* str1_cursor = SPrint(str1, STACount, CHC(0)); A_ASSERT(str1_cursor); const CHA* str1_result = SScan(str1, ch4_found); D_ASSERT_INDEX(str1_result, ISC(0)); A_AVOW_INDEX(CHC(0), ch4_found, 0); - for (CHC ch4_expected = cSTAEdgeCondition4; ch4_expected < (1 << 21); + for (CHC ch4_expected = STAEdgeCondition4; ch4_expected < (1 << 21); ch4_expected += 64) { - str1_cursor = SPrint(str1, cSTACount, ch4_expected); + str1_cursor = SPrint(str1, STACount, ch4_expected); D_ASSERT_INDEX(str1_cursor, IUC(ch4_expected)); const CHA* str1_result = SScan(str1, ch4_found); D_ASSERT_INDEX(str1_result, IUC(ch4_expected)); @@ -77,11 +78,11 @@ inline const CHA* Core(const CHA* args) { #if USING_UTF16 == YES_0 D_COUT(Headingf("Testing Testing CHB* SPrint (CHB*,CHB*,CHC)...")); enum { - cSTRBCount = 4, + STRBCount = 4, }; - CHB str2[cSTRBCount]; + CHB str2[STRBCount]; CHB* str2_cursor = str2; - str2_cursor = SPrint(str2, ISW(cSTRBCount) - 1, CHC(0)); + str2_cursor = SPrint(str2, ISW(STRBCount) - 1, CHC(0)); D_COUT(Hexf(str2) << TPtr(str2 + 3) - 1); A_ASSERT(str2_cursor); const CHB* str2_result = SScan(str2, ch4_found); diff --git a/_Seams/01.RNG.inl b/_Seams/01.RNG.inl index 44e0b50..fbb7916 100644 --- a/_Seams/01.RNG.inl +++ b/_Seams/01.RNG.inl @@ -6,7 +6,6 @@ Form is subject to the terms of the Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed with this file, You can obtain one at . */ - #if SEAM >= SCRIPT2_RNG #include "../RNG.h" using namespace _; diff --git a/_Seams/02.ItoS.inl b/_Seams/02.ItoS.inl index e0d040b..766e879 100644 --- a/_Seams/02.ItoS.inl +++ b/_Seams/02.ItoS.inl @@ -13,7 +13,7 @@ the MPL was not distributed with this file, You can obtain one at // #include "../Puff.hpp" #include "../RNG.h" -#include "../Stringf.hpp" +#include "../Uniprinter.hpp" using namespace _; #if SEAM == SCRIPT2_ITOS #include "../_Debug.inl" diff --git a/_Seams/04.SPrinter.inl b/_Seams/04.Uniprinter.inl similarity index 50% rename from _Seams/04.SPrinter.inl rename to _Seams/04.Uniprinter.inl index 255d5ca..0909c25 100644 --- a/_Seams/04.SPrinter.inl +++ b/_Seams/04.Uniprinter.inl @@ -1,17 +1,15 @@ /* Script2™ @link https://github.com/KabukiStarship/Script2.git -@file /_Seams/04.SPrinter.inl +@file /_Seams/04.Uniprinter.inl @author Cale McCollough @license Copyright Kabuki Starship™ ; This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed with this file, You can obtain one at . */ - -#if SEAM >= SCRIPT2_SPRINTER -#include "../Array.hpp" -#include "../Stringf.hpp" +#if SEAM >= SCRIPT2_UNIPRINTER +#include "../Uniprinter.hpp" using namespace _; -#if SEAM == SCRIPT2_SPRINTER +#if SEAM == SCRIPT2_UNIPRINTER #include "../_Debug.inl" #else #include "../_Release.inl" @@ -19,96 +17,96 @@ using namespace _; #endif namespace Script2 { -#if SEAM >= SCRIPT2_SPRINTER +#if SEAM >= SCRIPT2_UNIPRINTER template -static const CHT* TestSPrinter() { +static const CHA* TestSPrinter() { D_COUT(Linef('-') << "\n\n\nTesting UTF\n\n" << Linef('-')); enum { - cCount = 512, + Count = 512, }; - CHT str_a[cCount]; - static const CHT cTesting123[] = { 'T', 'e', 's', 't', 'i', 'n', + CHT str_a[Count]; + static const CHT Testing123[] = { 'T', 'e', 's', 't', 'i', 'n', 'g', ' ', '1', ',', ' ', '2', ',', ' ', '3', '.', NIL }; - D_ARRAY_WIPE(str_a, cCount * sizeof(CHT)); - TSPrint(str_a, cCount, cTesting123); + D_ARRAY_WIPE(str_a, Count * sizeof(CHT)); + TSPrint(str_a, Count, Testing123); D_COUT(Charsf(str_a, 64)); - TSPrinter utf(str_a, cCount); + TSPrinter utf(str_a, Count); - enum { cTestStringsCount = 4 }; + enum { TestStringsCount = 4 }; - const CHT kTestStrings[5][2][7] = {{{'?', NIL, NIL, NIL, NIL, NIL, NIL}, - {NIL, NIL, NIL, NIL, NIL, NIL, NIL}}, - {{'?', NIL, NIL, NIL, NIL, NIL, NIL}, - {'?', NIL, NIL, NIL, NIL, NIL, NIL}}, - {{'?', ' ', NIL, NIL, NIL, NIL, NIL}, - {'?', NIL, NIL, NIL, NIL, NIL, NIL}}, - {{'A', 'p', 'p', 'l', 'e', 's', NIL}, - {'A', 'p', 'p', 'l', 'e', 's', NIL}}, - {{'A', 'p', 'p', 'l', 'e', 's', NIL}, - {'A', 'p', 'p', 'l', 'e', 's', NIL}}}; + const CHT TestStrings[5][2][7] = {{{'?', NIL, NIL, NIL, NIL, NIL, NIL}, + {NIL, NIL, NIL, NIL, NIL, NIL, NIL}}, + {{'?', NIL, NIL, NIL, NIL, NIL, NIL}, + {'?', NIL, NIL, NIL, NIL, NIL, NIL}}, + {{'?', ' ', NIL, NIL, NIL, NIL, NIL}, + {'?', NIL, NIL, NIL, NIL, NIL, NIL}}, + {{'A', 'p', 'p', 'l', 'e', 's', NIL}, + {'A', 'p', 'p', 'l', 'e', 's', NIL}}, + {{'A', 'p', 'p', 'l', 'e', 's', NIL}, + {'A', 'p', 'p', 'l', 'e', 's', NIL}}}; const CHT* cursor; - for (ISC i = 0; i < cTestStringsCount; ++i) { - D_ARRAY_WIPE(str_a, cCount * sizeof(CHT)); - cursor = TSPrintString(str_a, str_a + cCount, kTestStrings[i][0]); + for (ISC i = 0; i < TestStringsCount; ++i) { + D_ARRAY_WIPE(str_a, Count * sizeof(CHT)); + cursor = TSPrintString(str_a, str_a + Count, TestStrings[i][0]); D_COUT(Charsf(str_a, 64)); Test(cursor); - cursor = TSTREquals(str_a, kTestStrings[i][0]); + cursor = TSTREquals(str_a, TestStrings[i][0]); Test(cursor); } D_COUT(Headingf("Testing TSPrinter") - << "\n\nExpecting \"" << cTesting123 << '\"'); - static const CHT kCommaSpace[] = {',', ' ', NIL}; + << "\n\nExpecting \"" << Testing123 << '\"'); + static const CHT CommaSpace[] = {',', ' ', NIL}; const CHT kTestingSpace[] = {'T', 'e', 's', 't', 'i', 'n', 'g', ' ', NIL}; - D_ARRAY_WIPE(str_a, cCount * sizeof(CHT)); + D_ARRAY_WIPE(str_a, Count * sizeof(CHT)); utf.Set(str_a).Print(kTestingSpace); utf.Print(1); - utf.Print(kCommaSpace); + utf.Print(CommaSpace); utf.Print(2); utf.Print(", "); utf.Print(3); utf.Print('.'); - utf.Set(str_a) << kTestingSpace << 1 << kCommaSpace << 2 << ", " << 3 << '.'; + utf.Set(str_a) << kTestingSpace << 1 << CommaSpace << 2 << ", " << 3 << '.'; D_COUT(Charsf(str_a, 64)); - A_AVOW(cTesting123, str_a); + A_AVOW(Testing123, str_a); D_COUT("\n\nTesting TSTREquals"); - const CHT kCompareStrings[4][9] = { + const CHT CompareStrings[4][9] = { {'T', 'e', 's', 't', 'i', 'n', 'g', NIL, NIL}, {'T', 'e', 'x', 't', 'i', 'n', 'g', NIL, NIL}, {'T', 'e', 's', 't', 'i', 'n', 'g', '@', NIL}, {'T', 'e', 'x', 't', 'i', 'n', 'g', '@', NIL}, }; - A_ASSERT(!TSTREquals(kCompareStrings[0], kCompareStrings[1])); - A_ASSERT(!TSTREquals(kCompareStrings[0], kCompareStrings[3])); - A_ASSERT(TSTREquals(kCompareStrings[0], kCompareStrings[0])); - A_ASSERT(!TSTREquals(kCompareStrings[2], kCompareStrings[3])); - A_ASSERT(TSTREquals(kCompareStrings[2], kCompareStrings[2])); + A_ASSERT(!TSTREquals(CompareStrings[0], CompareStrings[1])); + A_ASSERT(!TSTREquals(CompareStrings[0], CompareStrings[3])); + A_ASSERT(TSTREquals(CompareStrings[0], CompareStrings[0])); + A_ASSERT(!TSTREquals(CompareStrings[2], CompareStrings[3])); + A_ASSERT(TSTREquals(CompareStrings[2], CompareStrings[2])); - const CHT k1to9[] = {'1', '2', '3', '4', '5', '6', '7', '8', '9', NIL}; - A_AVOW(9, TSTRLength(k1to9)); + const CHT Chars1to9[] = {'1', '2', '3', '4', '5', '6', '7', '8', '9', NIL}; + A_AVOW(9, TSTRLength(Chars1to9)); D_COUT("\n\nTesting TSTRFind"); - const CHT kOne[] = {'1', ',', NIL}; - const CHT kThreePeriod[] = {'3', '.', NIL}; - A_ASSERT(TSTRFind(cTesting123, kOne)); - A_ASSERT(TSTRFind(cTesting123, kThreePeriod)); + const CHT One[] = {'1', ',', NIL}; + const CHT ThreePeriod[] = {'3', '.', NIL}; + A_ASSERT(TSTRFind(Testing123, One)); + A_ASSERT(TSTRFind(Testing123, ThreePeriod)); D_COUT(Headingf("Testing TPrintRight")); - const CHT kRightAligned[12][13] = { + const CHT RightAligned[12][13] = { {'.', NIL, NIL, NIL, NIL, NIL, NIL, NIL, NIL, NIL, NIL, NIL, NIL}, {'.', '.', NIL, NIL, NIL, NIL, NIL, NIL, NIL, NIL, NIL, NIL, NIL}, {'.', '.', '.', NIL, NIL, NIL, NIL, NIL, NIL, NIL, NIL, NIL, NIL}, @@ -124,16 +122,16 @@ static const CHT* TestSPrinter() { ISC shift_right = 6; for (ISC i = 0; i < 12; ++i) { - D_ARRAY_WIPE(str_a, (ISW)(cCount * sizeof(CHT))); - cursor = TPrintRight(str_a, str_a + cCount - 1, kTestingSpace, i + 1); + D_ARRAY_WIPE(str_a, (ISW)(Count * sizeof(CHT))); + cursor = TPrintRight(str_a, str_a + Count - 1, kTestingSpace, i + 1); D_ASSERT_INDEX(cursor, i); D_COUT(Charsf(str_a, 64) << "\n Wrote:\"" << str_a << "\":" << TSTRLength(str_a)); - A_AVOW_INDEX(&kRightAligned[i][0], str_a, i); + A_AVOW_INDEX(&RightAligned[i][0], str_a, i); } D_COUT(Headingf("Testing TPrintCenter")); - const CHT kCentered[13][14] = { + const CHT CenterAligned[13][14] = { {'.', NIL, NIL, NIL, NIL, NIL, NIL, NIL, NIL, NIL, NIL, NIL, NIL, NIL}, {'.', '.', NIL, NIL, NIL, NIL, NIL, NIL, NIL, NIL, NIL, NIL, NIL, NIL}, {'.', '.', '.', NIL, NIL, NIL, NIL, NIL, NIL, NIL, NIL, NIL, NIL, NIL}, @@ -148,34 +146,55 @@ static const CHT* TestSPrinter() { {' ', '1', '2', '3', '4', '5', '6', '7', '8', '9', ' ', ' ', NIL, NIL}, {' ', ' ', '1', '2', '3', '4', '5', '6', '7', '8', '9', ' ', ' ', NIL}}; - static const CHT kNumbers[] = {'1', '2', '3', '4', '5', - '6', '7', '8', '9', NIL}; + static const CHT Numbers1To9[] = {'1', '2', '3', '4', '5', + '6', '7', '8', '9', NIL}; for (ISC i = 12; i >= 0; --i) { - D_ARRAY_WIPE(str_a, cCount * sizeof(CHT)); - cursor = TPrintCenter(str_a, str_a + cCount - 1, kNumbers, i + 1); + D_ARRAY_WIPE(str_a, Count * sizeof(CHT)); + cursor = TPrintCenter(str_a, str_a + Count - 1, Numbers1To9, i + 1); D_ASSERT_INDEX(cursor, i); D_COUT(Charsf(str_a, 64) << "\n Wrote:\"" << str_a << "\":" << TSTRLength(str_a)); - A_AVOW_INDEX(&kCentered[i][0], str_a, i); + A_AVOW_INDEX(&CenterAligned[i][0], str_a, i); } return nullptr; } -#endif //< #if SEAM >= SCRIPT2_SPRINTER -static const CHA* SPrinter(const CHA* args) { -#if SEAM >= SCRIPT2_SPRINTER +static const CHA* TestSPrinter() { A_TEST_BEGIN; - - if (TestSPrinter()) return "Error testing UTF-8."; - + if (TestSPrinter()) return "Error testing SPrinter UTF-8."; #if USING_UTF16 == YES_0 - if (TestSPrinter()) return "Error testing UTF-16."; + if (TestSPrinter()) return "Error testing SPrinter UTF-16."; #endif #if USING_UTF32 == YES_0 - if (TestSPrinter()) return "Error testing UTF-32."; + if (TestSPrinter()) return "Error testing SPrinter UTF-32."; #endif + return nullptr; +} + +static const CHR* TestATypef() { + D_COUT("Testing ATypef..."); + // ATypef was the first class that implemented the new Center and Right + // functions that return Centerf and Right respectivly. I'm not very conserned + // about the types being printed right so much as I am in testing said + // funcationality. + auto o = ::_::StdOut(); + CHA buffer[256]; + buffer[255] = 0; + TSPrinter p(buffer, 1024); + TPrintAType>(p, ATypePack(_ISA, _STK)); + + o << "\n\nResult:\n\"" << buffer << '\"'; + return nullptr; +} + +#endif //< #if SEAM >= SCRIPT2_UNIPRINTER + +static const CHA* Uniprinter(const CHA* args) { +#if SEAM >= SCRIPT2_UNIPRINTER + D_RUN(TestSPrinter); + D_RUN(TestATypef); #endif return nullptr; } diff --git a/_Seams/05.Clock.inl b/_Seams/05.Clock.inl index 1442fcd..aa73ad6 100644 --- a/_Seams/05.Clock.inl +++ b/_Seams/05.Clock.inl @@ -9,7 +9,7 @@ the MPL was not distributed with this file, You can obtain one at #if SEAM >= SCRIPT2_CLOCK #include "../Clock.hpp" -#include "../Stringf.hpp" +#include "../Uniprinter.hpp" using namespace _; #if SEAM == SCRIPT2_CLOCK #include "../_Debug.inl" diff --git a/_Seams/06.Stack.inl b/_Seams/06.Stack.inl index d122404..baaf440 100644 --- a/_Seams/06.Stack.inl +++ b/_Seams/06.Stack.inl @@ -8,7 +8,7 @@ the MPL was not distributed with this file, You can obtain one at . */ #if SEAM >= SCRIPT2_STACK #include "../Stack.hpp" -using namespace _; +using namespace ::_; #if SEAM == SCRIPT2_STACK #include "../_Debug.inl" #else @@ -49,7 +49,7 @@ void TestStack(const CHA* args) { D_COUT(Headingf("\n\nPopping items off the Stack... ") << "i:" << i << 'n'); #if SEAM == SCRIPT2_STACK - TStackPrint(COut().Star(), stack.This()); + TStackPrint<_::COut, T, IS>(StdOut(), stack.This()); #endif for (i=i-1; i >= 0; --i) { //D_COUT_OBJ(stack); @@ -68,13 +68,13 @@ static const CHA* Stack(const CHA* args) { #if SEAM >= SCRIPT2_STACK A_TEST_BEGIN; - D_COUT(Headingf("Testing ArrayCompare with offset sequential arrays...")); + D_COUT(Headingf("Testing RAMCompare with offset sequential arrays...")); enum { OffsetMax = 2 * WordByteCount, TestByteCount = 256, BufferSizeBytes = TestByteCount + 2 * OffsetMax, - BufferSizeWords = BufferSizeBytes >> WordBitCount, + BufferSizeWords = BufferSizeBytes >> ACPUBitCount, }; IUW source[BufferSizeWords], destination[BufferSizeWords + OffsetMax]; @@ -138,12 +138,12 @@ static const CHA* Stack(const CHA* args) { } } - D_COUT(Headingf("Test ArrayCopy")); + D_COUT(Headingf("Test RAMCopy")); for (IUW s_offset = 0; s_offset < OffsetMax; ++s_offset) { for (IUW d_offset = 0; d_offset < OffsetMax; ++d_offset) { //D_COUT("\n\ns_offset: " << s_offset << " d_offset: " << d_offset); - ArrayFill(destination, BufferSizeBytes, 0); + RAMFill(destination, BufferSizeBytes, 0); IUA* cursor = TPtr(source); for (IUW i = 0; i < s_offset; ++i) *cursor++ = 0; diff --git a/_Seams/08.String.inl b/_Seams/08.String.inl index a3efedd..c78ecc2 100644 --- a/_Seams/08.String.inl +++ b/_Seams/08.String.inl @@ -21,7 +21,7 @@ namespace Script2 { #if SEAM >= SCRIPT2_STRING template void TestStringN() { - static const CHT cTesting123[] = {'T', 'e', 's', 't', 'i', 'n', + static const CHT Testing123[] = {'T', 'e', 's', 't', 'i', 'n', 'g', ' ', '1', ',', ' ', '2', ',', ' ', '3', '.', NIL}; enum { @@ -31,17 +31,18 @@ void TestStringN() { AString str; D_COUT_OBJ(str); - D_COUT("\nbuffer_size:" << str.Array().Size() << " buffer_size_bytes:" - << str.Array().SizeBytes() << " buffer_size_words:" - << str.Array().SizeWords()); + D_COUT("\nbuffer_size:" << str.Array().Size() << + " buffer_size_bytes:" << str.Array().SizeBytes() << + " buffer_size_words:" << str.Array().SizeWords()); D_COUT("\n\nExpecting \"" - << cTesting123 << "\"\n\nThe first print function should fail...\n"); + << Testing123 << "\"\n\nThe first print function should fail...\n"); str << "Testing "; + D_COUT("\n\nWORKS HERE!!!\n\n"); for (ISN i = 1; i < 256; ++i) str << i << ", "; D_COUT("\n\nResult:\"" << str.Start() << "\"\n"); - //A_ASSERT(str.Find(cTesting123)); + //A_ASSERT(str.Find(Testing123)); } #endif diff --git a/_Seams/10.List.inl b/_Seams/10.List.inl index 959e4f2..3c77195 100644 --- a/_Seams/10.List.inl +++ b/_Seams/10.List.inl @@ -10,6 +10,7 @@ the MPL was not distributed with this file, You can obtain one at #if SEAM >= SCRIPT2_LIST #include "../List.hpp" #include "../RNG.h" +//#include "../Uniprinter.hpp" using namespace _; #if SEAM == SCRIPT2_LIST #include "../_Debug.inl" @@ -87,16 +88,6 @@ static const CHA* List(const CHA* args) { TestList(); TestList(); TestList(); - D_COUT("\n\nTesting TTypePrint...\n"); - for (DTB type = TEST_MIN; type < TEST_MAX; ++type) { - D_COUT('\n' << type << ".) "); - D_COUT(TPrintType(COut().Star(), type)); - } - - D_COUT("\n\nTTypePrint: ARY_CHA"); -#if SEAM == SCRIPT2_LIST - TPrintType(COut().Star(), DTB(_ARY | _CHA)); -#endif #endif return nullptr; } diff --git a/_Seams/11.Book.inl b/_Seams/11.Book.inl index 88b19f5..07d188f 100644 --- a/_Seams/11.Book.inl +++ b/_Seams/11.Book.inl @@ -22,7 +22,7 @@ using namespace _; #include "../_Release.inl" #endif namespace Script2 { -template void TestBook() { D_COUT(Linef("\n\n---\n\n")); @@ -31,8 +31,8 @@ void TestBook() { SizeBytes = 512 * sizeof(CHT) }; - D_COUT("\n\nTesting ABook() << ",IU" << TSizef() << - ",IS" << TSizef() << ",CH" << TSizef() << + D_COUT("\n\nTesting ABook() << ",IS" << TSizef() << + ",CH" << TSizef() << ",DT" << TSizef
() << "> with SizeBytes:" << SizeBytes); ABook book; @@ -55,7 +55,7 @@ void TestBook() { D_COUT("\nStep 1:\n" << Charsf(book.This(), book.SizeBytes())); A_AVOW(ISY(1), book.Insert(word_cursor += word_step, ISA(1))); book.COut(); - /* + D_COUT("\nStep 2:\n" << Charsf(book.This(), book.SizeBytes())); A_AVOW(ISY(2), book.Insert(word_cursor += word_step, IUA(2))); book.COut(); @@ -100,7 +100,7 @@ void TestBook() { for (ISN i = 0; i < 1024; ++i) *cursor++ = '*'; *cursor = 0; ISZ index = book.Insert(large_string, 1); - */ + #if D_THIS book.COut(); #endif @@ -113,18 +113,18 @@ namespace Script2 { const CHA* Book(const CHA* args) { #if SEAM >= SCRIPT2_BOOK A_TEST_BEGIN; - TestBook(); - TestBook(); - TestBook(); + TestBook(); + TestBook(); + TestBook(); #if USING_UTF16 == YES_0 - TestBook(); - TestBook(); - TestBook(); + TestBook(); + TestBook(); + TestBook(); #endif #if USING_UTF32 == YES_0 - TestBook(); - TestBook(); - TestBook(); + TestBook(); + TestBook(); + TestBook(); #endif #endif return nullptr; diff --git a/_Seams/12.Map.inl b/_Seams/12.Map.inl index 04459f8..d6bd8c1 100644 --- a/_Seams/12.Map.inl +++ b/_Seams/12.Map.inl @@ -20,13 +20,13 @@ using namespace _; namespace Script2 { template + ISZ kCodomainMin_, ISZ kCodomainMax_, ISZ Size_> void TestMap() { D_COUT(Linef("\n\n\n\n\n\n+---\nTesting AMap\n+---\n\n")); - AMap map; + AMap map; D_COUT_OBJ(map); D_COUT("map_size:" << map.Size() << " map_size_bytes:" << map.SizeBytes() @@ -35,26 +35,26 @@ void TestMap() { << "\n domain:" << TDelta<>(map.This(), map.Domain()) << " codomain:" << TDelta<>(map.This(), map.Codomain())); - D domain[cSize_]; + D domain[Size_]; D_COUT(Headingf("Generating random domain values...")); - for (ISZ i = 0; i < cSize_; ++i) { + for (ISZ i = 0; i < Size_; ++i) { D d = Random(kDomainMin_, kDomainMax); domain[i] = d; D_COUT("\n" << i << ".) " << d); } - for (ISZ i = 0; i < cSize_; ++i) map.Add(domain[i]); + for (ISZ i = 0; i < Size_; ++i) map.Add(domain[i]); D_COUT(Headingf("Searching the domain for each domain[i]...")); - for (ISZ i = 0; i < cSize_; ++i) A_AVOW_INDEX(i, ISZ(map.Find(domain[i])), i); + for (ISZ i = 0; i < Size_; ++i) A_AVOW_INDEX(i, ISZ(map.Find(domain[i])), i); D_COUT(Headingf("Remapping the codomain to random numbers...")); - ISZ codomain[cSize_]; + ISZ codomain[Size_]; - for (ISZ i = 0; i < cSize_; ++i) { + for (ISZ i = 0; i < Size_; ++i) { ISZ c = Random(kCodomainMin_, kCodomainMax_); codomain[i] = c; map.RemapCodomain(i, c); @@ -62,7 +62,7 @@ void TestMap() { D_COUT_OBJ(map); D_COUT(Headingf("Searching for the remappings...")); - for (ISZ i = 0; i < cSize_; ++i) + for (ISZ i = 0; i < Size_; ++i) A_AVOW_INDEX(i, ISZ(map.FindCodomain(codomain[i])), i); D_COUT_OBJ(map); } diff --git a/_Seams/17.Seam.s2 b/_Seams/17.Seam.s2 index 907a50b..00907cc 100644 --- a/_Seams/17.Seam.s2 +++ b/_Seams/17.Seam.s2 @@ -14,8 +14,8 @@ | | | +-- There are 0 return parameters. | | | | v v v v - Foo <4, cSTR:32, cISA, cISB, cISC>: - Bar <1, cSTR:32>:<3, cISA, cISB, cISC> + Foo <4, STR_:32, cISA, cISB, cISC>: + Bar <1, STR_:32>:<3, cISA, cISB, cISC> FooBar : ^ ^ | | @@ -80,13 +80,13 @@ Parent1 { | | +---------------- This reserves 3 dictionary members. | | | v v v */ += DIC_4(nested, 1024, 3) { /* This is a nested dictionary. - +------------------------------ This is a operation with key "cSTR" + +------------------------------ This is a operation with key "STR_" | +----------------------- Dictionary key. | | +------------------ Max length 12. - | | | +-------------- cSTR value. + | | | +-------------- STR_ value. | | | | v v v v */ - += cSTR(item1 12 "ABC") -= + += STR_(item1 12 "ABC") -= Key item1 /* Operation "-Key" removes "item1". diff --git a/_Seams/_Config.h b/_Seams/_Config.h index 63f7107..f8edae6 100644 Binary files a/_Seams/_Config.h and b/_Seams/_Config.h differ diff --git a/_Seams/_Seams.inl b/_Seams/_Seams.inl index a85e41d..42e6e86 100644 Binary files a/_Seams/_Seams.inl and b/_Seams/_Seams.inl differ diff --git a/_Seams/_Tests.inl b/_Seams/_Tests.inl index b844f53..eb35137 100644 --- a/_Seams/_Tests.inl +++ b/_Seams/_Tests.inl @@ -10,11 +10,11 @@ the MPL was not distributed with this file, You can obtain one at // #include "../_Package.inl" // -#include "00.Core.inl" +#include "00.COut.inl" #include "01.RNG.inl" #include "02.ItoS.inl" #include "03.FtoS.inl" -#include "04.SPrinter.inl" +#include "04.Uniprinter.inl" #include "05.Clock.inl" #include "06.Stack.inl" #include "07.Matrix.inl" @@ -33,8 +33,8 @@ the MPL was not distributed with this file, You can obtain one at using namespace _; inline const CHA* Script2Tests(const CHA* args) { - return TTestTree - + - + @@ -127,12 +127,12 @@ + -