From cb3f187b54df7b61c5172ba0d8e7278c221a86b1 Mon Sep 17 00:00:00 2001 From: hl-valdemar Date: Thu, 8 Oct 2026 21:04:44 +0200 Subject: [PATCH] style: use snake_case for constants --- docs/style.md | 2 +- source/ast/ast.hon | 16 ++++++++-------- source/diagnostics/diagnostics.hon | 4 ++-- source/lexer/scan.hon | 4 ++-- source/lexer/token.hon | 6 +++--- source/parser/parse.hon | 2 +- source/sema/resolve.hon | 2 +- source/strpool/strpool.hon | 4 ++-- 8 files changed, 20 insertions(+), 20 deletions(-) diff --git a/docs/style.md b/docs/style.md index 15f905d..1d3445b 100644 --- a/docs/style.md +++ b/docs/style.md @@ -4,7 +4,7 @@ these guidelines apply to Honey programs, the compiler, and the standard library ## names -- use `snake_case` for procedures, variables, fields, and enum members; `PascalCase` for types; `SCREAMING_SNAKE_CASE` for named sentinel constants. +- use `snake_case` for procedures, variables, constants, fields, and enum members; `PascalCase` for types. - choose names that describe the value or operation. short loop indices are appropriate when their meaning is local. preserve external ABI names. - qualify imported operations with their module, such as `mem.alloc` and `ast.node_count`. mark file-local implementation details with `@hide:file`. diff --git a/source/ast/ast.hon b/source/ast/ast.hon index 12a30c3..0b9a5ab 100644 --- a/source/ast/ast.hon +++ b/source/ast/ast.hon @@ -14,12 +14,12 @@ import "@source/diagnostics" Span :: alias diagnostics.Span DiagnosticId :: alias diagnostics.DiagnosticId -NO_DIAGNOSTIC :: alias diagnostics.NO_DIAGNOSTIC +no_diagnostic :: alias diagnostics.no_diagnostic NodeId :: distinct u32 @hide:file -NO_NODE :: maxval!(NodeId) +no_node :: maxval!(NodeId) LiteralKind :: enum { int, float, string @@ -87,9 +87,9 @@ NodeData :: union { @hide:file Node :: struct { kind NodeKind - main NodeData = NodeData{ node_id = NO_NODE } - data0 NodeData = NodeData{ node_id = NO_NODE } - data1 NodeData = NodeData{ node_id = NO_NODE } + main NodeData = NodeData{ node_id = no_node } + data0 NodeData = NodeData{ node_id = no_node } + data1 NodeData = NodeData{ node_id = no_node } } @hide:file @@ -267,7 +267,7 @@ add_statement_decl proc( mutability Mutability, initializer NodeId, ) NodeId ! mem.AllocError { - raw_type :: if (type) |id| u32(id) else u32(NO_NODE) + raw_type :: if (type) |id| u32(id) else u32(no_node) extra :: try add_extra(builder, name.start) _ = try add_extra(builder, name.end) _ = try add_extra(builder, raw_type) @@ -591,12 +591,12 @@ get_span proc(storage @Storage, id NodeId) Span { @hide:file node_id proc(index usize) NodeId { - debug.assert(u64(index) < u64(NO_NODE)) + debug.assert(u64(index) < u64(no_node)) return NodeId(index) } @hide:file maybe_node_id proc(value u32) ?NodeId { - if (value == u32(NO_NODE)) return null + if (value == u32(no_node)) return null return NodeId(value) } diff --git a/source/diagnostics/diagnostics.hon b/source/diagnostics/diagnostics.hon index ac26d1d..7b80039 100644 --- a/source/diagnostics/diagnostics.hon +++ b/source/diagnostics/diagnostics.hon @@ -7,7 +7,7 @@ Span :: struct { } DiagnosticId :: distinct u32 -NO_DIAGNOSTIC :: maxval!(DiagnosticId) +no_diagnostic :: maxval!(DiagnosticId) Code :: enum { invalid_character, @@ -40,7 +40,7 @@ deinit proc(store @mut Store) void { #! allocates from the retained allocator; the returned ID is valid until deinit. add proc(store @mut Store, code Code, span Span) DiagnosticId ! (mem.AllocError | CapacityError) { - if (store.list.items.len >= usize(NO_DIAGNOSTIC)) return .diagnostic_limit_reached + if (store.list.items.len >= usize(no_diagnostic)) return .diagnostic_limit_reached id :: DiagnosticId(store.list.items.len) try arraylist.append(&store.list, Diagnostic{ code = code, span = span }) return id diff --git a/source/lexer/scan.hon b/source/lexer/scan.hon index bc5d704..527cc67 100644 --- a/source/lexer/scan.hon +++ b/source/lexer/scan.hon @@ -260,9 +260,9 @@ scan_ident proc(start usize, program []u8) ScanIdentResult { # don't intern keywords (already O(1) lookup via token kind) kind :: strmap.get(&keywords, program[start..cursor]) orelse .ident str_id :: if (kind == .ident) - strpool.intern(&strpool.strings, program[start..cursor]) catch strpool.NO_STR + strpool.intern(&strpool.strings, program[start..cursor]) catch strpool.no_str else - strpool.NO_STR + strpool.no_str return ScanIdentResult{ end = cursor, kind = kind, str_id = str_id } } diff --git a/source/lexer/token.hon b/source/lexer/token.hon index 6331738..6063876 100644 --- a/source/lexer/token.hon +++ b/source/lexer/token.hon @@ -3,7 +3,7 @@ import "@source/diagnostics" import "@source/strpool" TokenId :: distinct u32 -NO_TOKEN :: maxval!(TokenId) +no_token :: maxval!(TokenId) TokenData :: union { str_id strpool.StringId @@ -13,7 +13,7 @@ TokenData :: union { Token :: struct { span diagnostics.Span kind TokenKind - data TokenData = TokenData{ str_id = strpool.NO_STR } + data TokenData = TokenData{ str_id = strpool.no_str } } TokenKind :: enum { @@ -73,6 +73,6 @@ render_token proc(token Token, program []u8) void { } token_id proc(index uint) TokenId { - debug.assert(u64(index) < u64(NO_TOKEN)) + debug.assert(u64(index) < u64(no_token)) return TokenId(index) } diff --git a/source/parser/parse.hon b/source/parser/parse.hon index be6b542..38acb1b 100644 --- a/source/parser/parse.hon +++ b/source/parser/parse.hon @@ -332,7 +332,7 @@ parse_primary proc(state @mut State) ast.NodeId ! ParseError { return try ast.add_identifier(&state.builder, token.span) } else: { - diagnostic :: if (token.data.diagnostic != diagnostics.NO_DIAGNOSTIC) + diagnostic :: if (token.data.diagnostic != diagnostics.no_diagnostic) token.data.diagnostic else try diagnostics.add(state.diagnostics, .unexpected_token, token.span) diff --git a/source/sema/resolve.hon b/source/sema/resolve.hon index e353f4a..ab42ecc 100644 --- a/source/sema/resolve.hon +++ b/source/sema/resolve.hon @@ -26,7 +26,7 @@ BindingData :: union { Binding :: struct { kind BindingKind = .none - data BindingData = BindingData{ diagnostic = diagnostics.NO_DIAGNOSTIC } + data BindingData = BindingData{ diagnostic = diagnostics.no_diagnostic } } @hide:file diff --git a/source/strpool/strpool.hon b/source/strpool/strpool.hon index a691f22..6fd74cb 100644 --- a/source/strpool/strpool.hon +++ b/source/strpool/strpool.hon @@ -6,7 +6,7 @@ InternError :: enum { out_of_space } StringId :: alias u32 -NO_STR :: maxval!(StringId) +no_str :: maxval!(StringId) #! global pool owned by main.hon; initialize before scanning and release with deinit. strings StringPool := undefined @@ -38,7 +38,7 @@ deinit proc(pool @mut StringPool) void { intern proc(pool @mut StringPool, str []u8) StringId ! (mem.AllocError | InternError) { if hashmap.get(&pool.ids, str) |id| return id - if (pool.strings.items.len >= usize(NO_STR)) return .out_of_space + if (pool.strings.items.len >= usize(no_str)) return .out_of_space id :: StringId(pool.strings.items.len) owned_str []mut u8 :: try mem.alloc(u8, pool.allocator, str.len)