style: use snake_case for constants

This commit is contained in:
2026-10-08 21:04:44 +02:00
parent 57e544f255
commit cb3f187b54
8 changed files with 20 additions and 20 deletions
+1 -1
View File
@@ -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`.
+8 -8
View File
@@ -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)
}
+2 -2
View File
@@ -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
+2 -2
View File
@@ -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 }
}
+3 -3
View File
@@ -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)
}
+1 -1
View File
@@ -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)
+1 -1
View File
@@ -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
+2 -2
View File
@@ -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)