From e630590065cb4fcd8e4b3633105d4fe0f6ce463d Mon Sep 17 00:00:00 2001 From: Ed_ Date: Fri, 20 Feb 2026 21:03:37 -0500 Subject: [PATCH] adjustments --- CONVENTIONS.md | 34 +++++++++++++++++++++++++++++++++- attempt_1/duffle.amd64.win32.h | 11 +++++++++++ attempt_1/main.c | 25 +++++++------------------ 3 files changed, 51 insertions(+), 19 deletions(-) diff --git a/CONVENTIONS.md b/CONVENTIONS.md index ed298ef..60e6b2d 100644 --- a/CONVENTIONS.md +++ b/CONVENTIONS.md @@ -32,7 +32,29 @@ This document outlines the strict C style and architectural conventions expected ## 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. + * Example Struct: + ```c + typedef struct MS_WNDCLASSA { + U4 style; + S8 (*lpfnWndProc)(void*, U4, U8, S8); + S4 cbClsExtra; + // ... + char const* lpszClassName; + } MS_WNDCLASSA; + ``` +* **Multi-line Argument Alignment:** For long function signatures, place one argument per line with a single 4-space indent. + * Example: + ```c + WinAPI B4 ms_read_console( + MS_Handle handle, + UTF8*r buffer, + U4 to_read, + U4*r num_read, + U8 reserved_input_control + ) asm("ReadConsoleA"); + ``` +* **WinAPI Grouping:** Group foreign procedure declarations by their originating OS library (e.g., Kernel32, User32, GDI32) using comment headers. +* **Brace Style:** Use Allman style (braces on a new line) for function bodies or control blocks (`if`, `for`, `switch`, etc.) that are large or complex. Smaller blocks may use K&R style. * **Conditionals:** Always place `else if` and `else` statements on a new line, un-nested from the previous closing brace. ## 5. Memory Management @@ -45,3 +67,13 @@ This document outlines the strict C style and architectural conventions expected * **Correct:** `char const* my_ptr;` (Pointer to a constant character) * **Correct:** `U4 const* const my_ptr;` (Constant pointer to a constant U4) * **Incorrect:** `const char* my_ptr;` + +## 7. Metadata Coupling (X-Macros) +* **Metadata Enums:** Use X-Macros to define Enums that are tightly coupled with static metadata (colors, prefixes, names). + * Example: + ```c + #define Tag_Entries() \ + X(Define, "Define", 0x0018AEFF, ":") \ + X(Call, "Call", 0x00D6A454, "~") + ``` +* **Naming Conventions:** When using X-Macros for Tags, entry names should be PascalCase, and the Enum symbols should be prefixed with the Enum type name (e.g., `tmpl(STag, Define)` -> `STag_Define`). diff --git a/attempt_1/duffle.amd64.win32.h b/attempt_1/duffle.amd64.win32.h index 9a13c9e..646037e 100644 --- a/attempt_1/duffle.amd64.win32.h +++ b/attempt_1/duffle.amd64.win32.h @@ -696,4 +696,15 @@ WinAPI S4 ms_delete_object(void* ho) asm(" #define MS_VK_DOWN 0x28 #define MS_PAGE_EXECUTE_READWRITE 0x40 + +#define MS_WM_CHAR 0x0102 +#define MS_VK_RETURN 0x0D +#define MS_VK_BACK 0x08 +#define MS_VK_TAB 0x09 +#define MS_VK_SPACE 0x20 +#define MS_VK_F5 0x74 +#define MS_VK_PRIOR 0x21 +#define MS_VK_NEXT 0x22 + +#define MS_VK_SHIFT 0x10 #pragma endregion OS_GDI_And_Minimal diff --git a/attempt_1/main.c b/attempt_1/main.c index 3b03c4a..7b7e6d7 100644 --- a/attempt_1/main.c +++ b/attempt_1/main.c @@ -71,15 +71,15 @@ global U4 log_count = 0; global S4 scroll_y_offset = 0; void ms_builtin_print(U8 val) { - if (log_count < 16) { - log_buffer[log_count++] = val; - } + if (log_count < 16) { + log_buffer[log_count++] = val; + } } // Dictionary typedef struct { - U4 val; - U4 offset; + U4 val; + U4 offset; } DictEntry; global DictEntry dict[256]; global U8 dict_count = 0; @@ -216,11 +216,11 @@ IA_ void compile_and_run_tape(void) in_def = false; } } - else if (tag == tmpl(STag, Data)) { + else if (tag == STag_Data) { emit8(0x48); emit8(0x89); emit8(0xC2); // mov rdx, rax emit8(0x48); emit8(0xC7); emit8(0xC0); emit32(val); // mov rax, imm32 } - else if (tag == tmpl(STag, Imm)) + else if (tag == STag_Imm) { if (in_def) { // If we execute something, we jump out of def block first @@ -253,17 +253,6 @@ IA_ void compile_and_run_tape(void) vm_rdx = vm_globals[15]; } -#define MS_WM_CHAR 0x0102 -#define MS_VK_RETURN 0x0D -#define MS_VK_BACK 0x08 -#define MS_VK_TAB 0x09 -#define MS_VK_SPACE 0x20 -#define MS_VK_F5 0x74 -#define MS_VK_PRIOR 0x21 -#define MS_VK_NEXT 0x22 - -#define MS_VK_SHIFT 0x10 - // --- Window Procedure --- S8 win_proc(void* hwnd, U4 msg, U8 wparam, S8 lparam) {