style: use snake_case for constants
This commit is contained in:
+1
-1
@@ -4,7 +4,7 @@ these guidelines apply to Honey programs, the compiler, and the standard library
|
|||||||
|
|
||||||
## names
|
## 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.
|
- 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`.
|
- qualify imported operations with their module, such as `mem.alloc` and `ast.node_count`. mark file-local implementation details with `@hide:file`.
|
||||||
|
|
||||||
|
|||||||
+8
-8
@@ -14,12 +14,12 @@ import "@source/diagnostics"
|
|||||||
|
|
||||||
Span :: alias diagnostics.Span
|
Span :: alias diagnostics.Span
|
||||||
DiagnosticId :: alias diagnostics.DiagnosticId
|
DiagnosticId :: alias diagnostics.DiagnosticId
|
||||||
NO_DIAGNOSTIC :: alias diagnostics.NO_DIAGNOSTIC
|
no_diagnostic :: alias diagnostics.no_diagnostic
|
||||||
|
|
||||||
NodeId :: distinct u32
|
NodeId :: distinct u32
|
||||||
|
|
||||||
@hide:file
|
@hide:file
|
||||||
NO_NODE :: maxval!(NodeId)
|
no_node :: maxval!(NodeId)
|
||||||
|
|
||||||
LiteralKind :: enum {
|
LiteralKind :: enum {
|
||||||
int, float, string
|
int, float, string
|
||||||
@@ -87,9 +87,9 @@ NodeData :: union {
|
|||||||
@hide:file
|
@hide:file
|
||||||
Node :: struct {
|
Node :: struct {
|
||||||
kind NodeKind
|
kind NodeKind
|
||||||
main NodeData = NodeData{ node_id = NO_NODE }
|
main NodeData = NodeData{ node_id = no_node }
|
||||||
data0 NodeData = NodeData{ node_id = NO_NODE }
|
data0 NodeData = NodeData{ node_id = no_node }
|
||||||
data1 NodeData = NodeData{ node_id = NO_NODE }
|
data1 NodeData = NodeData{ node_id = no_node }
|
||||||
}
|
}
|
||||||
|
|
||||||
@hide:file
|
@hide:file
|
||||||
@@ -267,7 +267,7 @@ add_statement_decl proc(
|
|||||||
mutability Mutability,
|
mutability Mutability,
|
||||||
initializer NodeId,
|
initializer NodeId,
|
||||||
) NodeId ! mem.AllocError {
|
) 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)
|
extra :: try add_extra(builder, name.start)
|
||||||
_ = try add_extra(builder, name.end)
|
_ = try add_extra(builder, name.end)
|
||||||
_ = try add_extra(builder, raw_type)
|
_ = try add_extra(builder, raw_type)
|
||||||
@@ -591,12 +591,12 @@ get_span proc(storage @Storage, id NodeId) Span {
|
|||||||
|
|
||||||
@hide:file
|
@hide:file
|
||||||
node_id proc(index usize) NodeId {
|
node_id proc(index usize) NodeId {
|
||||||
debug.assert(u64(index) < u64(NO_NODE))
|
debug.assert(u64(index) < u64(no_node))
|
||||||
return NodeId(index)
|
return NodeId(index)
|
||||||
}
|
}
|
||||||
|
|
||||||
@hide:file
|
@hide:file
|
||||||
maybe_node_id proc(value u32) ?NodeId {
|
maybe_node_id proc(value u32) ?NodeId {
|
||||||
if (value == u32(NO_NODE)) return null
|
if (value == u32(no_node)) return null
|
||||||
return NodeId(value)
|
return NodeId(value)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ Span :: struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
DiagnosticId :: distinct u32
|
DiagnosticId :: distinct u32
|
||||||
NO_DIAGNOSTIC :: maxval!(DiagnosticId)
|
no_diagnostic :: maxval!(DiagnosticId)
|
||||||
|
|
||||||
Code :: enum {
|
Code :: enum {
|
||||||
invalid_character,
|
invalid_character,
|
||||||
@@ -40,7 +40,7 @@ deinit proc(store @mut Store) void {
|
|||||||
|
|
||||||
#! allocates from the retained allocator; the returned ID is valid until deinit.
|
#! 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) {
|
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)
|
id :: DiagnosticId(store.list.items.len)
|
||||||
try arraylist.append(&store.list, Diagnostic{ code = code, span = span })
|
try arraylist.append(&store.list, Diagnostic{ code = code, span = span })
|
||||||
return id
|
return id
|
||||||
|
|||||||
@@ -260,9 +260,9 @@ scan_ident proc(start usize, program []u8) ScanIdentResult {
|
|||||||
# don't intern keywords (already O(1) lookup via token kind)
|
# don't intern keywords (already O(1) lookup via token kind)
|
||||||
kind :: strmap.get(&keywords, program[start..cursor]) orelse .ident
|
kind :: strmap.get(&keywords, program[start..cursor]) orelse .ident
|
||||||
str_id :: if (kind == .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
|
else
|
||||||
strpool.NO_STR
|
strpool.no_str
|
||||||
return ScanIdentResult{ end = cursor, kind = kind, str_id = str_id }
|
return ScanIdentResult{ end = cursor, kind = kind, str_id = str_id }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ import "@source/diagnostics"
|
|||||||
import "@source/strpool"
|
import "@source/strpool"
|
||||||
|
|
||||||
TokenId :: distinct u32
|
TokenId :: distinct u32
|
||||||
NO_TOKEN :: maxval!(TokenId)
|
no_token :: maxval!(TokenId)
|
||||||
|
|
||||||
TokenData :: union {
|
TokenData :: union {
|
||||||
str_id strpool.StringId
|
str_id strpool.StringId
|
||||||
@@ -13,7 +13,7 @@ TokenData :: union {
|
|||||||
Token :: struct {
|
Token :: struct {
|
||||||
span diagnostics.Span
|
span diagnostics.Span
|
||||||
kind TokenKind
|
kind TokenKind
|
||||||
data TokenData = TokenData{ str_id = strpool.NO_STR }
|
data TokenData = TokenData{ str_id = strpool.no_str }
|
||||||
}
|
}
|
||||||
|
|
||||||
TokenKind :: enum {
|
TokenKind :: enum {
|
||||||
@@ -73,6 +73,6 @@ render_token proc(token Token, program []u8) void {
|
|||||||
}
|
}
|
||||||
|
|
||||||
token_id proc(index uint) TokenId {
|
token_id proc(index uint) TokenId {
|
||||||
debug.assert(u64(index) < u64(NO_TOKEN))
|
debug.assert(u64(index) < u64(no_token))
|
||||||
return TokenId(index)
|
return TokenId(index)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -332,7 +332,7 @@ parse_primary proc(state @mut State) ast.NodeId ! ParseError {
|
|||||||
return try ast.add_identifier(&state.builder, token.span)
|
return try ast.add_identifier(&state.builder, token.span)
|
||||||
}
|
}
|
||||||
else: {
|
else: {
|
||||||
diagnostic :: if (token.data.diagnostic != diagnostics.NO_DIAGNOSTIC)
|
diagnostic :: if (token.data.diagnostic != diagnostics.no_diagnostic)
|
||||||
token.data.diagnostic
|
token.data.diagnostic
|
||||||
else
|
else
|
||||||
try diagnostics.add(state.diagnostics, .unexpected_token, token.span)
|
try diagnostics.add(state.diagnostics, .unexpected_token, token.span)
|
||||||
|
|||||||
@@ -26,7 +26,7 @@ BindingData :: union {
|
|||||||
|
|
||||||
Binding :: struct {
|
Binding :: struct {
|
||||||
kind BindingKind = .none
|
kind BindingKind = .none
|
||||||
data BindingData = BindingData{ diagnostic = diagnostics.NO_DIAGNOSTIC }
|
data BindingData = BindingData{ diagnostic = diagnostics.no_diagnostic }
|
||||||
}
|
}
|
||||||
|
|
||||||
@hide:file
|
@hide:file
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ InternError :: enum { out_of_space }
|
|||||||
|
|
||||||
StringId :: alias u32
|
StringId :: alias u32
|
||||||
|
|
||||||
NO_STR :: maxval!(StringId)
|
no_str :: maxval!(StringId)
|
||||||
|
|
||||||
#! global pool owned by main.hon; initialize before scanning and release with deinit.
|
#! global pool owned by main.hon; initialize before scanning and release with deinit.
|
||||||
strings StringPool := undefined
|
strings StringPool := undefined
|
||||||
@@ -38,7 +38,7 @@ deinit proc(pool @mut StringPool) void {
|
|||||||
intern proc(pool @mut StringPool, str []u8) StringId ! (mem.AllocError | InternError) {
|
intern proc(pool @mut StringPool, str []u8) StringId ! (mem.AllocError | InternError) {
|
||||||
if hashmap.get(&pool.ids, str) |id| return id
|
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)
|
id :: StringId(pool.strings.items.len)
|
||||||
|
|
||||||
owned_str []mut u8 :: try mem.alloc(u8, pool.allocator, str.len)
|
owned_str []mut u8 :: try mem.alloc(u8, pool.allocator, str.len)
|
||||||
|
|||||||
Reference in New Issue
Block a user