From bc30206e658216d7769519b565b6d8cb06ee2c25 Mon Sep 17 00:00:00 2001 From: Ed_ Date: Fri, 20 Feb 2026 19:42:19 -0500 Subject: [PATCH] add skill and some adjustments --- .gitignore | 1 + CONVENTIONS.md | 18 +++--- attempt_1/duffle.amd64.win32.h | 18 ++++++ attempt_1/main.c | 109 ++++++++++++++------------------- colorforth-nudge.skill | Bin 0 -> 1249 bytes colorforth-nudge/SKILL.md | 31 ++++++++++ scripts/build.attempt_1.c.ps1 | 6 +- 7 files changed, 108 insertions(+), 75 deletions(-) create mode 100644 colorforth-nudge.skill create mode 100644 colorforth-nudge/SKILL.md diff --git a/.gitignore b/.gitignore index 735fc9a..47104d2 100644 --- a/.gitignore +++ b/.gitignore @@ -3,3 +3,4 @@ references/processed_visuals build bootslop.proj +clay_ui_temp diff --git a/CONVENTIONS.md b/CONVENTIONS.md index d1f61e8..3cbb4ca 100644 --- a/CONVENTIONS.md +++ b/CONVENTIONS.md @@ -27,17 +27,15 @@ This document outlines the strict C style and architectural conventions expected * **Case:** Strictly use `lower_snake_case` for all functions and variables. * **Types:** Use `PascalCase` for type names (`FArena`, `SWord_Tag`). * **WinAPI Symbols:** When declaring foreign Win32 symbols, prefix the C function name with `ms_` (using `lower_snake_case`) and use the `asm("SymbolName")` attribute to link it to the actual DLL export. - * *Correct:* `WinAPI U2 ms_register_class(const MS_WNDCLASSA* lpWndClass) asm("RegisterClassA");` + * *Correct:* `WinAPI U2 ms_register_class_a(const MS_WNDCLASSA* lpWndClass) asm("RegisterClassA");` * *Incorrect:* `WinAPI U2 RegisterClassA(...);` -## 4. Memory Management +## 4. Formatting & Layout +* **Vertical Alignment:** Align related variable declarations, struct fields, and function prototypes into columns to create a "sheet-like" layout. This improves visual parsing. +* **Brace Style:** Use Allman style (braces on a new line) for function bodies control block (`if`, `for`, `switch`, etc.) that spans more than 50 lines or contains nested logic. +* **Conditionals:** Always place `else if` and `else` statements on a new line, un-nested from the previous closing brace. + +## 5. Memory Management * **No Standard Library:** The environment is built with `-nostdlib` and `-ffreestanding`. Never include ``, ``, etc. * **Arenas over Malloc:** Use `FArena` and its associated macros (`farena_push`, `farena_push_type`, `farena_reset`) for all dynamic memory allocations. Do not use raw pointers with manual arithmetic when an arena can handle it. -* **Memory Ops:** Use `mem_fill` and `mem_copy` instead of standard `memset`/`memcpy` within the application logic. (A minimal `memset`/`memcpy` shim is only provided to satisfy compiler intrinsic struct zeroing under `-nostdlib`). - -## 5. Modifiers -* `internal`: Static functions. -* `global`: Global state variables. -* `IA_`: Internal Always Inline. -* `I_`: Internal Inline. -* Pointers use `*r` (restrict) or `*v` (volatile) macros where applicable. \ No newline at end of file +* **Memory Ops:** Use `mem_fill` and `mem_copy` instead of standard `memset`/`memcpy` within the application logic. diff --git a/attempt_1/duffle.amd64.win32.h b/attempt_1/duffle.amd64.win32.h index eeb0198..7814d93 100644 --- a/attempt_1/duffle.amd64.win32.h +++ b/attempt_1/duffle.amd64.win32.h @@ -182,6 +182,24 @@ IA_ U8 align_pow2(U8 x, U8 b) { return ((x + b - 1) & (~(b - 1))); } +#if 0 +#pragma clang optimize off +// TODO(Ed): Replace these later (only matters if CRT is not used) +void* memset(void* dest, int c, U8 count) { + U1* bytes = (U1*)dest; + while (count--) *bytes++ = (U1)c; + return dest; +} + +void* memcpy(void* dest, const void* src, U8 count) { + U1* d = (U1*)dest; + const U1* s = (const U1*)src; + while (count--) *d++ = *s++; + return dest; +} +#pragma clang optimize on +#endif + IA_ U8 mem_copy (U8 dest, U8 src, U8 len) { return (U8)(__builtin_memcpy ((void*)dest, (void const*)src, len)); } IA_ U8 mem_copy_overlapping(U8 dest, U8 src, U8 len) { return (U8)(__builtin_memmove((void*)dest, (void const*)src, len)); } IA_ U8 mem_fill (U8 dest, U8 value, U8 len) { return (U8)(__builtin_memset ((void*)dest, (int) value, len)); } diff --git a/attempt_1/main.c b/attempt_1/main.c index 849a999..20a46ba 100644 --- a/attempt_1/main.c +++ b/attempt_1/main.c @@ -93,21 +93,6 @@ typedef struct { global DictEntry dict[256]; global U8 dict_count = 0; -#pragma clang optimize off -void* memset(void* dest, int c, U8 count) { - U1* bytes = (U1*)dest; - while (count--) *bytes++ = (U1)c; - return dest; -} - -void* memcpy(void* dest, const void* src, U8 count) { - U1* d = (U1*)dest; - const U1* s = (const U1*)src; - while (count--) *d++ = *s++; - return dest; -} -#pragma clang optimize on - IA_ void scatter(U4 token, const char* anno_str) { if (tape_arena.used + sizeof(U4) <= tape_arena.capacity && anno_arena.used + sizeof(U8) <= anno_arena.capacity) { U4*r ptr = C_(U4*r, tape_arena.start + tape_arena.used); @@ -578,54 +563,54 @@ S8 win_proc(void* hwnd, U4 msg, U8 wparam, S8 lparam) { // Render VM State ms_set_text_color(hdc, 0x00FFFFFF); - char jit_str[64] = "Mode: Incremental | JIT Size: 0x000 bytes"; - if (run_full) mem_copy(u8_(jit_str + 6), u8_("Full "), 11); - u64_to_hex(code_arena.used, jit_str + 32, 3); - ms_text_out_a(hdc, 40, 520, jit_str, 41); - - char state_str[64] = "RAX: 00000000 | RDX: 00000000"; - u64_to_hex(vm_rax, state_str + 5, 8); - u64_to_hex(vm_rdx, state_str + 21, 8); - ms_set_text_color(hdc, 0x0094BAA1); // Number green - ms_text_out_a(hdc, 40, 550, state_str, 29); + char jit_str[64] = "Mode: Incremental | JIT Size: 0x000 bytes"; + if (run_full) mem_copy(u8_(jit_str + 6), u8_("Full "), 11); + u64_to_hex(code_arena.used, jit_str + 32, 3); + ms_text_out_a(hdc, 40, 520, jit_str, 41); - // HUD: Display Current Token Meaning - if (tape_count > 0 && cursor_idx < tape_count) { - U4 cur_tag = UNPACK_TAG(tape_ptr[cursor_idx]); - const char* tag_name = tag_names[cur_tag]; - U4 cur_color = tag_colors[cur_tag]; - - char semantics_str[64] = "Current Tag: "; - U4 name_len = 0; - while (tag_name[name_len]) { - semantics_str[13 + name_len] = tag_name[name_len]; - name_len++; - } - semantics_str[13 + name_len] = '\0'; - - ms_set_text_color(hdc, cur_color); - ms_text_out_a(hdc, 40, 580, semantics_str, 13 + name_len); - } - - ms_set_text_color(hdc, 0x00C8C8C8); - ms_text_out_a(hdc, 400, 520, "Global Memory (Contiguous Array):", 33); - for (int i=0; i<4; i++) { - char glob_str[32] = "[0]: 00000000"; - glob_str[1] = '0' + i; - u64_to_hex(vm_globals[i], glob_str + 5, 8); - ms_set_text_color(hdc, 0x00D6A454); // Soft blue - ms_text_out_a(hdc, 400, 550 + (i * 25), glob_str, 13); - } - - // Print Log - ms_set_text_color(hdc, 0x00C8C8C8); - ms_text_out_a(hdc, 750, 520, "Print Log:", 10); - for (int i=0; i 0 && cursor_idx < tape_count) { + U4 cur_tag = UNPACK_TAG(tape_ptr[cursor_idx]); + const char* tag_name = tag_names[cur_tag]; + U4 cur_color = tag_colors[cur_tag]; + + char semantics_str[64] = "Current Tag: "; + U4 name_len = 0; + while (tag_name[name_len]) { + semantics_str[13 + name_len] = tag_name[name_len]; + name_len++; + } + semantics_str[13 + name_len] = '\0'; + + ms_set_text_color(hdc, cur_color); + ms_text_out_a(hdc, 40, 580, semantics_str, 13 + name_len); + } + + ms_set_text_color(hdc, 0x00C8C8C8); + ms_text_out_a(hdc, 400, 520, "Global Memory (Contiguous Array):", 33); + for (int i=0; i<4; i++) { + char glob_str[32] = "[0]: 00000000"; + glob_str[1] = '0' + i; + u64_to_hex(vm_globals[i], glob_str + 5, 8); + ms_set_text_color(hdc, 0x00D6A454); // Soft blue + ms_text_out_a(hdc, 400, 550 + (i * 25), glob_str, 13); + } + + // Print Log + ms_set_text_color(hdc, 0x00C8C8C8); + ms_text_out_a(hdc, 750, 520, "Print Log:", 10); + for (int i=0; i9*0WC00*iO>*U26n|?GcrL~9*6_L`Z*Xl zF!XbQ^#^-<`uOPOreHHi0m+=+(A@0DZUX<-#T&j@!1z%7-LJFprxM?JdCi(~oIzdc*9 zpZx1u^Tjoqj(kh3d{0g9?X)nfNPW3r%|$Pd3x2F~=B&E6Q^Hb5-b!?3cwA=i_HLWm z&i!u=n?9;u>0^IUS)ND!WoG`GvzvUAnOJ}NTwJZ^&~0{M{he9oF8q2ojYp+Pqj#lr zb<>Us?=ATlJ~Q#W=eSXvsTCY#^VMfv)!IjIydIQ`uzuqI!h0$7nr!A{-`LIdt)?b< z8)lXHob(c9e72SK&zE6@Z za`lzAh7=3=vAlj@{V>Y@)hCuh)gJ%ApC0uU;hW@a(r-GKe^YsAn0xxx0fi;Y(r=Aed`<_5A(zxk&lx#Y>!q?6^vuOcl&FWr6}L&Eg{pM-_g0w|GmC;=lwf& zckFee_WoUHJx}`^kM^NYpG{}IUm$(w=Ft$n-&4N)xT9HJl^Df;&%0+~dCH2S%yRZ( z^?8~v9M$~x<%^m*-#-3cetPt!V~eMLUVilHBiC!Io7WoMU35n+_u=RBoJ?nqUN(7} z+1a6fAo>=gr_Zj?W6UfyuN|2Ujc264XuD*?