======= General-purpose arrays supporting an initial fixed-size memory buffer
with compile-time support and optimized access (eg: bit-shifts instead of re-interpreting)
Explanation | Examples |
---|---|
// Always dynamically allocated
Array<int>;
Array<int, 0zu>;
Array<int, HEAP>; // Fixed-size buffer of `sizeof(…) == 3zu * sizeof int`
// the default `Allocator …` does not allow
// for further allocation once the buffer is at capacity
Array<int, 3zu, …>;
// — but `Allocator<HEAP>` and any non-default `Allocator`
// may ignore said behavior
Array<int, 3zu, Allocator<HEAP> >; |
Array<int, 3zu> fixed {1, 2}; // int[3] {1, 2, 0}
Array<int> dynamic; // int*
fixed.add(…); // ❌ can’t add to a fixed-sized array
dynamic.add(1, 2, 3); // ✅ int (*)[3] {1, 2, 3} Array<int, 3zu, Allocator<HEAP> > heaped; // int (*)[3] {0, 0, 0}
heaped.add(1, 2, 3); // ✅ int (*)[6] {0, 0, 0, 1, 2, 3} |
// Needs better design
// → floating_point<true, 1zu, 0u>
operate::add<
floating_point<false, 1zu, 0zu>,
floating_point<true, 2zu, 0zu>
>::value;
Function function = {}; // → Function{ARM_64}
// Needs better design
function.addInstruction(…);
Function::addInstruction(INTEL_x86_64, function, …);
Function::addInstruction(function, …);
- Allocator for platform-specific executable memory
- Defaults dynamic memory management on the program heap
- Pre-processed to contain
__FILE__
and__LINE__
diagnostics - Provides the allocator interface for pre-reserved memory
Allocator<> allocator = {}; // → Allocator<byte, HEAP>
allocator.allocate(…);
// Allocates from the program heap
Memory::allocateHeap(…);
Memory::allocateHeap(…, EXECUTABLE | ZEROED);
// Allocates from an instantiated `static` buffer
Memory::allocateStatic(…);
// Likely wouldn't be developed
Memory::allocateStack(…);
with compile-time support.
Akin to how constructors/ destructors allow for more expressive resource management with object lifetimes
class Array {
public:
property<unsigned, get, set> length;
};
Array array = {};
array.length; // get(unsigned&, …)
array.length = 42u; // set(unsigned&, …, 42u)
$0; // function(a) { return a }
$0 + $1; // function(a, b) { return a + b }
$0 + …; // function(a, …) { return a + … }
with compile-time support
Strings may be hashed as unsigned integers for quicker comparison
— see CopperSpice strings
// Inherits from `Array` since both can be SOO optimized
// — quantifies by code units, not by character type
// → String<…, UNICODE>
String<char16_t>; // Standard 16-bit codepoint string
String<char32_t>; // Standard 32-bit codepoint string
String<char8_t>; // Standard 8-bit codepoint string
String<char>; // Standard character strings (supports ASCII and Latin-1 (ISO-8859-1))
String<wchar_t>; // Standard wide character strings