From 618cfd396b97891aab0848dd9701084dc00ef845 Mon Sep 17 00:00:00 2001 From: Ed_ Date: Wed, 25 Jun 2025 10:13:20 -0400 Subject: [PATCH] odin progress --- C/watl.v0.msvc.c | 11 ++- Odin/watl.v0.odin | 180 ++++++++++++++++++++++++++++++++++++++++------ 2 files changed, 165 insertions(+), 26 deletions(-) diff --git a/C/watl.v0.msvc.c b/C/watl.v0.msvc.c index 3e3cb89..b4f8c3c 100644 --- a/C/watl.v0.msvc.c +++ b/C/watl.v0.msvc.c @@ -525,13 +525,12 @@ Byte* kt1cx__set (KT1CX_Byte kt, U64 key, Slice_Byte value, AllocatorInfo ba #pragma region String Operations inline B32 char_is_upper(U8 c) { return('A' <= c && c <= 'Z'); } inline U8 char_to_lower(U8 c) { if (char_is_upper(c)) { c += ('a' - 'A'); } return(c); } - -char* str8_to_cstr_capped(Str8 content, Slice_Byte mem); - inline U8 integer_symbols(U8 value) { local_persist U8 lookup_table[16] = { '0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F', }; return lookup_table[value]; } -Str8 str8_from_u32(AllocatorInfo ainfo, U32 num, U32 radix, U8 min_digits, U8 digit_group_separator); + +char* str8_to_cstr_capped(Str8 content, Slice_Byte mem); +Str8 str8_from_u32(AllocatorInfo ainfo, U32 num, U32 radix, U8 min_digits, U8 digit_group_separator); typedef def_farray(Str8, 2); typedef def_Slice(A2_Str8); @@ -568,8 +567,6 @@ typedef def_struct(Opts_str8cache_init) { void str8cache__init(Str8Cache* cache, Opts_str8cache_init* opts); Str8Cache str8cache__make( Opts_str8cache_init* opts); -#define str8gen_slice_byte(gen) (Slice_Byte){ cast(Byte*, (gen).ptr), (gen).cap } - #define str8cache_init(cache, ...) str8cache__init(cache, opt_args(Opts_str8cache_init, __VA_ARGS__)) #define str8cache_make(...) str8cache__make( opt_args(Opts_str8cache_init, __VA_ARGS__)) @@ -588,6 +585,8 @@ typedef def_struct(Str8Gen) { void str8gen_init(Str8Gen* gen, AllocatorInfo backing); Str8Gen str8gen_make( AllocatorInfo backing); +#define str8gen_slice_byte(gen) (Slice_Byte){ cast(Byte*, (gen).ptr), (gen).cap } + inline Str8 str8_from_str8gen(Str8Gen gen) { return (Str8){gen.ptr, gen.len}; } void str8gen_append_str8(Str8Gen* gen, Str8 str); diff --git a/Odin/watl.v0.odin b/Odin/watl.v0.odin index 84d7d36..40580ae 100644 --- a/Odin/watl.v0.odin +++ b/Odin/watl.v0.odin @@ -1,6 +1,6 @@ /* WATL Exercise -Version: 0 (From Scratch, 1-Stage Compilation, MSVC & WinAPI Only, Win CRT Multi-threaded Static Linkage) +Version: 0 (From Scratch, 1-Stage Compilation, WinAPI Only, Win CRT Multi-threaded Static Linkage) Host: Windows 11 (x86-64) Toolchain: odin-lang/Odin dev-2025-06 */ @@ -69,7 +69,7 @@ Raw_Slice :: struct { len: int, } slice_assert :: proc "contextless" (s: $Type / []$SliceType) -> Type { - return assert(len(s) > 0) && s != nil + return assert(len(s) > 0) && assert(s != nil) } slice_end :: proc "contextless" (s : $Type / []$SliceType) -> Type { return s[len(s) - 1] @@ -78,7 +78,7 @@ size_of_slice_type :: proc "contextless" (slice: $Type / []$SliceType) -> int { return size_of(E) } @(require_results) -to_bytes :: proc "contextless" (s: []$Type) -> []byte { +slice_to_bytes :: proc "contextless" (s: []$Type) -> []byte { return ([^]byte)(raw_data(s))[:len(s) * size_of(T)] } slice_zero :: proc "contextless" (data: $Type / []$SliceType) -> Type { @@ -107,12 +107,13 @@ sll_stack_push_n :: proc "contextless" (first: ^$SLL_NodeType, n: ^SLL_NodeType) sll_queue_push_nz :: proc(nil_val: ^$SLL_NodeType, first: ^SLL_NodeType, last: ^SLL_NodeType, n: ^SLL_NodeType) { if first^ == nil_val { first^ = n - last^ = n + last^ = n n.next = nil_val - } else { + } + else { last^.next = n - last^ = n - n.next = nil_val + last^ = n + n.next = nil_val } } sll_queue_push_n :: proc "contextless" (first: ^$SLL_NodeType, last: ^SLL_NodeType, n: ^SLL_NodeType) { @@ -151,11 +152,11 @@ AllocatorSP :: struct { } AllocatorProc :: #type proc (input: AllocatorProc_In, out: ^AllocatorProc_Out) AllocatorProc_In :: struct { - data: rawptr, - requested_size: int, - alignment: int, + data: rawptr, + requested_size: int, + alignment: int, old_allocation: []byte, - op: AllocatorOp, + op: AllocatorOp, } AllocatorProc_Out :: struct { using _ : struct #raw_union { @@ -223,7 +224,7 @@ alloc_slice :: proc(ainfo: AllocatorInfo, $Type: typeid, num : int) -> []Type { //#region("Strings") Raw_String :: struct { data: [^]byte, - len: int, + len: int, } //#endregion("Strings") @@ -231,7 +232,7 @@ Raw_String :: struct { //#region("FArena") FArena :: struct { mem: []byte, - used: int, + used: int, } farena_make :: proc(backing: []byte) -> FArena { arena := FArena {mem = backing}; return arena } farena_init :: proc(arena: ^FArena, backing: []byte) { @@ -321,9 +322,9 @@ Arena :: struct { backing: ^VArena, prev: ^Arena, curr: ^Arena, - base_pos: int, - pos: int, - flags: ArenaFlags, + base_pos: int, + pos: int, + flags: ArenaFlags, } arena_make :: proc() arena_push :: proc() @@ -347,24 +348,163 @@ KT1L_Meta :: struct { slot_size: int, kt_value_offset: int, type_width: int, - type_name: string, + type_name: int, } -kt1l_populate_slice_a2_Slice_Byte :: proc(kt: ^[]KT1L_Slot(byte), m: KT1L_Meta, backing: AllocatorInfo, values: []byte, num_values: []byte) { +kt1l_populate_slice_a2_Slice_Byte :: proc(kt: ^[]KT1L_Slot(byte), m: KT1L_Meta, backing: AllocatorInfo, values: [][2]byte) -> int { } -kt1l_populate_slice_a2 :: proc($Type: typeid, kt: ^[]KT1L_Slot(Type), backing: AllocatorInfo, values: [][2]Type) { - +kt1l_populate_slice_a2 :: proc($Type: typeid, kt: ^[]KT1L_Slot(Type), backing: AllocatorInfo, values: [][2]Type) -> int { + } //#endregion("Key Table 1-Layer Linear (KT1L)") //#region("Key Table 1-Layer Chained-Chunked-Cells (KT1CX)") +KT1CX_Slot :: struct($type: typeid) { + value: type, + key: u64, + occupied: b32, +} +KT1CX_Cell :: struct($type: typeid, $depth: int) { + slots: [depth]KT1CX_Slot(type), + next: ^KT1CX_Cell(type, depth), +} +KT1CX :: struct($type: typeid, $depth: int, $cell: typeid / KT1CX_Cell(type, depth)) { + cell_pool: []cell, + table: []cell, +} +KT1CX_Byte_Slot :: struct { + key: u64, + occupied: b32, +} +KT1CX_Byte_Cell :: struct { + next: ^byte, +} +KT1CX_Byte :: struct { + cell_pool: []byte, + table: []byte, +} +KT1CX_ByteMeta :: struct { + slot_size: int, + slot_key_offset: int, + cell_next_offset: int, + cell_depth: int, + cell_size: int, + type_width: int, + type_name: string, +} +KT1CX_InfoMeta :: struct { + cell_pool_size: int, + table_size: int, + slot_size: int, + slot_key_offset: int, + cell_next_offset: int, + cell_depth: int, + cell_size: int, + type_width: int, + type_name: string, +} +KT1CX_Info :: struct { + backing_table: AllocatorInfo, + backing_cells: AllocatorInfo, +} +kt1cx_init :: proc(info: KT1CX_Info, m: KT1CX_InfoMeta, result: ^KT1CX_Byte) { +} +kt1cx_clear :: proc(kt: KT1CX_Byte, m: KT1CX_ByteMeta) { + +} +kt1cx_slot_id :: proc(kt: KT1CX_Byte, key: u64, m: KT1CX_ByteMeta) { + +} +kt1cx_get :: proc(kt: KT1CX_Byte, key: u64, m: KT1CX_ByteMeta) { + +} +kt1cx_set :: proc(kt: KT1CX_Byte, key: u64, value: []byte, backing_cells: AllocatorInfo, m: KT1CX_ByteMeta) { + +} +kt1cx_assert :: proc(kt: $type / KT1CX) { + slice_assert(kt.cell_pool) + slice_assert(kt.table) +} +kt1cx_byte :: proc(kt: $type / KT1CX) -> KT1CX_Byte { return { slice_to_bytes(kt.cell_pool), slice_to_bytes(kt.table) } } //#endregion("Key Table 1-Layer Chained-Chunked-Cells (KT1CX)") //#region("String Operations") +char_is_upper :: proc(c: u8) -> b32 { return('A' <= c && c <= 'Z') } +char_to_lower :: proc(c: u8) -> u8 { c:=c; if (char_is_upper(c)) { c += ('a' - 'A') }; return (c) } + +integer_symbols :: proc(value: u8) -> u8 { + @static lookup_table: [16]u8 = { '0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F', }; + return lookup_table[value]; +} + +str8_to_cstr_capped :: proc(content: string, mem: []byte) -> cstring { + +} +str8_from_u32 :: proc(ainfo: AllocatorInfo, num: u32, radix: u32 = 10, min_digits: u8 = 0, digit_group_separator: u8 = 0) -> string { + +} + +str8_fmt_backed :: proc(tbl_ainfo, buf_ainfo: AllocatorInfo, fmt_template: string, entries: [][2]string) -> string { + +} +str8_fmt_tmp :: proc(fmt_template: string, entries: [][2]string) -> string { + +} + +Str8Cache_CELL_DEPTH :: 4 + +KT1CX_Slot_Str8 :: KT1CX_Slot(string) +KT1CX_Cell_Str8 :: KT1CX_Cell(string, Str8Cache_CELL_DEPTH) +KT1CX_Str8 :: KT1CX(string, Str8Cache_CELL_DEPTH, KT1CX_Cell_Str8) +Str8Cache :: struct { + str_reserve: AllocatorInfo, + cell_reserve: AllocatorInfo, + tbl_backing: AllocatorInfo, + kt: KT1CX_Str8, +} +str8cache_init :: proc(cache: ^Str8Cache, str_reserve, cell_reserve, tbl_backing: AllocatorInfo, cell_pool_size, table_size: int) { + +} +str8cache_make :: proc(str_reserve, cell_reserve, tbl_backing: AllocatorInfo, cell_pool_size, table_size: int) -> Str8Cache { + cache : Str8Cache; str8cache_init(& cache, str_reserve, cell_reserve, tbl_backing, cell_pool_size, table_size); return cache +} +str8cache_clear :: proc(kt: KT1CX_Str8) { + +} +str8cache_get :: proc(kt: KT1CX_Str8, key: u64) -> ^string { + +} +str8cache_set :: proc(kt: KT1CX_Str8, key: u64, value: string, str_reserve, cell_reserve: AllocatorInfo) -> ^string { + +} +cache_str8 :: proc(cache: ^Str8Cache, str: string) -> ^string { + +} + +Str8Gen :: struct { + backing: AllocatorInfo, + ptr: ^u8, + len: int, + cap: int, +} +str8gen_init :: proc(gen: ^Str8Gen, ainfo: AllocatorInfo) { + +} +str8gen_make :: proc(ainfo: AllocatorInfo) -> Str8Gen { gen: Str8Gen; str8gen_init(& gen, ainfo); return gen } +str8gen_to_bytes :: proc(gen: Str8Gen) -> []byte { return transmute([]byte) Raw_Slice {data = gen.ptr, len = gen.len} } +str8_from_str8gen :: proc(gen: Str8Gen) -> string { return transmute([]string) Raw_Slice {data = gen.ptr, len = gen.len} } + +str8gen_append_str8 :: proc(gen: ^Str8Gen, str: string) { + +} +str8gen_append_fmt :: proc(gen: ^Str8Gen, fmt_template: string, tokens: [][2]string) { + +} //#endregion("String Operations") //#region("File System") + //#endregion("File System") //#region("WATL")