Skip to content

Commit

Permalink
Dictionary: Refactor to ASCII List with keys Table in element 0 #233.…
Browse files Browse the repository at this point in the history
…E Code is working and tested by is not printing the values.
  • Loading branch information
CookingWithCale committed Oct 30, 2024
1 parent 3294239 commit c2dda30
Show file tree
Hide file tree
Showing 32 changed files with 829 additions and 651 deletions.
2 changes: 1 addition & 1 deletion Array.h
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ class Nil {
static constexpr ISW Size();

/* Gets the size of the socket. */
static constexpr ISW SizeBytes();
static constexpr ISW Bytes();

/* Gets the size of the socket. */
static constexpr ISW SizeWords();
Expand Down
44 changes: 22 additions & 22 deletions Array.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,24 @@ the MPL was not distributed with this file, You can obtain one at
#include "Types.hpp"
namespace _ {

/* An ASCII Array.
Please see the ASCII Data Specificaiton for DRY documentation.
@link ./Spec/Data/VectorTypes/Array.md
@code
+-----------------+
| C-Style Array |
| 255-byte array | size=255, requires 8-bits.
|-----------------| ^
| TArray Header | |
+-----------------+ 0xN
@endcode
*/
template<typename IS = ISR>
struct TArray {
IS size; //< Number of elements in the array.
};

/* Overwrites the memory with fill_char; functionally equivalent to memset. */
inline CHA* RAMFill(void* start, void* stop, CHA fill_char = 0) {
return RAMFill(start, TPtr<CHA>(stop) - TPtr<CHA>(start) + 1, fill_char);
Expand Down Expand Up @@ -81,24 +99,6 @@ inline void Delete(Autoject obj) {
if (ram) ram(obj.origin, 0);
}

/* An ASCII Array.
Please see the ASCII Data Specificaiton for DRY documentation.
@link ./Spec/Data/VectorTypes/Array.md
@code
+-----------------+
| C-Style Array |
| 255-byte array | size=255, requires 8-bits.
|-----------------| ^
| TArray Header | |
+-----------------+ 0xN
@endcode
*/
template<typename IS = ISR>
struct TArray {
IS size; //< Number of elements in the array.
};

/* Checks if the given autoject count is in the min max bounds of an ASCII
Object. */
template<typename T, typename IS>
Expand Down Expand Up @@ -135,9 +135,9 @@ TArray<IS>* TArrayCopy(void* destination, const void* source) {
auto src = TPtr<const IS>(source);
auto dst_count = *dst;
auto src_count = *src;
auto result = RAMCopy(TPtrAlignUp<>(dst + 1, AlignMask),
auto result = RAMCopy(TPtrUp<>(dst + 1, AlignMask),
dst_count * sizeof(T),
TPtrAlignUp<>(src + 1, AlignMask),
TPtrUp<>(src + 1, AlignMask),
src_count * sizeof(T));
if (result <= 0) return nullptr;
*dst = src_count;
Expand Down Expand Up @@ -394,8 +394,8 @@ Printer& TArrayPrint(Printer& o, Autoject& obj) {
return o;
}

/* Inserts the given item at the start stack.
@pre You must perform bounds checking before calling this function. */
/* Inserts the given item into the stack, but can't push on top.
@pre items_start must be less than items_stop */
template<typename T>
inline void TArrayInsert_NC(T* items_start, T* items_stop, T item) {
while (items_start < items_stop) {
Expand Down
18 changes: 9 additions & 9 deletions Array.inl
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,11 @@ CHA* RAMFill(void* origin, ISW count, CHA fill_char) {
IUW fill_word = FillWord(fill_char);

// 1.) Align start pointer up to a word boundry and fill the unaligned bytes.
CHA *success = stop, *aligned_pointer = TPtrAlignUp<>(start);
CHA *success = stop, *aligned_pointer = TPtrUp<>(start);
while (start < aligned_pointer) *start++ = fill_char;
// 2.) Align stop pointer down to a word boundry and copy the midde words.
IUW *words = TPtr<IUW>(start),
*words_end = TPtrAlignDown<IUW>(stop);
*words_end = TPtrDown<IUW>(stop);
while (words < words_end) *words++ = fill_word;
// 3.) Copy remaining unaligned bytes.
start = TPtr<CHA>(words_end);
Expand Down Expand Up @@ -117,9 +117,9 @@ ISW ArrayCompareFast(const void* a, const ISW a_bytes, const void* b,
// xABCDEFG_HIJKLMNP_OQRSTUVW_XYZ v---- b_end
// xxxxABCD_EFGHIJKL_MNPOQRST_UVWXYZ
// Step 1: Compare the words...
const IUW* a_begin_word = TPtrAlignDown<IUW>(a_cursor),
* b_begin_word = TPtrAlignDown<IUW>(b_cursor);
const IUA* a_end_word = TPtrAlignDown<const IUA>(a_end);
const IUW* a_begin_word = TPtrDown<IUW>(a_cursor),
* b_begin_word = TPtrDown<IUW>(b_cursor);
const IUA* a_end_word = TPtrDown<const IUA>(a_end);
IUW a_offset = TDelta(a_begin_word, a_cursor) * 8,
b_offset = TDelta(b_begin_word, b_cursor) * 8,
a_offset_msb = IUW(ALUSize) * 8 - a_offset,
Expand Down Expand Up @@ -252,12 +252,12 @@ ISW ArrayCopyFast(void* write, ISW w_size, const void* read,
const IUA* r_start = TPtr<IUA>(read),
* r_stop = r_start + r_size;
IUA * w_cursor = TPtr<IUA>(write);
IUW * w_start_word = TPtrAlignUp<IUW>(w_cursor);
IUW * w_start_word = TPtrUp<IUW>(w_cursor);

while (w_cursor < TPtr<IUA>(w_start_word)) *w_cursor++ = *r_start++;

IUW* w_stop_word = TPtrAlignDown<IUW>(w_cursor + r_size);
const IUW *r_start_word = TPtrAlignDown<const IUW>(r_start);
IUW* w_stop_word = TPtrDown<IUW>(w_cursor + r_size);
const IUW *r_start_word = TPtrDown<const IUW>(r_start);
IUW w_offset = TDelta(w_cursor, w_start_word),
r_offset = TDelta(r_start_word, r_start);

Expand Down Expand Up @@ -338,7 +338,7 @@ inline ISW ArrayCopySlow(void* write, void* w_end, const void* read,

Nil::Nil() {}
constexpr ISW Nil::Size() { return 0; }
constexpr ISW Nil::SizeBytes() { return 0; }
constexpr ISW Nil::Bytes() { return 0; }
constexpr ISW Nil::SizeWords() { return 0; }
IUW* Nil::Words() { return nullptr; }

Expand Down
29 changes: 19 additions & 10 deletions Binary.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,15 @@ inline const T* TPtr(const void* ptr) {
return reinterpret_cast<const T*>(ptr);
}

/* Checks if the pointer is between values 0-63. */
inline BOL PtrIsValid(const void* ptr) { return IUW(ptr) >= CrabsErrorCount; }

// Checks if the input is aligned to the T word boundary.
template<typename T = void>
inline BOL TAlignIs(const T* input) { return (IUW(input) & (sizeof(T) - 1)) == 0; }
template<typename T = IUW, typename I = T>
inline BOL TAlignIs(I input) { return (input & (sizeof(T) - 1)) == 0; }

/* Syntactical sugar for reinterpret_cast using templates. */
template<typename T = void>
inline T* CPtr(const void* ptr) {
Expand Down Expand Up @@ -342,7 +351,7 @@ inline const void* AlignUpPTR(const void* pointer, ISW mask = ALUWordMask) {
@param value The value to align.
@param mask The power of 2 to align to minus 1 (makes the mask). */
template<typename T = CHA>
inline T* TPtrAlignUp(void* pointer, ISW mask = ALUWordMask) {
inline T* TPtrUp(void* pointer, ISW mask = ALUWordMask) {
ISW value = ISW(pointer);
return TPtr<T>(value + ((-value) & mask));
}
Expand All @@ -352,7 +361,7 @@ inline T* TPtrAlignUp(void* pointer, ISW mask = ALUWordMask) {
@param value The value to align.
@param mask The power of 2 to align to minus 1 (makes the mask). */
template<typename T = CHA>
inline T* TPtrAlignUp(const void* pointer, ISW mask = ALUWordMask) {
inline T* TPtrUp(const void* pointer, ISW mask = ALUWordMask) {
ISW value = ISW(pointer);
return TPtr<T>(value + ((-value) & mask));
}
Expand Down Expand Up @@ -416,7 +425,7 @@ inline I TAlignUpArray(I count) {

/* Aligns the given pointer up to the given least_significant_bits_max. */
inline const CHA* AlignUp(const CHA* pointer, IUW least_significant_bits_max) {
return TPtrAlignUp<const CHA>(pointer, least_significant_bits_max);
return TPtrUp<const CHA>(pointer, least_significant_bits_max);
}


Expand Down Expand Up @@ -529,36 +538,36 @@ inline I TAlignDown(I value) {
@param value The value to align.
@param mask The power of 2 to align to minus 1 (makes the mask). */
template<typename T = IUW, typename AlignT = T>
inline T* TPtrAlignDown(void* ptr) {
inline T* TPtrDown(void* ptr) {
IUW value = IUW(ptr);
return TPtr<T>(value - (value & (sizeof(AlignT) - 1)));
}
template<typename T = IUW, typename AlignT = T>
inline const T* TPtrAlignDown(const void* ptr) {
inline const T* TPtrDown(const void* ptr) {
IUW value = IUW(ptr);
return TPtr<const T>(value - (value & (sizeof(AlignT) - 1)));
}
template<typename T = IUW, typename AlignT = T>
inline T* TPtrAlignDown(void* ptr, ISW ptr_offset) {
inline T* TPtrDown(void* ptr, ISW ptr_offset) {
IUW value = IUW(ISW(ptr) + ptr_offset);
return TPtr<T>(value - (value & (sizeof(AlignT) - 1)));
}
template<typename T = IUW, typename AlignT = T>
inline const T* TPtrAlignDown(const void* ptr, ISW ptr_offset) {
inline const T* TPtrDown(const void* ptr, ISW ptr_offset) {
IUW value = IUW(ISW(ptr) + ptr_offset);
return TPtr<const T>(value - (value & (sizeof(AlignT) - 1)));
}

/* Aligns the given pointer down to the given least_significant_bits_max. */
inline CHA* AlignDown(CHA* pointer, IUW least_significant_bits_max) {
return TPtrAlignDown<CHA>(pointer);
return TPtrDown<CHA>(pointer);
}
inline const CHA* AlignDown(const CHA* pointer,
IUW least_significant_bits_max) {
return TPtrAlignDown<const CHA>(pointer);
return TPtrDown<const CHA>(pointer);
}
inline const IUW* AlignDown(const IUW* pointer, IUW least_significant_bits_max) {
return TPtrAlignDown<const IUW>(pointer);
return TPtrDown<const IUW>(pointer);
}
inline IUW* AlignDown(IUW* pointer, IUW least_significant_bits_max) {
return const_cast<IUW*>(
Expand Down
Loading

0 comments on commit c2dda30

Please sign in to comment.