mirror of
https://github.com/Ed94/WATL_Exercise.git
synced 2025-08-06 07:12:42 -07:00
progress
need to debugt dump listing
This commit is contained in:
@@ -1,28 +1,31 @@
|
|||||||
root = true
|
root = true
|
||||||
|
|
||||||
|
[*]
|
||||||
|
end_of_line = lf
|
||||||
|
|
||||||
[*.refactor]
|
[*.refactor]
|
||||||
indent_style = space
|
indent_style = space
|
||||||
indent_size = 4
|
indent_size = 4
|
||||||
|
|
||||||
[*.md]
|
[*.md]
|
||||||
indent_style = space
|
indent_style = tab
|
||||||
indent_size = 4
|
indent_size = 4
|
||||||
|
|
||||||
[*.c]
|
[*.c]
|
||||||
indent_style = tab
|
indent_style = tab
|
||||||
indent_size = 4
|
indent_size = 2
|
||||||
|
|
||||||
[*.cpp]
|
[*.cpp]
|
||||||
indent_style = tab
|
indent_style = tab
|
||||||
indent_size = 4
|
indent_size = 2
|
||||||
|
|
||||||
[*.h]
|
[*.h]
|
||||||
indent_style = tab
|
indent_style = tab
|
||||||
indent_size = 4
|
indent_size = 2
|
||||||
|
|
||||||
[*.hpp]
|
[*.hpp]
|
||||||
indent_style = tab
|
indent_style = tab
|
||||||
indent_size = 4
|
indent_size = 2
|
||||||
|
|
||||||
[*.ps1]
|
[*.ps1]
|
||||||
indent_style = tab
|
indent_style = tab
|
||||||
|
194
C/watl.v0.msvc.c
194
C/watl.v0.msvc.c
@@ -367,6 +367,7 @@ Slice_Byte varena__push (VArena* arena, SSIZE amount, SSIZE type_width, Opts_v
|
|||||||
void varena_release(VArena* arena);
|
void varena_release(VArena* arena);
|
||||||
void varena_rewind (VArena* arena, AllocatorSP save_point);
|
void varena_rewind (VArena* arena, AllocatorSP save_point);
|
||||||
void varena_reset (VArena* arena);
|
void varena_reset (VArena* arena);
|
||||||
|
Slice_Byte varena__shrink(VArena* arena, Slice_Byte old_allocation, SSIZE requested_size, Opts_varena* opts);
|
||||||
AllocatorSP varena_save (VArena* arena);
|
AllocatorSP varena_save (VArena* arena);
|
||||||
|
|
||||||
void varena_allocator_proc(AllocatorProc_In in, AllocatorProc_Out* out);
|
void varena_allocator_proc(AllocatorProc_In in, AllocatorProc_Out* out);
|
||||||
@@ -443,7 +444,7 @@ typedef def_struct(KT1L_Info) {
|
|||||||
};
|
};
|
||||||
SSIZE kt1l__populate_slice_a2(KT1L_Byte* kt, KT1L_Info info, Slice_Byte values, SSIZE num_values );
|
SSIZE kt1l__populate_slice_a2(KT1L_Byte* kt, KT1L_Info info, Slice_Byte values, SSIZE num_values );
|
||||||
#define kt1l_populate_slice_a2(type, kt, ainfo, values) kt1l__populate_slice_a2( \
|
#define kt1l_populate_slice_a2(type, kt, ainfo, values) kt1l__populate_slice_a2( \
|
||||||
pcast(KT1L_Byte*, kt), \
|
cast(KT1L_Byte*, kt), \
|
||||||
(KT1L_Info){ \
|
(KT1L_Info){ \
|
||||||
.backing = ainfo, \
|
.backing = ainfo, \
|
||||||
.slot_size = size_of(KT1L_Slot_Str8), \
|
.slot_size = size_of(KT1L_Slot_Str8), \
|
||||||
@@ -511,8 +512,8 @@ typedef def_struct(KT1CX_Info) {
|
|||||||
void kt1cx__init (KT1CX_Info info, KT1CX_Byte* result);
|
void kt1cx__init (KT1CX_Info info, KT1CX_Byte* result);
|
||||||
void kt1cx__clear (KT1CX_Byte kt, KT1CX_ByteMeta meta);
|
void kt1cx__clear (KT1CX_Byte kt, KT1CX_ByteMeta meta);
|
||||||
U64 kt1cx__slot_id(KT1CX_Byte kt, U64 key, KT1CX_ByteMeta meta);
|
U64 kt1cx__slot_id(KT1CX_Byte kt, U64 key, KT1CX_ByteMeta meta);
|
||||||
Slice_Byte kt1cx__get (KT1CX_Byte kt, U64 key, KT1CX_ByteMeta meta);
|
Byte* kt1cx__get (KT1CX_Byte kt, U64 key, KT1CX_ByteMeta meta);
|
||||||
Slice_Byte kt1cx__set (KT1CX_Byte kt, U64 key, Slice_Byte value, AllocatorInfo backing_cells, KT1CX_ByteMeta meta);
|
Byte* kt1cx__set (KT1CX_Byte kt, U64 key, Slice_Byte value, AllocatorInfo backing_cells, KT1CX_ByteMeta meta);
|
||||||
|
|
||||||
#define kt1cx_assert(kt) do { \
|
#define kt1cx_assert(kt) do { \
|
||||||
slice_assert(kt.cell_pool); \
|
slice_assert(kt.cell_pool); \
|
||||||
@@ -573,8 +574,8 @@ Str8Cache str8cache__make( Opts_str8cache_init* opts);
|
|||||||
#define str8cache_make(...) str8cache__make( opt_args(Opts_str8cache_init, __VA_ARGS__))
|
#define str8cache_make(...) str8cache__make( opt_args(Opts_str8cache_init, __VA_ARGS__))
|
||||||
|
|
||||||
void str8cache_clear(KT1CX_Str8 kt);
|
void str8cache_clear(KT1CX_Str8 kt);
|
||||||
Str8 str8cache_get (KT1CX_Str8 kt, U64 key);
|
Str8* str8cache_get (KT1CX_Str8 kt, U64 key);
|
||||||
Str8 str8cache_set (KT1CX_Str8 kt, U64 key, Str8 value, AllocatorInfo str_reserve, AllocatorInfo backing_cells);
|
Str8* str8cache_set (KT1CX_Str8 kt, U64 key, Str8 value, AllocatorInfo str_reserve, AllocatorInfo backing_cells);
|
||||||
|
|
||||||
Str8 cache_str8(Str8Cache* cache, Str8 str);
|
Str8 cache_str8(Str8Cache* cache, Str8 str);
|
||||||
|
|
||||||
@@ -620,16 +621,9 @@ typedef def_enum(U32, WATL_TokKind) {
|
|||||||
WATL_Tok_Text = 0xFFFFFFFF,
|
WATL_Tok_Text = 0xFFFFFFFF,
|
||||||
};
|
};
|
||||||
typedef Str8 WATL_Tok;
|
typedef Str8 WATL_Tok;
|
||||||
// typedef def_struct(WATL_Tok) {
|
|
||||||
// UTF8* code;
|
|
||||||
// byte_pad(8);
|
|
||||||
// };
|
|
||||||
typedef def_Slice(WATL_Tok);
|
typedef def_Slice(WATL_Tok);
|
||||||
typedef def_enum(U32, WATL_LexStatus) {
|
typedef def_enum(U32, WATL_LexStatus) {
|
||||||
WATL_LexStatus_MemFail_SliceConstraintFail = (1 << 0),
|
WATL_LexStatus_MemFail_SliceConstraintFail = (1 << 0),
|
||||||
// WATL_LexStatus_PosUntrackable = (1 << 1),
|
|
||||||
// WATL_LexStatus_UnsupportedCodepoints = (1 << 2),
|
|
||||||
// WATL_LexStatus_MessageOverflow = (1 << 3),
|
|
||||||
};
|
};
|
||||||
typedef def_struct(WATL_Pos) {
|
typedef def_struct(WATL_Pos) {
|
||||||
S32 line;
|
S32 line;
|
||||||
@@ -672,9 +666,6 @@ typedef def_struct(WATL_ParseMsg) {
|
|||||||
};
|
};
|
||||||
typedef def_enum(U32, WATL_ParseStatus) {
|
typedef def_enum(U32, WATL_ParseStatus) {
|
||||||
WATL_ParseStatus_MemFail_SliceConstraintFail = (1 << 0),
|
WATL_ParseStatus_MemFail_SliceConstraintFail = (1 << 0),
|
||||||
// WATL_ParseStatus_PosUntrackable = (1 << 1),
|
|
||||||
// WATL_ParseStatus_UnsupportedTokens = (1 << 2),
|
|
||||||
// WATL_ParseStatus_MessageOverflow = (1 << 3),
|
|
||||||
};
|
};
|
||||||
typedef def_struct(WATL_ParseInfo) {
|
typedef def_struct(WATL_ParseInfo) {
|
||||||
Slice_WATL_Line lines;
|
Slice_WATL_Line lines;
|
||||||
@@ -898,9 +889,48 @@ void farena_allocator_proc(AllocatorProc_In in, AllocatorProc_Out* out)
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case AllocatorOp_Grow:
|
case AllocatorOp_Grow:
|
||||||
case AllocatorOp_Grow_NoZero:
|
case AllocatorOp_Grow_NoZero: {
|
||||||
case AllocatorOp_Shrink:
|
// Check if the allocation is at the end of the arena
|
||||||
assert_msg(false, "not implemented");
|
Byte* alloc_end = in.old_allocation.ptr + in.old_allocation.len;
|
||||||
|
Byte* arena_end = cast(Byte*, cast(SSIZE, arena->start) + arena->used);
|
||||||
|
if (alloc_end != arena_end) {
|
||||||
|
// Not at the end, can't grow in place
|
||||||
|
out->allocation = (Slice_Byte){0};
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Calculate growth
|
||||||
|
SSIZE grow_amount = in.requested_size - in.old_allocation.len;
|
||||||
|
SSIZE aligned_grow = align_pow2(grow_amount, in.alignment ? in.alignment : MEMORY_ALIGNMENT_DEFAULT);
|
||||||
|
SSIZE unused = arena->capacity - arena->used;
|
||||||
|
if (aligned_grow > unused) {
|
||||||
|
// Not enough space
|
||||||
|
out->allocation = (Slice_Byte){0};
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
arena->used += aligned_grow;
|
||||||
|
out->allocation = (Slice_Byte){in.old_allocation.ptr, in.requested_size};
|
||||||
|
memory_zero(in.old_allocation.ptr + in.old_allocation.len, grow_amount * cast(SSIZE, in.op - AllocatorOp_Grow_NoZero));
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
case AllocatorOp_Shrink: {
|
||||||
|
// Check if the allocation is at the end of the arena
|
||||||
|
Byte* alloc_end = in.old_allocation.ptr + in.old_allocation.len;
|
||||||
|
Byte* arena_end = cast(Byte*, cast(SSIZE, arena->start) + arena->used);
|
||||||
|
if (alloc_end != arena_end) {
|
||||||
|
// Not at the end, can't shrink but return adjusted size
|
||||||
|
out->allocation = (Slice_Byte){in.old_allocation.ptr, in.requested_size};
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Calculate shrinkage
|
||||||
|
//SSIZE shrink_amount = in.old_allocation.len - in.requested_size;
|
||||||
|
SSIZE aligned_original = align_pow2(in.old_allocation.len, MEMORY_ALIGNMENT_DEFAULT);
|
||||||
|
SSIZE aligned_new = align_pow2(in.requested_size, in.alignment ? in.alignment : MEMORY_ALIGNMENT_DEFAULT);
|
||||||
|
arena->used -= (aligned_original - aligned_new);
|
||||||
|
out->allocation = (Slice_Byte){in.old_allocation.ptr, in.requested_size};
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case AllocatorOp_Rewind:
|
case AllocatorOp_Rewind:
|
||||||
@@ -914,7 +944,7 @@ void farena_allocator_proc(AllocatorProc_In in, AllocatorProc_Out* out)
|
|||||||
out->features =
|
out->features =
|
||||||
AllocatorQuery_Alloc
|
AllocatorQuery_Alloc
|
||||||
| AllocatorQuery_Reset
|
| AllocatorQuery_Reset
|
||||||
// | AllocatorQuery_Resize
|
| AllocatorQuery_Resize
|
||||||
| AllocatorQuery_Rewind
|
| AllocatorQuery_Rewind
|
||||||
;
|
;
|
||||||
out->max_alloc = arena->capacity - arena->used;
|
out->max_alloc = arena->capacity - arena->used;
|
||||||
@@ -1010,7 +1040,7 @@ void os_init(void) {
|
|||||||
info->target_page_size = (SSIZE)GetLargePageMinimum();
|
info->target_page_size = (SSIZE)GetLargePageMinimum();
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO(Ed): Large pages disabled for now...
|
// TODO(Ed): Large pages disabled for now... (not failing gracefully)
|
||||||
inline Byte* os__vmem_reserve(SSIZE size, Opts_vmem* opts) {
|
inline Byte* os__vmem_reserve(SSIZE size, Opts_vmem* opts) {
|
||||||
assert(opts != nullptr);
|
assert(opts != nullptr);
|
||||||
void* result = VirtualAlloc(cast(void*, opts->base_addr), size
|
void* result = VirtualAlloc(cast(void*, opts->base_addr), size
|
||||||
@@ -1082,11 +1112,25 @@ Slice_Byte varena__push(VArena* vm, SSIZE amount, SSIZE type_width, Opts_varena*
|
|||||||
return (Slice_Byte){.ptr = cast(Byte*, current_offset), .len = requested_size};
|
return (Slice_Byte){.ptr = cast(Byte*, current_offset), .len = requested_size};
|
||||||
}
|
}
|
||||||
inline void varena_release(VArena* arena) { os_vmem_release(arena, arena->reserve); }
|
inline void varena_release(VArena* arena) { os_vmem_release(arena, arena->reserve); }
|
||||||
|
inline Slice_Byte varena__shrink(VArena* vm, Slice_Byte old_allocation, SSIZE requested_size, Opts_varena* opts) {
|
||||||
|
assert(opts != nullptr);
|
||||||
|
Slice_Byte result = {0};
|
||||||
|
SSIZE current_offset = vm->reserve_start + vm->commit_used;
|
||||||
|
SSIZE shrink_amount = old_allocation.len - requested_size;
|
||||||
|
if (shrink_amount < 0) {
|
||||||
|
result = old_allocation;
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
assert(old_allocation.ptr == cast(Byte*, current_offset));
|
||||||
|
vm->commit_used -= shrink_amount;
|
||||||
|
result = (Slice_Byte){ old_allocation.ptr, requested_size };
|
||||||
|
return result;
|
||||||
|
}
|
||||||
inline
|
inline
|
||||||
void varena_rewind(VArena* vm, AllocatorSP sp) {
|
void varena_rewind(VArena* vm, AllocatorSP sp) {
|
||||||
assert(vm != nullptr);
|
assert(vm != nullptr);
|
||||||
assert(sp.type_sig == & varena_allocator_proc);
|
assert(sp.type_sig == & varena_allocator_proc);
|
||||||
vm->commit_used = sp.slot;
|
vm->commit_used = max(sp.slot, sizeof(VArena));
|
||||||
}
|
}
|
||||||
inline AllocatorSP varena_save(VArena* vm) { return (AllocatorSP){varena_allocator_proc, vm->commit_used}; }
|
inline AllocatorSP varena_save(VArena* vm) { return (AllocatorSP){varena_allocator_proc, vm->commit_used}; }
|
||||||
void varena_allocator_proc(AllocatorProc_In in, AllocatorProc_Out* out)
|
void varena_allocator_proc(AllocatorProc_In in, AllocatorProc_Out* out)
|
||||||
@@ -1231,7 +1275,7 @@ void arena_rewind(Arena* arena, AllocatorSP save_point) {
|
|||||||
SSIZE new_pos = big_pos - curr->base_pos;
|
SSIZE new_pos = big_pos - curr->base_pos;
|
||||||
assert(new_pos <= curr->pos);
|
assert(new_pos <= curr->pos);
|
||||||
curr->pos = new_pos;
|
curr->pos = new_pos;
|
||||||
varena_rewind(curr->backing, (AllocatorSP){varena_allocator_proc, curr->pos});
|
varena_rewind(curr->backing, (AllocatorSP){varena_allocator_proc, curr->pos + sizeof(VArena)});
|
||||||
}
|
}
|
||||||
inline AllocatorSP arena_save(Arena* arena) { return (AllocatorSP){arena_allocator_proc, arena->base_pos + arena->current->pos}; };
|
inline AllocatorSP arena_save(Arena* arena) { return (AllocatorSP){arena_allocator_proc, arena->base_pos + arena->current->pos}; };
|
||||||
void arena_allocator_proc(AllocatorProc_In in, AllocatorProc_Out* out)
|
void arena_allocator_proc(AllocatorProc_In in, AllocatorProc_Out* out)
|
||||||
@@ -1251,11 +1295,59 @@ void arena_allocator_proc(AllocatorProc_In in, AllocatorProc_Out* out)
|
|||||||
case AllocatorOp_Reset:
|
case AllocatorOp_Reset:
|
||||||
arena_reset(arena);
|
arena_reset(arena);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case AllocatorOp_Grow:
|
case AllocatorOp_Grow:
|
||||||
case AllocatorOp_Grow_NoZero:
|
case AllocatorOp_Grow_NoZero: {
|
||||||
case AllocatorOp_Shrink:
|
Arena* active = arena->current;
|
||||||
assert_msg(false, "not implemented");
|
Byte* alloc_end = in.old_allocation.ptr + in.old_allocation.len;
|
||||||
|
Byte* arena_end = cast(Byte*, active) + active->pos;
|
||||||
|
if (alloc_end == arena_end)
|
||||||
|
{
|
||||||
|
SSIZE grow_amount = in.requested_size - in.old_allocation.len;
|
||||||
|
SSIZE aligned_grow = align_pow2(grow_amount, in.alignment ? in.alignment : MEMORY_ALIGNMENT_DEFAULT);
|
||||||
|
if (active->pos + aligned_grow <= active->backing->reserve)
|
||||||
|
{
|
||||||
|
Slice_Byte vresult = varena_push_array(active->backing, Byte, aligned_grow, .alignment = in.alignment);
|
||||||
|
if (vresult.ptr != nullptr)
|
||||||
|
{
|
||||||
|
active->pos += aligned_grow;
|
||||||
|
out->allocation = (Slice_Byte){in.old_allocation.ptr, in.requested_size};
|
||||||
|
out->continuity_break = false;
|
||||||
|
memory_zero(in.old_allocation.ptr + in.old_allocation.len, grow_amount * (cast(SSIZE, in.op) - AllocatorOp_Grow_NoZero));
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Slice_Byte new_alloc = arena__push(arena, in.requested_size, 1, &(Opts_arena){.alignment = in.alignment});
|
||||||
|
if (new_alloc.ptr == nullptr) {
|
||||||
|
out->allocation = (Slice_Byte){0};
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
memory_copy(new_alloc.ptr, in.old_allocation.ptr, in.old_allocation.len);
|
||||||
|
memory_zero(new_alloc.ptr + in.old_allocation.len, (in.requested_size - in.old_allocation.len) * (cast(SSIZE, in.op) - AllocatorOp_Grow_NoZero) );
|
||||||
|
out->allocation = new_alloc;
|
||||||
|
out->continuity_break = true;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
case AllocatorOp_Shrink: {
|
||||||
|
Arena* active = arena->current;
|
||||||
|
Byte* alloc_end = in.old_allocation.ptr + in.old_allocation.len;
|
||||||
|
Byte* arena_end = cast(Byte*, active) + active->pos;
|
||||||
|
if (alloc_end != arena_end) {
|
||||||
|
out->allocation = (Slice_Byte){in.old_allocation.ptr, in.requested_size};
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
//SSIZE shrink_amount = in.old_allocation.len - in.requested_size;
|
||||||
|
SSIZE aligned_original = align_pow2(in.old_allocation.len, MEMORY_ALIGNMENT_DEFAULT);
|
||||||
|
SSIZE aligned_new = align_pow2(in.requested_size, in.alignment ? in.alignment : MEMORY_ALIGNMENT_DEFAULT);
|
||||||
|
SSIZE pos_reduction = aligned_original - aligned_new;
|
||||||
|
active->pos -= pos_reduction;
|
||||||
|
varena__shrink(active->backing, in.old_allocation, in.requested_size, &(Opts_varena){.alignment = in.alignment});
|
||||||
|
out->allocation = (Slice_Byte){in.old_allocation.ptr, in.requested_size};
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
case AllocatorOp_Rewind:
|
case AllocatorOp_Rewind:
|
||||||
arena_rewind(arena, * cast(AllocatorSP*, in.old_allocation.ptr));
|
arena_rewind(arena, * cast(AllocatorSP*, in.old_allocation.ptr));
|
||||||
break;
|
break;
|
||||||
@@ -1266,7 +1358,7 @@ void arena_allocator_proc(AllocatorProc_In in, AllocatorProc_Out* out)
|
|||||||
case AllocatorOp_Query:
|
case AllocatorOp_Query:
|
||||||
out->features =
|
out->features =
|
||||||
AllocatorQuery_Alloc
|
AllocatorQuery_Alloc
|
||||||
// | AllocatorQuery_Resize
|
| AllocatorQuery_Resize
|
||||||
| AllocatorQuery_Reset
|
| AllocatorQuery_Reset
|
||||||
| AllocatorQuery_Rewind
|
| AllocatorQuery_Rewind
|
||||||
;
|
;
|
||||||
@@ -1347,7 +1439,7 @@ U64 kt1cx__slot_id(KT1CX_Byte kt, U64 key, KT1CX_ByteMeta m) {
|
|||||||
U64 hash_index = key % cast(U64, kt.table.len * m.cell_size);
|
U64 hash_index = key % cast(U64, kt.table.len * m.cell_size);
|
||||||
return hash_index;
|
return hash_index;
|
||||||
}
|
}
|
||||||
Slice_Byte kt1cx__get(KT1CX_Byte kt, U64 key, KT1CX_ByteMeta m) {
|
Byte* kt1cx__get(KT1CX_Byte kt, U64 key, KT1CX_ByteMeta m) {
|
||||||
U64 hash_index = kt1cx__slot_id(kt, key, m);
|
U64 hash_index = kt1cx__slot_id(kt, key, m);
|
||||||
Slice_Byte cell = { & kt.table.ptr[hash_index], m.cell_size};
|
Slice_Byte cell = { & kt.table.ptr[hash_index], m.cell_size};
|
||||||
{
|
{
|
||||||
@@ -1357,8 +1449,8 @@ Slice_Byte kt1cx__get(KT1CX_Byte kt, U64 key, KT1CX_ByteMeta m) {
|
|||||||
process_slots:
|
process_slots:
|
||||||
KT1CX_Byte_Slot* slot = cast(KT1CX_Byte_Slot*, slot_cursor + m.slot_key_offset);
|
KT1CX_Byte_Slot* slot = cast(KT1CX_Byte_Slot*, slot_cursor + m.slot_key_offset);
|
||||||
if (slot->occupied && slot->key == key) {
|
if (slot->occupied && slot->key == key) {
|
||||||
Slice_Byte slot_value = {slot_cursor, m.type_width};
|
//Slice_Byte slot_value = {slot_cursor, m.type_width};
|
||||||
return slot_value;
|
return slot_cursor;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Byte* slot_next = slot_cursor + m.cell_next_offset;
|
Byte* slot_next = slot_cursor + m.cell_next_offset;
|
||||||
@@ -1368,11 +1460,11 @@ Slice_Byte kt1cx__get(KT1CX_Byte kt, U64 key, KT1CX_ByteMeta m) {
|
|||||||
goto process_slots;
|
goto process_slots;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
return (Slice_Byte){0};
|
return nullptr;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Slice_Byte kt1cx__set(KT1CX_Byte kt, U64 key, Slice_Byte value, AllocatorInfo backing_cells, KT1CX_ByteMeta m) {
|
Byte* kt1cx__set(KT1CX_Byte kt, U64 key, Slice_Byte value, AllocatorInfo backing_cells, KT1CX_ByteMeta m) {
|
||||||
U64 hash_index = kt1cx__slot_id(kt, key, m);
|
U64 hash_index = kt1cx__slot_id(kt, key, m);
|
||||||
Slice_Byte cell = { & kt.table.ptr[hash_index], m.cell_size};
|
Slice_Byte cell = { & kt.table.ptr[hash_index], m.cell_size};
|
||||||
{
|
{
|
||||||
@@ -1384,12 +1476,12 @@ Slice_Byte kt1cx__set(KT1CX_Byte kt, U64 key, Slice_Byte value, AllocatorInfo ba
|
|||||||
if (slot->occupied == false) {
|
if (slot->occupied == false) {
|
||||||
slot->occupied = true;
|
slot->occupied = true;
|
||||||
slot->key = key;
|
slot->key = key;
|
||||||
Slice_Byte slot_value = {slot_cursor, m.type_width};
|
//Slice_Byte slot_value = {slot_cursor, m.type_width};
|
||||||
return slot_value;
|
return slot_cursor;
|
||||||
}
|
}
|
||||||
else if (slot->key == key) {
|
else if (slot->key == key) {
|
||||||
Slice_Byte slot_value = {slot_cursor, m.type_width};
|
//Slice_Byte slot_value = {slot_cursor, m.type_width};
|
||||||
return slot_value;
|
return slot_cursor;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
KT1CX_Byte_Cell curr_cell = { slot_cursor + m.cell_next_offset };
|
KT1CX_Byte_Cell curr_cell = { slot_cursor + m.cell_next_offset };
|
||||||
@@ -1405,12 +1497,12 @@ Slice_Byte kt1cx__set(KT1CX_Byte kt, U64 key, Slice_Byte value, AllocatorInfo ba
|
|||||||
KT1CX_Byte_Slot* slot = cast(KT1CX_Byte_Slot*, new_cell.ptr + m.slot_key_offset);
|
KT1CX_Byte_Slot* slot = cast(KT1CX_Byte_Slot*, new_cell.ptr + m.slot_key_offset);
|
||||||
slot->occupied = true;
|
slot->occupied = true;
|
||||||
slot->key = key;
|
slot->key = key;
|
||||||
Slice_Byte slot_value = {new_cell.ptr, m.type_width};
|
//Slice_Byte slot_value = {new_cell.ptr, m.type_width};
|
||||||
return slot_value;
|
return new_cell.ptr;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
assert_msg(false, "impossible path");
|
assert_msg(false, "impossible path");
|
||||||
return (Slice_Byte){0};
|
return nullptr;
|
||||||
}
|
}
|
||||||
#pragma endregion Key Table
|
#pragma endregion Key Table
|
||||||
|
|
||||||
@@ -1579,7 +1671,7 @@ Str8 str8__fmt_kt1l(AllocatorInfo ainfo, Slice_Byte buffer, KT1L_Str8 table, Str
|
|||||||
}
|
}
|
||||||
inline
|
inline
|
||||||
Str8 str8__fmt_backed(AllocatorInfo tbl_backing, AllocatorInfo buf_backing, Str8 fmt_template, Slice_A2_Str8* entries) {
|
Str8 str8__fmt_backed(AllocatorInfo tbl_backing, AllocatorInfo buf_backing, Str8 fmt_template, Slice_A2_Str8* entries) {
|
||||||
KT1L_Str8 kt; SSIZE num_bytes = kt1l_populate_slice_a2(Str8, kt, tbl_backing, *entries );
|
KT1L_Str8 kt; SSIZE num_bytes = kt1l_populate_slice_a2(Str8, & kt, tbl_backing, *entries );
|
||||||
SSIZE buf_size = fmt_template.len + num_bytes; buf_size = buf_size > kilo(16) ? buf_size : kilo(16);
|
SSIZE buf_size = fmt_template.len + num_bytes; buf_size = buf_size > kilo(16) ? buf_size : kilo(16);
|
||||||
Slice_Byte buffer = mem_alloc(buf_backing, buf_size);
|
Slice_Byte buffer = mem_alloc(buf_backing, buf_size);
|
||||||
Str8 result = str8__fmt_kt1l(buf_backing, buffer, kt, fmt_template);
|
Str8 result = str8__fmt_kt1l(buf_backing, buffer, kt, fmt_template);
|
||||||
@@ -1588,7 +1680,7 @@ Str8 str8__fmt_backed(AllocatorInfo tbl_backing, AllocatorInfo buf_backing, Str8
|
|||||||
Str8 str8__fmt(Str8 fmt_template, Slice_A2_Str8* entries) {
|
Str8 str8__fmt(Str8 fmt_template, Slice_A2_Str8* entries) {
|
||||||
local_persist Byte tbl_mem[kilo(32)]; FArena tbl_arena = farena_make(slice_fmem(tbl_mem));
|
local_persist Byte tbl_mem[kilo(32)]; FArena tbl_arena = farena_make(slice_fmem(tbl_mem));
|
||||||
local_persist Byte buf_mem[kilo(128)];
|
local_persist Byte buf_mem[kilo(128)];
|
||||||
KT1L_Str8 kt = {0}; kt1l_populate_slice_a2(Str8, kt, ainfo_farena(tbl_arena), *entries );
|
KT1L_Str8 kt = {0}; kt1l_populate_slice_a2(Str8, & kt, ainfo_farena(tbl_arena), *entries );
|
||||||
Str8 result = str8__fmt_kt1l((AllocatorInfo){0}, slice_fmem(buf_mem), kt, fmt_template);
|
Str8 result = str8__fmt_kt1l((AllocatorInfo){0}, slice_fmem(buf_mem), kt, fmt_template);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
@@ -1634,9 +1726,9 @@ void str8cache_clear(KT1CX_Str8 kt) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
inline
|
inline
|
||||||
Str8 str8cache_get(KT1CX_Str8 kt, U64 key) {
|
Str8* str8cache_get(KT1CX_Str8 kt, U64 key) {
|
||||||
kt1cx_assert(kt);
|
kt1cx_assert(kt);
|
||||||
Slice_Byte result = kt1cx__get(kt1cx_byte(kt), key
|
Byte* result = kt1cx__get(kt1cx_byte(kt), key
|
||||||
, (KT1CX_ByteMeta){
|
, (KT1CX_ByteMeta){
|
||||||
.slot_size = size_of(KT1CX_Slot_Str8),
|
.slot_size = size_of(KT1CX_Slot_Str8),
|
||||||
.slot_key_offset = offset_of(KT1CX_Slot_Str8, key),
|
.slot_key_offset = offset_of(KT1CX_Slot_Str8, key),
|
||||||
@@ -1646,15 +1738,15 @@ Str8 str8cache_get(KT1CX_Str8 kt, U64 key) {
|
|||||||
.type_width = size_of(Str8),
|
.type_width = size_of(Str8),
|
||||||
.type_name = lit(stringify(Str8))
|
.type_name = lit(stringify(Str8))
|
||||||
});
|
});
|
||||||
return pcast(Str8, result);
|
return cast(Str8*, result);
|
||||||
}
|
}
|
||||||
inline
|
inline
|
||||||
Str8 str8cache_set(KT1CX_Str8 kt, U64 key, Str8 value, AllocatorInfo str_reserve, AllocatorInfo backing_cells) {
|
Str8* str8cache_set(KT1CX_Str8 kt, U64 key, Str8 value, AllocatorInfo str_reserve, AllocatorInfo backing_cells) {
|
||||||
kt1cx_assert(kt);
|
kt1cx_assert(kt);
|
||||||
slice_assert(value);
|
slice_assert(value);
|
||||||
assert(str_reserve.proc != nullptr);
|
assert(str_reserve.proc != nullptr);
|
||||||
assert(backing_cells.proc != nullptr);
|
assert(backing_cells.proc != nullptr);
|
||||||
Slice_Byte entry = kt1cx__set(kt1cx_byte(kt), key, slice_byte(value), backing_cells, (KT1CX_ByteMeta){
|
Byte* entry = kt1cx__set(kt1cx_byte(kt), key, slice_byte(value), backing_cells, (KT1CX_ByteMeta){
|
||||||
.slot_size = size_of(KT1CX_Slot_Str8),
|
.slot_size = size_of(KT1CX_Slot_Str8),
|
||||||
.slot_key_offset = offset_of(KT1CX_Slot_Str8, key),
|
.slot_key_offset = offset_of(KT1CX_Slot_Str8, key),
|
||||||
.cell_next_offset = offset_of(KT1CX_Cell_Str8, next),
|
.cell_next_offset = offset_of(KT1CX_Cell_Str8, next),
|
||||||
@@ -1663,21 +1755,21 @@ Str8 str8cache_set(KT1CX_Str8 kt, U64 key, Str8 value, AllocatorInfo str_reserve
|
|||||||
.type_width = size_of(Str8),
|
.type_width = size_of(Str8),
|
||||||
.type_name = lit(stringify(Str8))
|
.type_name = lit(stringify(Str8))
|
||||||
});
|
});
|
||||||
slice_assert(entry);
|
assert(entry != nullptr);
|
||||||
Str8* result = pcast(Str8*, entry.ptr);
|
Str8* result = pcast(Str8*, entry);
|
||||||
B32 is_empty = (result->len == 0);
|
B32 is_empty = (result->len == 0);
|
||||||
if (is_empty) {
|
if (is_empty) {
|
||||||
* result = alloc_slice(str_reserve, UTF8, value.len);
|
* result = alloc_slice(str_reserve, UTF8, value.len);
|
||||||
slice_copy(* result, value);
|
slice_copy(* result, value);
|
||||||
}
|
}
|
||||||
return * result;
|
return result;
|
||||||
}
|
}
|
||||||
inline
|
inline
|
||||||
Str8 cache_str8(Str8Cache* cache, Str8 str) {
|
Str8 cache_str8(Str8Cache* cache, Str8 str) {
|
||||||
assert(cache != nullptr);
|
assert(cache != nullptr);
|
||||||
U64 key = 0; hash64_djb8(& key, slice_byte(str));
|
U64 key = 0; hash64_djb8(& key, slice_byte(str));
|
||||||
Str8 result = str8cache_set(cache->kt, key, str, cache->str_reserve, cache->cell_reserve);
|
Str8* result = str8cache_set(cache->kt, key, str, cache->str_reserve, cache->cell_reserve);
|
||||||
return result;
|
return * result;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline
|
inline
|
||||||
@@ -1701,7 +1793,7 @@ void str8gen_append_str8(Str8Gen* gen, Str8 str){
|
|||||||
}
|
}
|
||||||
void str8gen__append_fmt(Str8Gen* gen, Str8 fmt_template, Slice_A2_Str8* entries){
|
void str8gen__append_fmt(Str8Gen* gen, Str8 fmt_template, Slice_A2_Str8* entries){
|
||||||
local_persist Byte tbl_mem[kilo(32)]; FArena tbl_arena = farena_make(slice_fmem(tbl_mem));
|
local_persist Byte tbl_mem[kilo(32)]; FArena tbl_arena = farena_make(slice_fmem(tbl_mem));
|
||||||
KT1L_Str8 kt = {0}; kt1l_populate_slice_a2(Str8, kt, ainfo_farena(tbl_arena), *entries );
|
KT1L_Str8 kt = {0}; kt1l_populate_slice_a2(Str8, & kt, ainfo_farena(tbl_arena), *entries );
|
||||||
Slice_Byte buffer = { gen->ptr + gen->len, gen->cap - gen->len };
|
Slice_Byte buffer = { gen->ptr + gen->len, gen->cap - gen->len };
|
||||||
if (buffer.len < kilo(16)) {
|
if (buffer.len < kilo(16)) {
|
||||||
Slice_Byte result = mem_grow(gen->backing, str8gen_slice_byte(* gen), kilo(16) + gen->cap );
|
Slice_Byte result = mem_grow(gen->backing, str8gen_slice_byte(* gen), kilo(16) + gen->cap );
|
||||||
|
Reference in New Issue
Block a user