last set of fixes for UE

This commit is contained in:
2024-12-15 19:54:27 -05:00
parent a6143e12b4
commit b027778328
5 changed files with 113 additions and 99 deletions

View File

@ -376,6 +376,9 @@ void deinit(Context* ctx)
if (_ctx == ctx)
_ctx = nullptr;
-- context_counter;
Context wipe = {};
* ctx = wipe;
}
Context* get_context() {

View File

@ -79,6 +79,8 @@ struct Context
u32 InitSize_Fallback_Allocator_Bucket_Size;
Array(Arena) Fallback_AllocatorBuckets;
StringTable token_fmt_map;
// Array(Token) LexerTokens;
Array(Pool) CodePools;
@ -381,12 +383,20 @@ GEN_API Code untyped_token_fmt( s32 num_tokens, char const* fmt, ... );
#ifndef name
// Convienence for defining any name used with the gen api.
// Lets you provide the length and string literal to the functions without the need for the DSL.
#define name( Id_ ) { stringize(Id_), sizeof(stringize( Id_ )) - 1 }
# if GEN_COMPILER_C
# define name( Id_ ) (Str){ stringize(Id_), sizeof(stringize( Id_ )) - 1 }
# else
# define name( Id_ ) Str { stringize(Id_), sizeof(stringize( Id_ )) - 1 }
# endif
#endif
#ifndef code
// Same as name just used to indicate intention of literal for code instead of names.
#define code( ... ) { stringize( __VA_ARGS__ ), sizeof(stringize(__VA_ARGS__)) - 1 }
# if GEN_COMPILER_C
# define code( ... ) (Str){ stringize( __VA_ARGS__ ), sizeof(stringize(__VA_ARGS__)) - 1 }
# else
# define code( ... ) Str { stringize( __VA_ARGS__ ), sizeof(stringize(__VA_ARGS__)) - 1 }
# endif
#endif
#ifndef args

View File

@ -8,9 +8,8 @@ ssize token_fmt_va( char* buf, usize buf_size, s32 num_tokens, va_list va )
char const* buf_begin = buf;
ssize remaining = buf_size;
local_persist StringTable tok_map;
do_once() {
tok_map = hashtable_init(Str, _ctx->Allocator_DyanmicContainers );
if (_ctx->token_fmt_map.Hashes == nullptr) {
_ctx->token_fmt_map = hashtable_init(Str, _ctx->Allocator_DyanmicContainers );
}
// Populate token pairs
{
@ -22,7 +21,7 @@ ssize token_fmt_va( char* buf, usize buf_size, s32 num_tokens, va_list va )
Str value = va_arg( va, Str );
u32 key = crc32( token, c_str_len(token) );
hashtable_set( tok_map, key, value );
hashtable_set( _ctx->token_fmt_map, key, value );
}
}
@ -57,8 +56,8 @@ ssize token_fmt_va( char* buf, usize buf_size, s32 num_tokens, va_list va )
char const* token = fmt + 1;
u32 key = crc32( token, tok_len );
Str* value = hashtable_get(tok_map, key );
u32 key = crc32( token, tok_len );
Str* value = hashtable_get(_ctx->token_fmt_map, key );
if ( value )
{
@ -87,7 +86,7 @@ ssize token_fmt_va( char* buf, usize buf_size, s32 num_tokens, va_list va )
current = * fmt;
}
}
hashtable_clear(tok_map);
hashtable_clear(_ctx->token_fmt_map);
ssize result = buf_size - remaining;
return result;
}