finished collaping arena->allocator info code paths

This commit is contained in:
2025-02-10 01:43:33 -05:00
parent fd44c53e57
commit a54d309fbf
10 changed files with 228 additions and 326 deletions
+2 -2
View File
@@ -71,7 +71,7 @@ UNRESOLVED_GENERIC_SELECTION const assert_generic_selection_fail = {0};
// ----------------------------------------------------------------------------------------------------------------------------------
// Then each definiton of a function has an associated define:
#// #define GENERIC_SLOT_<#>_<generic identifier> <typename>, <function_to_resolve>
// #define GENERIC_SLOT_<#>_<generic identifier> <typename>, <function_to_resolve>
// Then somehwere later on
// <etc> <return_type> <function_id> ( <arguments> ) { <implementation> }
@@ -129,8 +129,8 @@ size_t example_hash__P_long_long( long long val ) { return val * 2654435761ull;
#ifndef type_to_expression
// Used to keep the _Generic keyword happy as bare types are not considered "expressions"
#define type_to_expression(type) (* (type*)NULL)
#endif
// Instead of using this macro, it should be directly expanded by code generation.
#endif
// _Generic also suffers from type compability flatting distinctions between typedef by resolving the selection to the underling type and qualifier.
// To resolve this these distinctions must be enforced using structs that enforce the typedef
+5 -1
View File
@@ -889,6 +889,11 @@ MD_API OperatingSystem operating_system_from_string(String8 string);
////////////////////////////////
//~ rjf: Basic Types & Space Enum -> String Conversions
String8 string_from_dimension (Dimension dimension);
String8 string_from_side (Side side);
String8 string_from_operating_system(OperatingSystem os);
String8 string_from_architecture (Arch arch);
inline String8
string_from_dimension(Dimension dimension) {
local_persist String8 strings[] = {
@@ -1172,7 +1177,6 @@ MD_API void str8_serial_push_u32__ainfo (AllocatorInfo ainfo, String8Lis
#define str8_serial_push_cstr(allocator, srl, str) _Generic(allocator, Arena*: str8_serial_push_cstr__arena, AllocatorInfo: str8_serial_push_cstr__ainfo, default: assert_generic_selection_fail) resolved_function_call(allocator, srl, str)
#define str8_serial_push_string(allocator, slr, str) _Generic(allocator, Arena*: str8_serial_push_string__arena, AllocatorInfo: str8_serial_push_string__ainfo, default: assert_generic_selection_fail) resolved_function_call(allocator, srl, str)
force_inline U64 str8_serial_push_align__arena(Arena* arena, String8List* srl, U64 align) { return str8_serial_push_align__ainfo(arena_allocator(arena), srl, align); }
force_inline void* str8_serial_push_size__arena (Arena* arena, String8List* srl, U64 size) { return str8_serial_push_size__ainfo (arena_allocator(arena), srl, size); }
force_inline void str8_serial_push_u64__arena (Arena* arena, String8List* srl, U64 x) { str8_serial_push_u64__ainfo (arena_allocator(arena), srl, x); }
+34 -95
View File
@@ -1,4 +1,5 @@
#ifdef INTELLISENSE_DIRECTIVES
# include "base/thread_context.h"
# include "mdesk.h"
#endif
@@ -25,26 +26,7 @@ void init(Context* ctx)
//~ rjf: Message Type Functions
void
msg_list_push(Arena* arena, MsgList* msgs, Node* node, MsgKind kind, String8 string)
{
#if MD_DONT_MAP_ANREA_TO_ALLOCATOR_IMPL
Msg*
msg = push_array(arena, Msg, 1);
msg->node = node;
msg->kind = kind;
msg->string = string;
sll_queue_push(msgs->first, msgs->last, msg);
msgs->count += 1;
msgs->worst_message_kind = md_max(kind, msgs->worst_message_kind);
#else
msg_list_alloc(arena_allocator(arena), msgs, node, kind, string);
#endif
}
void
msg_list_alloc(AllocatorInfo ainfo, MsgList* msgs, Node* node, MsgKind kind, String8 string)
msg_list_push__ainfo(AllocatorInfo ainfo, MsgList* msgs, Node* node, MsgKind kind, String8 string)
{
Msg*
msg = alloc_array(ainfo, Msg, 1);
@@ -97,13 +79,7 @@ content_string_from_token_flags_str8(TokenFlags flags, String8 string)
}
String8List
string_list_from_token_flags(Arena* arena, TokenFlags flags)
{
return string_list_from_token_flags_alloc(arena_allocator(arena), flags);
}
String8List
string_list_from_token_flags_alloc(AllocatorInfo ainfo, TokenFlags flags)
string_list_from_token_flags__ainfo(AllocatorInfo ainfo, TokenFlags flags)
{
String8List strs = {0};
if (flags & TokenFlag_Identifier ){ str8_list_push(ainfo, &strs, str8_lit("Identifier" )); }
@@ -121,13 +97,7 @@ string_list_from_token_flags_alloc(AllocatorInfo ainfo, TokenFlags flags)
}
void
token_chunk_list_push(Arena* arena, TokenChunkList* list, U64 cap, Token token)
{
token_chunk_list_alloc(arena_allocator(arena), list, cap, token);
}
void
token_chunk_list_alloc(AllocatorInfo ainfo, TokenChunkList* list, U64 cap, Token token)
token_chunk_list_push__ainfo(AllocatorInfo ainfo, TokenChunkList* list, U64 cap, Token token)
{
TokenChunkNode* node = list->last;
if (node == 0 || node->count >= node->cap) {
@@ -143,13 +113,7 @@ token_chunk_list_alloc(AllocatorInfo ainfo, TokenChunkList* list, U64 cap, Token
}
TokenArray
token_array_from_chunk_list_push(Arena* arena, TokenChunkList* chunks)
{
return token_array_from_chunk_list_alloc(arena_allocator(arena), chunks);
}
TokenArray
token_array_from_chunk_list_alloc(AllocatorInfo ainfo, TokenChunkList* chunks)
token_array_from_chunk_list__ainfo(AllocatorInfo ainfo, TokenChunkList* chunks)
{
TokenArray result = {0};
result.count = chunks->total_token_count;
@@ -204,10 +168,10 @@ unhook(Node* node) {
//- rjf: tree introspection
String8
string_from_children(Arena* arena, Node* root)
string_from_children__ainfo(AllocatorInfo ainfo, Node* root)
{
String8 result;
TempArena scratch = scratch_begin(&arena, 1);
TempArena scratch = scratch_begin(ainfo);
{
String8List strs = {0};
for each_node(child, root->first)
@@ -218,7 +182,7 @@ string_from_children(Arena* arena, Node* root)
str8_list_push(scratch.arena, &strs, child->string);
}
result = str8_list_join(arena, &strs, 0);
result = str8_list_join(ainfo, &strs, 0);
}
scratch_end(scratch);
return result;
@@ -283,13 +247,7 @@ tree_match(Node* a, Node* b, StringMatchFlags flags)
//- rjf: tree duplication
Node*
tree_copy(Arena* arena, Node* src_root)
{
return tree_copy_alloc(arena_allocator(arena), src_root);
}
Node*
tree_copy_alloc(AllocatorInfo ainfo, Node* src_root)
tree_copy__ainfo(AllocatorInfo ainfo, Node* src_root)
{
Node* dst_root = nil_node();
Node* dst_parent = dst_root;
@@ -329,12 +287,7 @@ tree_copy_alloc(AllocatorInfo ainfo, Node* src_root)
//~ rjf: Text -> Tokens Functions
TokenizeResult
tokenize_from_text(Arena* arena, String8 text) {
return tokenize_from_text_alloc(arena_allocator(arena), text);
}
TokenizeResult
tokenize_from_text_alloc(AllocatorInfo ainfo, String8 text)
tokenize_from_text__ainfo(AllocatorInfo ainfo, String8 text)
{
TempArena scratch = scratch_begin(ainfo);
@@ -641,22 +594,22 @@ tokenize_from_text_alloc(AllocatorInfo ainfo, String8 text)
//- rjf: push errors on unterminated comments
if (token_flags & TokenFlag_BrokenComment)
{
Node* error = alloc_node(ainfo, NodeKind_ErrorMarker, 0, str8_lit(""), str8_lit(""), token_start - byte_first);
Node* error = push_node(ainfo, NodeKind_ErrorMarker, 0, str8_lit(""), str8_lit(""), token_start - byte_first);
String8 error_string = str8_lit("Unterminated comment.");
msg_list_alloc(ainfo, &msgs, error, MsgKind_Error, error_string);
msg_list_push(ainfo, &msgs, error, MsgKind_Error, error_string);
}
//- rjf: push errors on unterminated strings
if (token_flags & TokenFlag_BrokenStringLiteral) {
Node* error = alloc_node(ainfo, NodeKind_ErrorMarker, 0, str8_lit(""), str8_lit(""), token_start - byte_first);
Node* error = push_node(ainfo, NodeKind_ErrorMarker, 0, str8_lit(""), str8_lit(""), token_start - byte_first);
String8 error_string = str8_lit("Unterminated string literal.");
msg_list_alloc(ainfo, &msgs, error, MsgKind_Error, error_string);
msg_list_push(ainfo, &msgs, error, MsgKind_Error, error_string);
}
}
//- rjf: bake, fill & return
TokenizeResult result = {0}; {
result.tokens = token_array_from_chunk_list_alloc(ainfo, &tokens);
result.tokens = token_array_from_chunk_list(ainfo, &tokens);
result.msgs = msgs;
}
scratch_end(scratch);
@@ -713,18 +666,13 @@ void parse__work_pop(ParseWorkNode* work_top, ParseWorkNode* broken_work) {
}
ParseResult
parse_from_text_tokens_push(Arena* arena, String8 filename, String8 text, TokenArray tokens) {
return parse_from_text_tokens_alloc(arena_allocator(arena), filename, text, tokens);
}
ParseResult
parse_from_text_tokens_alloc(AllocatorInfo ainfo, String8 filename, String8 text, TokenArray tokens)
parse_from_text_tokens__ainfo(AllocatorInfo ainfo, String8 filename, String8 text, TokenArray tokens)
{
TempArena scratch = scratch_begin(ainfo);
//- rjf: set up outputs
MsgList msgs = {0};
Node* root = alloc_node(ainfo, NodeKind_File, 0, filename, text, 0);
Node* root = push_node(ainfo, NodeKind_File, 0, filename, text, 0);
//- rjf: set up parse rule stack
ParseWorkNode first_work = { 0, ParseWorkKind_Main, root };
@@ -819,9 +767,9 @@ parse_from_text_tokens_alloc(AllocatorInfo ainfo, String8 filename, String8 text
//- rjf: [main, main_implicit] unexpected reserved tokens
if (mode_main_or_main_implict && found_unexpected) {
Node* error = alloc_node(ainfo, NodeKind_ErrorMarker, 0, token_string, token_string, token->range.min);
Node* error = push_node(ainfo, NodeKind_ErrorMarker, 0, token_string, token_string, token->range.min);
String8 error_string = str8f(ainfo, "Unexpected reserved symbol \"%S\".", token_string);
msg_list_alloc(ainfo, &msgs, error, MsgKind_Error, error_string);
msg_list_push(ainfo, &msgs, error, MsgKind_Error, error_string);
token += 1;
goto end_consume;
}
@@ -834,9 +782,9 @@ parse_from_text_tokens_alloc(AllocatorInfo ainfo, String8 filename, String8 text
// Token after should be label.
if (token + 1 >= tokens_opl || !(token[1].flags & TokenFlagGroup_Label))
{
Node* error = alloc_node(ainfo, NodeKind_ErrorMarker, 0, token_string, token_string, token->range.min);
Node* error = push_node(ainfo, NodeKind_ErrorMarker, 0, token_string, token_string, token->range.min);
String8 error_string = str8_lit("Tag label expected after @ symbol.");
msg_list_alloc(ainfo, &msgs, error, MsgKind_Error, error_string);
msg_list_push(ainfo, &msgs, error, MsgKind_Error, error_string);
token += 1;
goto end_consume;
@@ -847,7 +795,7 @@ parse_from_text_tokens_alloc(AllocatorInfo ainfo, String8 filename, String8 text
String8 tag_name_raw = str8_substr(text, token[1].range);
String8 tag_name = content_string_from_token_flags_str8(token[1].flags, tag_name_raw);
Node* node = alloc_node(ainfo, NodeKind_Tag, node_flags_from_token_flags(token[1].flags), tag_name, tag_name_raw, token[0].range.min);
Node* node = push_node(ainfo, NodeKind_Tag, node_flags_from_token_flags(token[1].flags), tag_name, tag_name_raw, token[0].range.min);
dll_push_back_npz(nil_node(), work_top->first_gathered_tag, work_top->last_gathered_tag, node, next, prev);
B32 found_argument_paren = token[2].flags & TokenFlag_Reserved && str8_match(str8_substr(text, token[2].range), str8_lit("("), 0);
@@ -874,7 +822,7 @@ parse_from_text_tokens_alloc(AllocatorInfo ainfo, String8 filename, String8 text
work_top->gathered_node_flags = 0;
Node* node = alloc_node(ainfo, NodeKind_Main, flags, node_string, node_string_raw, token[0].range.min);
Node* node = push_node(ainfo, NodeKind_Main, flags, node_string, node_string_raw, token[0].range.min);
node->first_tag = work_top->first_gathered_tag;
node->last_tag = work_top->last_gathered_tag;
for (Node* tag = work_top->first_gathered_tag; !node_is_nil(tag); tag = tag->next) {
@@ -905,7 +853,7 @@ parse_from_text_tokens_alloc(AllocatorInfo ainfo, String8 filename, String8 text
work_top->gathered_node_flags = 0;
Node*
node = alloc_node(ainfo, NodeKind_Main, flags, str8_lit(""), str8_lit(""), token[0].range.min);
node = push_node(ainfo, NodeKind_Main, flags, str8_lit(""), str8_lit(""), token[0].range.min);
node->first_tag = work_top->first_gathered_tag;
node->last_tag = work_top->last_gathered_tag;
for (Node* tag = work_top->first_gathered_tag; !node_is_nil(tag); tag = tag->next) {
@@ -960,9 +908,9 @@ parse_from_text_tokens_alloc(AllocatorInfo ainfo, String8 filename, String8 text
if (work_top->counted_newlines >= 2)
{
Node* node = work_top->parent;
Node* error = alloc_node(ainfo, NodeKind_ErrorMarker, 0, token_string, token_string, token->range.min);
Node* error = push_node(ainfo, NodeKind_ErrorMarker, 0, token_string, token_string, token->range.min);
String8 error_string = str8f(ainfo, "More than two newlines following \"%S\", which has implicitly-delimited children, resulting in an empty list of children.", node->string);
msg_list_alloc(ainfo, &msgs, error, MsgKind_Warning, error_string);
msg_list_push(ainfo, &msgs, error, MsgKind_Warning, error_string);
parse_work_pop();
}
else
@@ -1009,9 +957,9 @@ parse_from_text_tokens_alloc(AllocatorInfo ainfo, String8 filename, String8 text
//- rjf: no consumption -> unexpected token! we don't know what to do with this.
{
Node* error = alloc_node(ainfo, NodeKind_ErrorMarker, 0, token_string, token_string, token->range.min);
Node* error = push_node(ainfo, NodeKind_ErrorMarker, 0, token_string, token_string, token->range.min);
String8 error_string = str8f(ainfo, "Unexpected \"%S\" token.", token_string);
msg_list_alloc(ainfo, &msgs, error, MsgKind_Error, error_string);
msg_list_push(ainfo, &msgs, error, MsgKind_Error, error_string);
token += 1;
// ???
}
@@ -1034,19 +982,10 @@ parse_from_text_tokens_alloc(AllocatorInfo ainfo, String8 filename, String8 text
//~ rjf: Bundled Text -> Tree Functions
ParseResult
parse_from_text(Arena* arena, String8 filename, String8 text) {
TempArena scratch = scratch_begin(&arena, 1);
TokenizeResult tokenize = tokenize_from_text(scratch.arena, text);
ParseResult parse = parse_from_text_tokens_push(arena, filename, text, tokenize.tokens);
scratch_end(scratch);
return parse;
}
ParseResult
parse_from_text_alloc(AllocatorInfo ainfo, String8 filename, String8 text) {
parse_from_text__ainfo(AllocatorInfo ainfo, String8 filename, String8 text) {
TempArena scratch = scratch_begin(ainfo);
TokenizeResult tokenize = tokenize_from_text(scratch.arena, text);
ParseResult parse = parse_from_text_tokens_alloc(ainfo, filename, text, tokenize.tokens);
ParseResult parse = parse_from_text_tokens__ainfo(ainfo, filename, text, tokenize.tokens);
scratch_end(scratch);
return parse;
}
@@ -1055,7 +994,7 @@ parse_from_text_alloc(AllocatorInfo ainfo, String8 filename, String8 text) {
//~ rjf: Tree -> Text Functions
String8List
debug_string_list_from_tree(Arena* arena, Node* root)
debug_string_list_from_tree__ainfo(AllocatorInfo ainfo, Node* root)
{
String8List strings = {0};
{
@@ -1084,11 +1023,11 @@ debug_string_list_from_tree(Arena* arena, Node* root)
}
// rjf: push node line
str8_list_pushf(arena, &strings, "%.*s\"%S\" : %S", depth, indentation, node->string, kind_string);
str8_list_pushf(ainfo, &strings, "%.*s\"%S\" : %S", depth, indentation, node->string, kind_string);
// rjf: children -> open brace
if (rec.push_count != 0) {
str8_list_pushf(arena, &strings, "%.*s\n{", depth, indentation);
str8_list_pushf(ainfo, &strings, "%.*s\n{", depth, indentation);
}
// rjf: descend
@@ -1096,7 +1035,7 @@ debug_string_list_from_tree(Arena* arena, Node* root)
// rjf: popping -> close braces
for (S32 pop_idx = 0; pop_idx < rec.pop_count; pop_idx += 1) {
str8_list_pushf(arena, &strings, "%.*s\n}", depth - 1 - pop_idx, indentation);
str8_list_pushf(ainfo, &strings, "%.*s\n}", depth - 1 - pop_idx, indentation);
}
// rjf: ascend
+70 -45
View File
@@ -270,21 +270,26 @@ nil_node()
// NOTE(Ed): The are see comments in Context struct, this is only necessary when not utilizing
// the metadesk os runtime provided entry_point interface
MD_API void init (Context* ctx);
MD_API void init(Context* ctx);
// MD_API void deinit(Context* ctx);
////////////////////////////////
//~ rjf: Message Type Functions
MD_API void msg_list_push (Arena* arena, MsgList* msgs, Node* node, MsgKind kind, String8 string);
MD_API void msg_list_alloc (AllocatorInfo ainfo, MsgList* msgs, Node* node, MsgKind kind, String8 string);
void msg_list_pushf (Arena* arena, MsgList* msgs, Node* node, MsgKind kind, char *fmt, ...);
void msg_list_allocf(AllocatorInfo ainfo, MsgList* msgs, Node* node, MsgKind kind, char *fmt, ...);
void msg_list_push__arena (Arena* arena, MsgList* msgs, Node* node, MsgKind kind, String8 string);
MD_API void msg_list_push__ainfo (AllocatorInfo ainfo, MsgList* msgs, Node* node, MsgKind kind, String8 string);
void msg_list_pushf__arena(Arena* arena, MsgList* msgs, Node* node, MsgKind kind, char *fmt, ...);
void msg_list_pushf__ainfo(AllocatorInfo ainfo, MsgList* msgs, Node* node, MsgKind kind, char *fmt, ...);
#define msg_list_push(allocator, msgs, node, kind, string) _Generic(allocator, Arena*: msg_list_push__arena, AllocatorInfo: msg_list_push__ainfo, default: assert_generic_selection_fail) resolved_function_call(allocator, msgs, node, kind, string)
#define msg_list_pushf(allocator, msgs, node, kind, string, fmt, ...) _Generic(allocator, Arena*: msg_list_pushf__arena, AllocatorInfo: msg_list_pushf__ainfo, default: assert_generic_selection_fail) resolved_function_call(allocator, msgs, node, kind, fmt, __VA_ARGS__)
MD_API void msg_list_concat_in_place(MsgList* dst, MsgList* to_push);
force_inline void msg_list_push__arena(Arena* arena, MsgList* msgs, Node* node, MsgKind kind, String8 string) { msg_list_push__ainfo(arena_allocator(arena), msgs, node, kind, string); }
inline void
msg_list_pushf(Arena* arena, MsgList* msgs, Node* node, MsgKind kind, char* fmt, ...) {
msg_list_pushf__arena(Arena* arena, MsgList* msgs, Node* node, MsgKind kind, char* fmt, ...) {
va_list args;
va_start(args, fmt);
String8 string = str8fv(arena, fmt, args);
@@ -293,11 +298,11 @@ msg_list_pushf(Arena* arena, MsgList* msgs, Node* node, MsgKind kind, char* fmt,
}
inline void
msg_list_allocf(AllocatorInfo ainfo, MsgList* msgs, Node* node, MsgKind kind, char* fmt, ...) {
msg_list_pushf__ainfo(AllocatorInfo ainfo, MsgList* msgs, Node* node, MsgKind kind, char* fmt, ...) {
va_list args;
va_start(args, fmt);
String8 string = str8fv(ainfo, fmt, args);
msg_list_alloc(ainfo, msgs, node, kind, string);
msg_list_push(ainfo, msgs, node, kind, string);
va_end(args);
}
@@ -309,12 +314,20 @@ B32 token_match(Token a, Token b);
MD_API String8 content_string_from_token_flags_str8(TokenFlags flags, String8 string);
MD_API String8List string_list_from_token_flags(Arena* arena, TokenFlags flags);
MD_API String8List string_list_from_token_flags_alloc(AllocatorInfo ainfo, TokenFlags flags);
MD_API void token_chunk_list_push (Arena* arena, TokenChunkList* list, U64 cap, Token token);
MD_API void token_chunk_list_alloc (AllocatorInfo ainfo, TokenChunkList* list, U64 cap, Token token);
MD_API TokenArray token_array_from_chunk_list_push(Arena* arena, TokenChunkList* chunks);
MD_API TokenArray token_array_from_chunk_list_alloc(AllocatorInfo aino, TokenChunkList* chunks);
String8List string_list_from_token_flags__arena(Arena* arena, TokenFlags flags);
MD_API String8List string_list_from_token_flags__ainfo(AllocatorInfo ainfo, TokenFlags flags);
MD_API void token_chunk_list_push__arena (Arena* arena, TokenChunkList* list, U64 cap, Token token);
MD_API void token_chunk_list_push__ainfo (AllocatorInfo ainfo, TokenChunkList* list, U64 cap, Token token);
MD_API TokenArray token_array_from_chunk_list__arena (Arena* arena, TokenChunkList* chunks);
MD_API TokenArray token_array_from_chunk_list__ainfo (AllocatorInfo ainfo, TokenChunkList* chunks);
#define string_list_from_token_flags(allocator, flags) _Generic(allocator, Arena*: string_list_from_token_flags__arena, AllocatorInfo: string_list_from_token_flags__ainfo, default: assert_generic_selection_fail) resolved_function_call(allocator, flags)
#define token_chunk_list_push(allocator, list, cap, token) _Generic(allocator, Arena*: token_chunk_list_push__arena, AllocatorInfo: token_chunk_list_push__ainfo, default: assert_generic_selection_fail) resolved_function_call(allocator, list, cap, token)
#define token_array_from_chunk_list(allocator, chunks) _Generic(allocator, Arena*: token_array_from_chunk_list__arena, AllocatorInfo: token_array_from_chunk_list__ainfo, default: assert_generic_selection_fail) resolved_function_call(allocator, chunks)
force_inline String8List string_list_from_token_flags__arena(Arena* arena, TokenFlags flags) { return string_list_from_token_flags__ainfo(arena_allocator(arena), flags); }
force_inline void token_chunk_list_push__arena (Arena* arena, TokenChunkList* list, U64 cap, Token token) { token_chunk_list_push__ainfo(arena_allocator(arena), list, cap, token); }
force_inline TokenArray token_array_from_chunk_list__arena (Arena* arena, TokenChunkList* chunks) { return token_array_from_chunk_list__ainfo(arena_allocator(arena), chunks); }
inline Token
token_make(Rng1U64 range, TokenFlags flags) {
@@ -364,8 +377,10 @@ MD_API NodeRec node_rec_depth_first(Node* node, Node* subtree_root, U64 child_of
//- rjf: tree building
Node* push_node (Arena* arena, NodeKind kind, NodeFlags flags, String8 string, String8 raw_string, U64 src_offset);
Node* alloc_node(AllocatorInfo ainfo, NodeKind kind, NodeFlags flags, String8 string, String8 raw_string, U64 src_offset);
Node* push_node__arena(Arena* arena, NodeKind kind, NodeFlags flags, String8 string, String8 raw_string, U64 src_offset);
Node* push_node__ainfo(AllocatorInfo ainfo, NodeKind kind, NodeFlags flags, String8 string, String8 raw_string, U64 src_offset);
#define push_node(allocator, kind, flags, string, raw_string, src_offset) _Generic(allocator, Arena*: push_node__arena, AllocatorInfo: push_node__ainfo, default: assert_generic_selection_fail) resolved_function_call(allocator, kind, flags, string, raw_string, src_offset)
void node_insert_tag (Node* parent, Node* prev_child, Node* node);
void node_insert_child(Node* parent, Node* prev_child, Node* node);
@@ -373,24 +388,10 @@ void node_push_child (Node* parent, Node* node);
void node_push_tag (Node* parent, Node* node);
void unhook (Node* node);
inline Node*
push_node(Arena* arena, NodeKind kind, NodeFlags flags, String8 string, String8 raw_string, U64 src_offset) {
#if MD_DONT_MAP_ANREA_TO_ALLOCATOR_IMPL
Node* node = push_array(arena, Node, 1);
node->first = node->last = node->parent = node->next = node->prev = node->first_tag = node->last_tag = nil_node();
node->kind = kind;
node->flags = flags;
node->string = string;
node->raw_string = raw_string;
node->src_offset = src_offset;
return node;
#else
alloc_node(arena_allocator(arena), kind, flags, string, raw_string, src_offset);
#endif
}
inline Node* push_node__arena(Arena* arena, NodeKind kind, NodeFlags flags, String8 string, String8 raw_string, U64 src_offset) { push_node__ainfo(arena_allocator(arena), kind, flags, string, raw_string, src_offset); }
inline Node*
alloc_node(AllocatorInfo ainfo, NodeKind kind, NodeFlags flags, String8 string, String8 raw_string, U64 src_offset) {
push_node__ainfo(AllocatorInfo ainfo, NodeKind kind, NodeFlags flags, String8 string, String8 raw_string, U64 src_offset) {
Node* node = alloc_array(ainfo, Node, 1);
node->first = node->last = node->parent = node->next = node->prev = node->first_tag = node->last_tag = nil_node();
node->kind = kind;
@@ -445,7 +446,12 @@ B32 node_has_tag (Node* node, String8 string, StringMatchFlags flags)
U64 child_count_from_node (Node* node);
U64 tag_count_from_node (Node* node);
MD_API String8 string_from_children(Arena* arena, Node* root);
MD_API String8 string_from_children__arena(Arena* arena, Node* root);
String8 string_from_children__ainfo(AllocatorInfo ainfo, Node* root);
#define string_from_children(allocator, root) _Generic(allocator, Arena*: string_from_children__arena, AllocatorInfo: string_from_children__ainfo, default: assert_generic_selection_fail) resolved_function_call(allocator, root)
force_inline String8 string_from_children__arena(Arena* arena, Node* root) { return string_from_children__ainfo(arena_allocator(arena), root); }
inline Node*
node_from_chain_string(Node* first, Node* opl, String8 string, StringMatchFlags flags)
@@ -552,32 +558,51 @@ MD_API B32 node_match(Node* a, Node* b, StringMatchFlags flags);
//- rjf: tree duplication
MD_API Node* tree_copy (Arena* arena, Node* src_root);
MD_API Node* tree_copy_alloc(AllocatorInfo ainfo, Node* src_root);
MD_API Node* tree_copy__arena(Arena* arena, Node* src_root);
MD_API Node* tree_copy__ainfo(AllocatorInfo ainfo, Node* src_root);
#define tree_copy(allocator, src_root) _Generic(allocator, Arena*: tree_copy__arena, AllocatorInfo: tree_copy__ainfo, default: assert_generic_selection_fail) resolved_function_call(allocator, src_root)
force_inline Node* tree_copy__arena(Arena* arena, Node* src_root) { return tree_copy__ainfo(arena_allocator(arena), src_root); }
////////////////////////////////
//~ rjf: Text -> Tokens Functions
MD_API TokenizeResult tokenize_from_text (Arena* arena, String8 text);
MD_API TokenizeResult tokenize_from_text_alloc(AllocatorInfo ainfo, String8 text);
MD_API TokenizeResult tokenize_from_text__arena(Arena* arena, String8 text);
MD_API TokenizeResult tokenize_from_text__ainfo(AllocatorInfo ainfo, String8 text);
#define tokenize_from_text(allocator, text) _Generic(allocator, Arena*: tokenize_from_text__arena, AllocatorInfo: tokenize_from_text__ainfo, default: assert_generic_selection_fail) resolved_function_call(allocator, text)
force_inline TokenizeResult tokenize_from_text__arena(Arena* arena, String8 text) { return tokenize_from_text__ainfo(arena_allocator(arena), text); }
////////////////////////////////
//~ rjf: Tokens -> Tree Functions
MD_API ParseResult parse_from_text_tokens (Arena* arena, String8 filename, String8 text, TokenArray tokens);
MD_API ParseResult parse_from_text_tokens_alloc(AllocatorInfo ainfo, String8 filename, String8 text, TokenArray tokens);
MD_API ParseResult parse_from_text_tokens__arena(Arena* arena, String8 filename, String8 text, TokenArray tokens);
MD_API ParseResult parse_from_text_tokens__ainfo(AllocatorInfo ainfo, String8 filename, String8 text, TokenArray tokens);
#define parse_from_text_tokens(allocator, filename, text, tokens) _Generic(allocator, Arena*: parse_from_text_tokens__arena, AllocatorInfo: parse_from_text_tokens__ainfo, default: assert_generic_selection_fail) resolved_function_call(allocator, filename, text, tokens)
force_inline ParseResult parse_from_text_tokens__arena(Arena* arena, String8 filename, String8 text, TokenArray tokens) { return parse_from_text_tokens__ainfo(arena_allocator(arena), filename, text, tokens); }
////////////////////////////////
//~ rjf: Bundled Text -> Tree Functions
MD_API ParseResult parse_from_text (Arena* arena, String8 filename, String8 text);
MD_API ParseResult parse_from_text_alloc(AllocatorInfo ainfo, String8 filename, String8 text);
MD_API ParseResult parse_from_text__arena(Arena* arena, String8 filename, String8 text);
MD_API ParseResult parse_from_text__ainfo(AllocatorInfo ainfo, String8 filename, String8 text);
#define tree_from_string(arena, string) (parse_from_text ((arena), str8_zero(), (string)).root)
#define tree_from_string_alloc(ainfo, string) (parse_from_text_alloc((ainfo), str8_zero(), (string)).root)
#define parse_from_text(allocator, filename, text) _Generic(allocator, Arena*: parse_from_text__arena, AllocatorInfo: parse_from_text__ainfo, default: assert_generic_selection_fail) resolved_function_call(allocator, filename, text)
#define tree_from_string(allocator, string) (parse_from_text((allocator), str8_zero(), (string)).root)
force_inline ParseResult parse_from_text__arena(Arena* arena, String8 filename, String8 text) { return parse_from_text__ainfo(arena_allocator(arena), filename, text); }
////////////////////////////////
//~ rjf: Tree -> Text Functions
MD_API String8List debug_string_list_from_tree (Arena* arena, Node* root);
MD_API String8List debug_string_list_from_tree_alloc(AllocatorInfo ainfo, Node* root);
MD_API String8List debug_string_list_from_tree__arena(Arena* arena, Node* root);
MD_API String8List debug_string_list_from_tree__ainfo(AllocatorInfo ainfo, Node* root);
#define debug_string_list_from_tree(allocator, string) _Generic(allocator, Arena*: debug_string_list_from_tree__arena, AllocatorInfo: debug_string_list_from_tree__ainfo, default: assert_generic_selection_fail) resolved_function_call(allocator, string)
force_inline String8List debug_string_list_from_tree__arena(Arena* arena, Node* root) { return debug_string_list_from_tree__ainfo(arena_allocator(arena), root); }
+7 -20
View File
@@ -274,23 +274,10 @@ os_copy_file_path(String8 dst, String8 src)
}
String8
os_full_path_from_path(Arena* arena, String8 path)
os_full_path_from_path__ainfo(AllocatorInfo ainfo, String8 path)
{
char buffer[PATH_MAX] = {0};
TempArena scratch = scratch_begin(&arena, 1); {
String8 path_copy = push_str8_copy(scratch.arena, path);
realpath((char *)path_copy.str, buffer);
}
scratch_end(scratch);
String8 result = push_str8_copy(arena, str8_cstring(buffer));
return result;
}
String8
os_full_path_from_path_alloc(AllocatorInfo ainfo, String8 path)
{
char buffer[PATH_MAX] = {0};
TempArena scratch = scratch_begin_alloc(ainfo); {
TempArena scratch = scratch_begin(ainfo); {
String8 path_copy = push_str8_copy(scratch.arena, path);
realpath((char *)path_copy.str, buffer);
}
@@ -363,15 +350,15 @@ os_file_map_view_close(OS_Handle map, void* ptr, Rng1U64 range) {
//- rjf: directory iteration
OS_FileIter*
os_file_iter_begin(Arena* arena, String8 path, OS_FileIterFlags flags)
os_file_iter_begin__ainfo(AllocatorInfo ainfo, String8 path, OS_FileIterFlags flags)
{
OS_FileIter*
base_iter = push_array(arena, OS_FileIter, 1);
base_iter = alloc_array(ainfo, OS_FileIter, 1);
base_iter->flags = flags;
OS_LNX_FileIter* iter = (OS_LNX_FileIter*)base_iter->memory;
{
String8 path_copy = push_str8_copy(arena, path);
String8 path_copy = str8_copy(arena, path);
iter->dir = opendir((char*)path_copy.str);
iter->path = path_copy;
}
@@ -395,7 +382,7 @@ os_file_iter_next(Arena* arena, OS_FileIter* iter, OS_FileInfo* info_out)
if(good)
{
TempArena scratch = scratch_begin(&arena, 1);
String8 full_path = push_str8f(scratch.arena, "%S/%s", lnx_iter->path, lnx_iter->dp->d_name);
String8 full_path = str8f(scratch.arena, "%S/%s", lnx_iter->path, lnx_iter->dp->d_name);
stat_result = stat((char *)full_path.str, &st);
scratch_end(scratch);
}
@@ -413,7 +400,7 @@ os_file_iter_next(Arena* arena, OS_FileIter* iter, OS_FileInfo* info_out)
// rjf: output & exit, if good & unfiltered
if (good && !filtered)
{
info_out->name = push_str8_copy(arena, str8_cstring(lnx_iter->dp->d_name));
info_out->name = str8_copy(arena, str8_cstring(lnx_iter->dp->d_name));
if (stat_result != -1) {
info_out->props = os_lnx_file_properties_from_stat(&st);
}
+2 -9
View File
@@ -184,16 +184,9 @@ MD_API void* os_lnx_thread_entry_point(void* ptr);
//~ rjf: @os_hooks System/Process Info (Implemented Per-OS)
inline String8
os_get_current_path(Arena* arena) {
os_get_current_path__ainfo(AllocatorInfo ainfo) {
char* cwdir = getcwd(0, 0);
String8 string = push_str8_copy(arena, str8_cstring(cwdir));
return string;
}
inline String8
os_get_current_path(AllocatorInfo ainfo) {
char* cwdir = getcwd(0, 0);
String8 string = alloc_str8_copy(ainfo, str8_cstring(cwdir));
String8 string = str8_copy(ainfo, str8_cstring(cwdir));
return string;
}
+82 -111
View File
@@ -1,8 +1,9 @@
#ifdef INTELLISENSE_DIRECTIVES
# pragma once
# include "base/file.h"
# include "base/debug.h"
# include "os_resolve.h"
# include "base/strings.h"
# include "base/thread_context.h"
# include "base/file.h"
#endif
// Copyright (c) 2024 Epic Games Tools
@@ -150,38 +151,16 @@ typedef void OS_ThreadFunctionType(void *ptr);
force_inline OS_Handle os_handle_zero (void) { OS_Handle handle = {0}; return handle; }
force_inline B32 os_handle_match(OS_Handle a, OS_Handle b) { return a.u64[0] == b.u64[0]; }
void os_handle_list_push (Arena* arena, OS_HandleList* handles, OS_Handle handle);
void os_handle_list_alloc (AllocatorInfo ainfo, OS_HandleList* handles, OS_Handle handle);
OS_HandleArray os_handle_array_from_list (Arena* arena, OS_HandleList* list);
OS_HandleArray os_handle_array_from_list_alloc(AllocatorInfo ainfo, OS_HandleList* list);
void os_handle_list_push__arena (Arena* arena, OS_HandleList* handles, OS_Handle handle);
void os_handle_list_push__ainfo (AllocatorInfo ainfo, OS_HandleList* handles, OS_Handle handle);
OS_HandleArray os_handle_array_from_list__arena(Arena* arena, OS_HandleList* list);
OS_HandleArray os_handle_array_from_list__ainfo(AllocatorInfo ainfo, OS_HandleList* list);
inline void
os_handle_list_push(Arena* arena, OS_HandleList* handles, OS_Handle handle) {
#if MD_DONT_MAP_ARENA_TO_ALLOCATOR_IMPL
OS_HandleNode* n = push_array(arena, OS_HandleNode, 1);
n->v = handle;
sll_queue_push(handles->first, handles->last, n);
handles->count += 1;
#else
os_handle_list_alloc(arena_allocator(arena), handles, handle);
#endif
}
#define os_handle_ist_push(arena, handles, handle) _Generic(allocator, Arena*: os_handle_list_push__arena, AllocatorInfo: os_handle_list_push__ainfo, default: assert_generic_selection_fail) resolved_function_call(allocator, handles, handle)
#define os_handle_array_from_list(allocator, list) _Generic(allocator, Arena*: os_handle_array_from_list__arena, AllocatorInfo: os_handle_list_push__ainfo, default: assert_generic_selection_fail) resolved_function_call(allocator, list)
inline OS_HandleArray
os_handle_array_from_list(Arena* arena, OS_HandleList* list) {
#if MD_DONT_MAP_ARENA_TO_ALLOCATOR_IMPL
OS_HandleArray result = {0};
result.count = list->count;
result.v = push_array_no_zero(arena, OS_Handle, result.count);
U64 idx = 0;
for(OS_HandleNode* n = list->first; n != 0; n = n->next, idx += 1) {
result.v[idx] = n->v;
}
return result;
#else
return os_handle_array_from_list_alloc(arena_allocator(arena), list);
#endif
}
force_inline void os_handle_list_push__arena (Arena* arena, OS_HandleList* handles, OS_Handle handle) { os_handle_list__push_ainfo (arena_allocator(arena), handles, handle); }
force_inline OS_HandleArray os_handle_array_from_list__arena(Arena* arena, OS_HandleList* list) { return os_handle_array_from_list__ainfo(arena_allocator(arena), list); }
inline void
os_handle_list_alloc(AllocatorInfo ainfo, OS_HandleList* handles, OS_Handle handle) {
@@ -206,44 +185,45 @@ os_handle_array_from_list_alloc(AllocatorInfo ainfo, OS_HandleList* list) {
////////////////////////////////
//~ rjf: Command Line Argc/Argv Helper (Helper, Implemented Once)
String8List os_string_list_from_argcv__arena(Arena* arena, int argc, char** argv);
String8List os_string_list_from_argcv__ainfo(AllocatorInfo ainfo, int argc, char** argv);
inline String8List
os_string_list_from_argcv_alloc(AllocatorInfo ainfo, int argc, char** argv) {
os_string_list_from_argcv__ainfo(AllocatorInfo ainfo, int argc, char** argv) {
String8List result = {0};
for(int i = 0; i < argc; i += 1)
{
String8 str = str8_cstring(argv[i]);
str8_list(ainfo, &result, str);
str8_list_push(ainfo, &result, str);
}
return result;
}
inline String8List
os_string_list_from_argcv(Arena* arena, int argc, char** argv) {
String8List result = {0};
for(int i = 0; i < argc; i += 1)
{
String8 str = str8_cstring(argv[i]);
str8_list_push(arena, &result, str);
}
return result;
}
#define os_string_list_from_argcv(allocator, argc, argv) _Generic(allocator, Arena*: os_string_list_from_argcv__arena, AllocatorInfo: os_string_list_from_argcv__ainfo, default: assert_generic_selection_fail) resolved_function_call(allocator, argc, argv)
force_inline String8List os_string_list_from_argcv__arena(Arena* arena, int argc, char** argv) { return os_string_list_from_argcv__ainfo(arena_allocator(arena), argc, argv); }
////////////////////////////////
//~ rjf: @os_hooks File System (Implemented Per-OS)
//- rjf: files
MD_API OS_Handle os_file_open (OS_AccessFlags flags, String8 path);
MD_API void os_file_close (OS_Handle file);
MD_API U64 os_file_read (OS_Handle file, Rng1U64 rng, void *out_data);
MD_API U64 os_file_write (OS_Handle file, Rng1U64 rng, void *data);
MD_API B32 os_file_set_times (OS_Handle file, DateTime time);
MD_API FileProperties os_properties_from_file (OS_Handle file);
MD_API OS_FileID os_id_from_file (OS_Handle file);
MD_API B32 os_delete_file_at_path (String8 path);
MD_API B32 os_copy_file_path (String8 dst, String8 src);
MD_API String8 os_full_path_from_path (Arena* arena, String8 path);
MD_API B32 os_file_path_exists (String8 path);
MD_API FileProperties os_properties_from_file_path(String8 path);
MD_API OS_Handle os_file_open (OS_AccessFlags flags, String8 path);
MD_API void os_file_close (OS_Handle file);
MD_API U64 os_file_read (OS_Handle file, Rng1U64 rng, void *out_data);
MD_API U64 os_file_write (OS_Handle file, Rng1U64 rng, void *data);
MD_API B32 os_file_set_times (OS_Handle file, DateTime time);
MD_API FileProperties os_properties_from_file (OS_Handle file);
MD_API OS_FileID os_id_from_file (OS_Handle file);
MD_API B32 os_delete_file_at_path (String8 path);
MD_API B32 os_copy_file_path (String8 dst, String8 src);
MD_API B32 os_file_path_exists (String8 path);
MD_API FileProperties os_properties_from_file_path (String8 path);
MD_API String8 os_full_path_from_path__arena(Arena* arena, String8 path);
MD_API String8 os_full_path_from_path__ainfo(AllocatorInfo arena, String8 path);
#define os_full_path_from_path(allocator, path) _Generic(allocator, Arena*: os_full_path_from_path__arena, AllocatorInfo: os_full_path_from_path__ainfo, default: assert_generic_selection_fail) resolved_function_call(allocator, path)
force_inline String8 os_full_path_from_path__arena(Arena* arena, String8 path) { return os_full_path_from_path__ainfo(arena_allocator(arena), path); }
//- rjf: file maps
MD_API OS_Handle os_file_map_open (OS_AccessFlags flags, OS_Handle file);
@@ -252,9 +232,17 @@ MD_API void* os_file_map_view_open (OS_Handle map, OS_AccessFlags flags, Rng
MD_API void os_file_map_view_close(OS_Handle map, void* ptr, Rng1U64 range);
//- rjf: directory iteration
MD_API OS_FileIter* os_file_iter_begin(Arena* arena, String8 path, OS_FileIterFlags flags);
MD_API B32 os_file_iter_next (Arena* arena, OS_FileIter* iter, OS_FileInfo* info_out);
MD_API void os_file_iter_end ( OS_FileIter* iter);
OS_FileIter* os_file_iter_begin__arena(Arena* arena, String8 path, OS_FileIterFlags flags);
MD_API OS_FileIter* os_file_iter_begin__ainfo(AllocatorInfo ainfo, String8 path, OS_FileIterFlags flags);
B32 os_file_iter_next__arena (Arena* arena, OS_FileIter* iter, OS_FileInfo* info_out);
MD_API B32 os_file_iter_next__ainfo (AllocatorInfo arena, OS_FileIter* iter, OS_FileInfo* info_out);
MD_API void os_file_iter_end ( OS_FileIter* iter);
#define os_file_iter_begin(allocator, path, flags) _Generic(allocator, Arena*: os_file_iter_begin__arena, AllocatorInfo: os_file_iter_begin__ainfo, default: assert_generic_selection_fail) resolved_function_call(allocator, path)
#define os_file_iter_next(allocator, iter, info_out) _Generic(allocator, Arena*: os_file_iter_next__arena, AllocatorInfo: os_file_iter_next__ainfo, default: assert_generic_selection_fail) resolved_function_call(allocator, path)
force_inline OS_FileIter* os_file_iter_begin__arena(Arena* arena, String8 path, OS_FileIterFlags flags) { reutrn (); }
force_inline B32 os_file_iter_next__arena (Arena* arena, OS_FileIter* iter, OS_FileInfo* info_out) { reutrn (); }
//- rjf: directory creation
MD_API B32 os_make_directory(String8 path);
@@ -268,36 +256,24 @@ MD_API B32 os_append_data_to_file_path (String8 path, String8 data)
OS_FileID os_id_from_file_path (String8 path);
S64 os_file_id_compare (OS_FileID a, OS_FileID b);
String8 os_data_from_file_path (Arena* arena, String8 path);
String8 os_data_from_file_path_alloc (AllocatorInfo ainfo, String8 path);
MD_API String8 os_string_from_file_range (Arena* arena, OS_Handle file, Rng1U64 range);
MD_API String8 os_string_from_file_range_alloc(AllocatorInfo ainfo, OS_Handle file, Rng1U64 range);
String8 os_data_from_file_path__arena (Arena* arena, String8 path);
String8 os_data_from_file_path__ainfo (AllocatorInfo ainfo, String8 path);
MD_API String8 os_string_from_file_range__arena(Arena* arena, OS_Handle file, Rng1U64 range);
MD_API String8 os_string_from_file_range__ainfo(AllocatorInfo ainfo, OS_Handle file, Rng1U64 range);
#define os_data_from_file_path(allocator, path) _Generic(allocator, Arena*: os_data_from_file_path__arena, AllocatorInfo: os_data_from_file_path__ainfo, default: assert_generic_selection_fail) resolved_function_call(allocator, path)
#define os_string_from_file_range(allocator, file, range) _Generic(allocator, Arena*: os_string_from_file_range__arena, AllocatorInfo: os_string_from_file_range__ainfo, default: assert_generic_selection_fail) resolved_function_call(allocator, file, range)
inline String8
os_data_from_file_path(Arena* arena, String8 path)
{
#if MD_DONT_MAP_ARENA_TO_ALLOCATOR_IMPL
OS_Handle file = os_file_open(OS_AccessFlag_Read | OS_AccessFlag_ShareRead, path);
FileProperties props = os_properties_from_file(file);
String8 data = os_string_from_file_range(arena, file, r1u64(0, props.size));
os_file_close(file);
return data;
#else
return os_data_from_file_path_alloc(arena_allocator(arena), path);
#endif
}
inline String8
os_data_from_file_path_alloc(AllocatorInfo ainfo, String8 path)
os_data_from_file_path__ainfo(AllocatorInfo ainfo, String8 path)
{
OS_Handle file = os_file_open(OS_AccessFlag_Read|OS_AccessFlag_ShareRead, path);
FileProperties props = os_properties_from_file(file);
String8 data = os_string_from_file_range_alloc(ainfo, file, r1u64(0, props.size));
String8 data = os_string_from_file_range(ainfo, file, r1u64(0, props.size));
os_file_close(file);
return data;
}
inline OS_FileID
os_id_from_file_path(String8 path) {
OS_Handle file = os_file_open(OS_AccessFlag_Read | OS_AccessFlag_ShareRead, path);
@@ -311,28 +287,17 @@ inline S64 os_file_id_compare(OS_FileID a, OS_FileID b) { S64 cmp = memory_compa
////////////////////////////////
//~ rjf: GUID Helpers (Helpers, Implemented Once)
inline String8
os_string_from_guid_alloc(AllocatorInfo ainfo, OS_Guid guid) {
String8 result = str8f(ainfo,
"%08X-%04X-%04X-%02X%02X-%02X%02X%02X%02X%02X%02X",
guid.data1,
guid.data2,
guid.data3,
guid.data4[0],
guid.data4[1],
guid.data4[2],
guid.data4[3],
guid.data4[4],
guid.data4[5],
guid.data4[6],
guid.data4[7]
);
return result;
}
String8 os_string_from_guid__arena(Arena* arena, OS_Guid guid);
String8 os_string_from_guid__ainfo(AllocatorInfo ainfo, OS_Guid guid);
#define os_string_from_guid(allocator, guid) _Generic(allocator, Arena*: os_string_from_guid__arena, AllocatorInfo: os_string_from_guid__ainfo, default: assert_generic_selection_fail) resolved_function_call(allocator, guid)
force_inline String8 os_string_from_guid__arena(Arena* arena, OS_Guid guid) { os_string_from_guid__ainfo(arena_allocator(arena), guid); }
inline String8
os_string_from_guid(Arena* arena, OS_Guid guid) {
String8 result = str8f(arena,
os_string_from_guid_alloc(AllocatorInfo ainfo, OS_Guid guid) {
String8 result = str8f(ainfo,
"%08X-%04X-%04X-%02X%02X-%02X%02X%02X%02X%02X%02X",
guid.data1,
guid.data2,
@@ -355,7 +320,12 @@ os_string_from_guid(Arena* arena, OS_Guid guid) {
MD_API OS_SystemInfo* os_get_system_info (void);
MD_API OS_ProcessInfo* os_get_process_info(void);
String8 os_get_current_path(Arena* arena);
String8 os_get_current_path__arena(Arena* arena);
String8 os_get_current_path__ainfo(AllocatorInfo arena);
#define os_get_current_path(allocator) _Generic(allocator, Arena*: os_get_current_path__arena, AllocatorInfo: os_get_current_path__ainfo) resolved_function_call(allocator)
force_inline String8 os_get_current_path__arena(Arena* arena) { return os_get_current_path__ainfo(arena_allocator(arena)); }
////////////////////////////////
//~ rjf: @os_hooks Memory Allocation (Implemented Per-OS)
@@ -373,7 +343,8 @@ B32 os_commit_large (void* ptr, U64 size);
////////////////////////////////
//~ rjf: @os_hooks Thread Info (Implemented Per-OS)
U32 os_tid (void);
U32 os_tid(void);
MD_API void os_set_thread_name(String8 string);
////////////////////////////////
@@ -424,12 +395,12 @@ MD_API void os_mutex_take (OS_Handle mutex);
MD_API void os_mutex_drop (OS_Handle mutex);
//- rjf: reader/writer mutexes
MD_API OS_Handle os_rw_mutex_alloc(void);
MD_API OS_Handle os_rw_mutex_alloc (void);
MD_API void os_rw_mutex_release(OS_Handle rw_mutex);
MD_API void os_rw_mutex_take_r(OS_Handle mutex);
MD_API void os_rw_mutex_drop_r(OS_Handle mutex);
MD_API void os_rw_mutex_take_w(OS_Handle mutex);
MD_API void os_rw_mutex_drop_w(OS_Handle mutex);
MD_API void os_rw_mutex_take_r (OS_Handle mutex);
MD_API void os_rw_mutex_drop_r (OS_Handle mutex);
MD_API void os_rw_mutex_take_w (OS_Handle mutex);
MD_API void os_rw_mutex_drop_w (OS_Handle mutex);
//- rjf: condition variables
MD_API OS_Handle os_condition_variable_alloc (void);
@@ -450,10 +421,10 @@ MD_API B32 os_semaphore_take (OS_Handle semaphore, U64 endt_us);
MD_API void os_semaphore_drop (OS_Handle semaphore);
//- rjf: scope macros
#define OS_MutexScope(mutex) defer_loop( os_mutex_take (mutex), os_mutex_drop (mutex))
#define OS_MutexScopeR(mutex) defer_loop( os_rw_mutex_take_r(mutex), os_rw_mutex_drop_r(mutex))
#define OS_MutexScopeW(mutex) defer_loop( os_rw_mutex_take_w(mutex), os_rw_mutex_drop_w(mutex))
#define OS_MutexScopeRWPromote(mutex) defer_loop((os_rw_mutex_drop_r(mutex), os_rw_mutex_take_w(mutex)), (os_rw_mutex_drop_w(mutex), os_rw_mutex_take_r(mutex)))
#define os_mutex_scope(mutex) defer_loop( os_mutex_take (mutex), os_mutex_drop (mutex))
#define os_mutex_scope_r(mutex) defer_loop( os_rw_mutex_take_r(mutex), os_rw_mutex_drop_r(mutex))
#define os_mutex_scope_W(mutex) defer_loop( os_rw_mutex_take_w(mutex), os_rw_mutex_drop_w(mutex))
#define os_mutex_scope_rw_promote(mutex) defer_loop((os_rw_mutex_drop_r(mutex), os_rw_mutex_take_w(mutex)), (os_rw_mutex_drop_w(mutex), os_rw_mutex_take_r(mutex)))
////////////////////////////////
//~ rjf: @os_hooks Dynamically-Loaded Libraries (Implemented Per-OS)
+11 -10
View File
@@ -1,5 +1,6 @@
#ifdef INTELLISENSE_DIRECTIVES
# include "os_win32.h"
# include "os.h"
#endif
// Copyright (c) 2024 Epic Games Tools
@@ -346,14 +347,14 @@ os_copy_file_path(String8 dst, String8 src)
}
String8
os_full_path_from_path(Arena* arena, String8 path)
os_full_path_from_path__ainfo(AllocatorInfo ainfo, String8 path)
{
TempArena scratch = scratch_begin(&arena, 1);
TempArena scratch = scratch_begin(ainfo);
DWORD buffer_size = MAX_PATH + 1;
U16* buffer = push_array_no_zero(scratch.arena, U16, buffer_size);
String16 path16 = str16_from(scratch.arena, path);
DWORD path16_size = GetFullPathNameW((WCHAR*)path16.str, buffer_size, (WCHAR*)buffer, NULL);
String8 full_path = str8_from(arena, str16(buffer, path16_size));
String8 full_path = str8_from(ainfo, str16(buffer, path16_size));
scratch_end(scratch);
return full_path;
}
@@ -476,15 +477,15 @@ os_file_map_view_close(OS_Handle map, void* ptr, Rng1U64 range) {
//- rjf: directory iteration
OS_FileIter*
os_file_iter_begin(Arena* arena, String8 path, OS_FileIterFlags flags)
os_file_iter_begin__ainfo(AllocatorInfo ainfo, String8 path, OS_FileIterFlags flags)
{
TempArena scratch = scratch_begin(&arena, 1);
TempArena scratch = scratch_begin(ainfo);
String8 path_with_wildcard = str8_cat(scratch.arena, path, str8_lit("\\*"));
String16 path16 = str16_from(scratch.arena, path_with_wildcard);
OS_FileIter*
iter = push_array(arena, OS_FileIter, 1);
iter = alloc_array(ainfo, OS_FileIter, 1);
iter->flags = flags;
OS_W32_FileIter* w32_iter = (OS_W32_FileIter*)iter->memory;
@@ -500,11 +501,11 @@ os_file_iter_begin(Arena* arena, String8 path, OS_FileIterFlags flags)
{
String16 next_drive_string_16 = str16_cstring((U16*)buffer + off);
off += next_drive_string_16.size + 1;
String8 next_drive_string = str8_from(arena, next_drive_string_16);
String8 next_drive_string = str8_from(ainfo, next_drive_string_16);
next_drive_string = str8_chop_last_slash(next_drive_string);
str8_list_push(scratch.arena, &drive_strings, next_drive_string);
}
w32_iter->drive_strings = str8_array_from_list(arena, &drive_strings);
w32_iter->drive_strings = str8_array_from_list(ainfo, &drive_strings);
w32_iter->drive_strings_iter_idx = 0;
}
else
@@ -516,7 +517,7 @@ os_file_iter_begin(Arena* arena, String8 path, OS_FileIterFlags flags)
}
B32
os_file_iter_next(Arena* arena, OS_FileIter* iter, OS_FileInfo* info_out)
os_file_iter_next__ainfo(AllocatorInfo ainfo, OS_FileIter* iter, OS_FileInfo* info_out)
{
B32 result = 0;
@@ -566,7 +567,7 @@ os_file_iter_next(Arena* arena, OS_FileIter* iter, OS_FileInfo* info_out)
// emit if usable
if (usable_file)
{
info_out->name = str8_from(arena, str16_cstring((U16*)file_name));
info_out->name = str8_from(ainfo, str16_cstring((U16*)file_name));
info_out->props.size = (U64)w32_iter->find_data.nFileSizeLow | (((U64)w32_iter->find_data.nFileSizeHigh) << 32);
os_w32_dense_time_from_file_time(&info_out->props.created, &w32_iter->find_data.ftCreationTime);
os_w32_dense_time_from_file_time(&info_out->props.modified, &w32_iter->find_data.ftLastWriteTime);
+1 -15
View File
@@ -164,7 +164,7 @@ MD_API DWORD os_w32_thread_entry_point(void* ptr);
//~ rjf: @os_hooks System/Process Info (Implemented Per-OS)
inline String8
os_get_current_path_alloc(AllocatorInfo ainfo) {
os_get_current_path__ainfo(AllocatorInfo ainfo) {
String8 name;
TempArena scratch = scratch_begin(ainfo);
{
@@ -177,20 +177,6 @@ os_get_current_path_alloc(AllocatorInfo ainfo) {
return name;
}
inline String8
os_get_current_path(Arena* arena) {
String8 name;
TempArena scratch = scratch_begin(&arena, 1);
{
DWORD length = GetCurrentDirectoryW(0, 0);
U16* memory = push_array_no_zero(scratch.arena, U16, length + 1);
length = GetCurrentDirectoryW(length + 1, (WCHAR*)memory);
name = str8_from(arena, str16(memory, length));
}
scratch_end(scratch);
return name;
}
////////////////////////////////
//~ rjf: @os_hooks Memory Allocation (Implemented Per-OS)
+14 -18
View File
@@ -57,6 +57,18 @@ word defer_loop_checked, md_defer_loop_checked
word each_enum_val, md_each_enum_val
word each_non_zero_enum_val, md_each_non_zero_enum_val
word stringify, md_stringify
word stringify_, md_stringify_
word glue, md_glue
word glue_, md_glue_
word do_once, md_do_once
word do_once_defer, md_do_once_defer
word do_once_start, md_do_once_start
// base/generic_macros.h
// base/profiling.h
word MARKUP_LAYER_COLOR, MD_MARKUP_LAYER_COLOR
@@ -345,18 +357,6 @@ namespace ins_atomic_, md_ins_atomic_
word check_nil, md_check_nil
word set_nil, md_set_nil
// word dll_insert_npz, md_dll_insert_npz,
// word dll_push_back_npz, md_dll_push_back_npz,
// word dll_push_front_npz, md_dll_push_front_npz,
// word dll_remove_npz, md_dll_remove_npz
// word sll_queue_push_nz, md_sll_queue_push_nz
// word sll_queue_push_front_nz, md_sll_queue_push_front_nz
// word sll_queue_pop_nz, md_sll_queue_pop_nz
// word sll_stack_push_n, md_sll_stack_push_n
// word sll_stack_pop_n, md_sll_stack_pop_n
namespace dll_, md_dll_
namespace sll_, md_sll_
@@ -364,12 +364,6 @@ word NO_ASAN, MD_NO_ASAN
namespace asan_, md_asan_
word stringify, md_stringify
word stringify_, md_stringify_
word glue, md_glue
word glue_, md_glue_
word array_count, md_array_count
word ceil_integer_div, md_ceil_integer_div
@@ -1031,6 +1025,8 @@ word TokenArray, MD_TokenArray
namespace NodeKind, MD_NodeKind
word Node, MD_Node
// metagen module