progress on strings.h/c started to look at thread_context.h/c

This commit is contained in:
2025-02-05 22:56:35 -05:00
parent 61f2fad8ef
commit af0dc24160
6 changed files with 465 additions and 440 deletions
+11
View File
@@ -2,6 +2,17 @@
# pragma once
#endif
////////////////////////////////
//~ rjf: Build Options
#if ! defined(BUILD_DEBUG)
# define BUILD_DEBUG 1
#endif
#if ! defined(BUILD_SUPPLEMENTARY_UNIT)
# define BUILD_SUPPLEMENTARY_UNIT 0
#endif
#pragma region Compiler Vendor
#if defined( _MSC_VER )
+236 -324
View File
@@ -1,6 +1,7 @@
#ifdef INTELLISENSE_DIRECTIVES
#pragma once
#include "base/strings.h"
# pragma once
# include "strings.h"
# include "thread_context.h"
#endif
// Copyright (c) 2024 Epic Games Tools
@@ -143,17 +144,17 @@ str8_find_needle(String8 string, U64 start_pos, String8 needle, StringMatchFlags
String8
str8_skip_chop_whitespace(String8 string)
{
U8* first = string.str;
U8* opl = first + string.size;
for (; first < opl; first += 1) {
if ( ! char_is_space(*first)) { break;}
}
for (; opl > first; ){
opl -= 1;
if ( ! char_is_space(*opl)){ opl += 1; break; }
}
String8 result = str8_range(first, opl);
return(result);
U8* first = string.str;
U8* opl = first + string.size;
for (; first < opl; first += 1) {
if ( ! char_is_space(*first)) { break;}
}
for (; opl > first; ){
opl -= 1;
if ( ! char_is_space(*opl)) { opl += 1; break; }
}
String8 result = str8_range(first, opl);
return(result);
}
////////////////////////////////
@@ -171,7 +172,7 @@ push_str8_cat(Arena* arena, String8 s1, String8 s2)
return(str);
}
internal String8
String8
push_str8_copy(Arena *arena, String8 s){
String8 str;
str.size = s.size;
@@ -181,7 +182,7 @@ push_str8_copy(Arena *arena, String8 s){
return(str);
}
internal String8
String8
push_str8fv(Arena *arena, char *fmt, va_list args){
va_list args2;
va_copy(args2, args);
@@ -194,15 +195,6 @@ push_str8fv(Arena *arena, char *fmt, va_list args){
return(result);
}
internal String8
push_str8f(Arena *arena, char *fmt, ...){
va_list args;
va_start(args, fmt);
String8 result = push_str8fv(arena, fmt, args);
va_end(args);
return(result);
}
String8
str8__cat(String8 s1, String8 s2, AllocatorInfo ainfo)
{
@@ -226,8 +218,8 @@ str8__copy(String8 s, AllocatorInfo ainfo)
return(str);
}
internal String8
push_str8fv(AllocatorInfo ainfo, char *fmt, va_list args){
String8
str8fv(AllocatorInfo ainfo, char *fmt, va_list args){
va_list args2;
va_copy(args2, args);
U32 needed_bytes = raddbg_vsnprintf(0, 0, fmt, args) + 1;
@@ -244,236 +236,204 @@ push_str8fv(AllocatorInfo ainfo, char *fmt, va_list args){
//- rjf: string -> integer
internal S64
sign_from_str8(String8 string, String8 *string_tail){
// count negative signs
U64 neg_count = 0;
U64 i = 0;
for (; i < string.size; i += 1){
if (string.str[i] == '-'){
neg_count += 1;
}
else if (string.str[i] != '+'){
break;
}
}
// output part of string after signs
*string_tail = str8_skip(string, i);
// output integer sign
S64 sign = (neg_count & 1)?-1:+1;
return(sign);
S64
sign_from_str8(String8 string, String8* string_tail)
{
// count negative signs
U64 neg_count = 0;
U64 i = 0;
for (; i < string.size; i += 1){
if (string.str[i] == '-') {
neg_count += 1;
}
else if (string.str[i] != '+') {
break;
}
}
// output part of string after signs
*string_tail = str8_skip(string, i);
// output integer sign
S64 sign = (neg_count & 1)?-1:+1;
return(sign);
}
internal B32
B32
str8_is_integer(String8 string, U32 radix){
B32 result = 0;
if (string.size > 0){
if (1 < radix && radix <= 16){
result = 1;
for (U64 i = 0; i < string.size; i += 1){
U8 c = string.str[i];
if (!(c < 0x80) || integer_symbol_reverse[c] >= radix){
result = 0;
break;
}
}
}
}
return(result);
B32 result = 0;
if (string.size > 0 && (1 < radix && radix <= 16)) {
result = 1;
for (U64 i = 0; i < string.size; i += 1) {
U8 c = string.str[i];
if ( ! (c < 0x80) || integer_symbol_reverse[c] >= radix){
result = 0;
break;
}
}
}
return(result);
}
internal U64
u64_from_str8(String8 string, U32 radix){
U64 x = 0;
if (1 < radix && radix <= 16){
for (U64 i = 0; i < string.size; i += 1){
x *= radix;
x += integer_symbol_reverse[string.str[i]&0x7F];
}
}
return(x);
}
internal S64
s64_from_str8(String8 string, U32 radix){
S64 sign = sign_from_str8(string, &string);
S64 x = (S64)u64_from_str8(string, radix) * sign;
return(x);
}
internal B32
try_u64_from_str8_c_rules(String8 string, U64 *x){
B32 is_integer = 0;
if (str8_is_integer(string, 10)){
is_integer = 1;
*x = u64_from_str8(string, 10);
}
else{
String8 hex_string = str8_skip(string, 2);
if (str8_match(str8_prefix(string, 2), str8_lit("0x"), 0) &&
str8_is_integer(hex_string, 0x10)){
is_integer = 1;
*x = u64_from_str8(hex_string, 0x10);
}
else if (str8_match(str8_prefix(string, 2), str8_lit("0b"), 0) &&
str8_is_integer(hex_string, 2)){
is_integer = 1;
*x = u64_from_str8(hex_string, 2);
}
else{
String8 oct_string = str8_skip(string, 1);
if (str8_match(str8_prefix(string, 1), str8_lit("0"), 0) &&
str8_is_integer(hex_string, 010)){
is_integer = 1;
*x = u64_from_str8(oct_string, 010);
}
}
}
return(is_integer);
}
internal B32
try_s64_from_str8_c_rules(String8 string, S64 *x){
String8 string_tail = {0};
S64 sign = sign_from_str8(string, &string_tail);
U64 x_u64 = 0;
B32 is_integer = try_u64_from_str8_c_rules(string_tail, &x_u64);
*x = x_u64*sign;
return(is_integer);
B32
try_u64_from_str8_c_rules(String8 string, U64 *x)
{
B32 is_integer = 0;
if (str8_is_integer(string, 10)) {
is_integer = 1;
*x = u64_from_str8(string, 10);
}
else
{
String8 hex_string = str8_skip(string, 2);
if (str8_match(str8_prefix(string, 2), str8_lit("0x"), 0) &&
str8_is_integer(hex_string, 0x10))
{
is_integer = 1;
*x = u64_from_str8(hex_string, 0x10);
}
else if (str8_match(str8_prefix(string, 2), str8_lit("0b"), 0) &&
str8_is_integer(hex_string, 2))
{
is_integer = 1;
*x = u64_from_str8(hex_string, 2);
}
else
{
String8 oct_string = str8_skip(string, 1);
if (str8_match(str8_prefix(string, 1), str8_lit("0"), 0) &&
str8_is_integer(hex_string, 010))
{
is_integer = 1;
*x = u64_from_str8(oct_string, 010);
}
}
}
return(is_integer);
}
//- rjf: integer -> string
internal String8
str8_from_memory_size(Arena *arena, U64 z){
String8 result = {0};
if (z < KB(1)){
result = push_str8f(arena, "%llu b", z);
}
else if (z < MB(1)){
result = push_str8f(arena, "%llu.%02llu Kb", z/KB(1), ((100*z)/KB(1))%100);
}
else if (z < GB(1)){
result = push_str8f(arena, "%llu.%02llu Mb", z/MB(1), ((100*z)/MB(1))%100);
}
else{
result = push_str8f(arena, "%llu.%02llu Gb", z/GB(1), ((100*z)/GB(1))%100);
}
return(result);
String8
str8_from_memory_size(Arena *arena, U64 z) {
String8 result = {0};
if (z < KB(1)) {
result = push_str8f(arena, "%llu b", z);
}
else if (z < MB(1)) {
result = push_str8f(arena, "%llu.%02llu Kb", z/KB(1), ((100*z)/KB(1))%100);
}
else if (z < GB(1)) {
result = push_str8f(arena, "%llu.%02llu Mb", z/MB(1), ((100*z)/MB(1))%100);
}
else{
result = push_str8f(arena, "%llu.%02llu Gb", z/GB(1), ((100*z)/GB(1))%100);
}
return(result);
}
internal String8
String8
str8_from_u64(Arena *arena, U64 u64, U32 radix, U8 min_digits, U8 digit_group_separator)
{
String8 result = {0};
{
// rjf: prefix
String8 prefix = {0};
switch(radix)
{
case 16:{prefix = str8_lit("0x");}break;
case 8: {prefix = str8_lit("0o");}break;
case 2: {prefix = str8_lit("0b");}break;
}
// rjf: determine # of chars between separators
U8 digit_group_size = 3;
switch(radix)
{
default:break;
case 2:
case 8:
case 16:
{digit_group_size = 4;}break;
}
// rjf: prep
U64 needed_leading_0s = 0;
{
U64 needed_digits = 1;
{
U64 u64_reduce = u64;
for(;;)
{
u64_reduce /= radix;
if(u64_reduce == 0)
{
break;
}
needed_digits += 1;
}
}
needed_leading_0s = (min_digits > needed_digits) ? min_digits - needed_digits : 0;
U64 needed_separators = 0;
if(digit_group_separator != 0)
{
needed_separators = (needed_digits+needed_leading_0s)/digit_group_size;
if(needed_separators > 0 && (needed_digits+needed_leading_0s)%digit_group_size == 0)
{
needed_separators -= 1;
}
}
result.size = prefix.size + needed_leading_0s + needed_separators + needed_digits;
result.str = push_array_no_zero(arena, U8, result.size + 1);
result.str[result.size] = 0;
}
// rjf: fill contents
{
U64 u64_reduce = u64;
U64 digits_until_separator = digit_group_size;
for(U64 idx = 0; idx < result.size; idx += 1)
{
if(digits_until_separator == 0 && digit_group_separator != 0)
{
result.str[result.size - idx - 1] = digit_group_separator;
digits_until_separator = digit_group_size+1;
}
else
{
result.str[result.size - idx - 1] = char_to_lower(integer_symbols[u64_reduce%radix]);
u64_reduce /= radix;
}
digits_until_separator -= 1;
if(u64_reduce == 0)
{
break;
}
}
for(U64 leading_0_idx = 0; leading_0_idx < needed_leading_0s; leading_0_idx += 1)
{
result.str[prefix.size + leading_0_idx] = '0';
}
}
// rjf: fill prefix
if(prefix.size != 0)
{
MemoryCopy(result.str, prefix.str, prefix.size);
}
}
return result;
String8 result = {0};
{
// rjf: prefix
String8 prefix = {0};
switch(radix)
{
case 16:{prefix = str8_lit("0x");}break;
case 8: {prefix = str8_lit("0o");}break;
case 2: {prefix = str8_lit("0b");}break;
}
// rjf: determine # of chars between separators
U8 digit_group_size = 3;
switch(radix)
{
default:break;
case 2:
case 8:
case 16:
{digit_group_size = 4;} break;
}
// rjf: prep
U64 needed_leading_0s = 0;
{
U64 needed_digits = 1;
{
U64 u64_reduce = u64;
for(;;)
{
u64_reduce /= radix;
if(u64_reduce == 0) {
break;
}
needed_digits += 1;
}
}
needed_leading_0s = (min_digits > needed_digits) ? min_digits - needed_digits : 0;
U64 needed_separators = 0;
if (digit_group_separator != 0)
{
needed_separators = (needed_digits+needed_leading_0s)/digit_group_size;
if(needed_separators > 0 && (needed_digits+needed_leading_0s)%digit_group_size == 0)
{
needed_separators -= 1;
}
}
result.size = prefix.size + needed_leading_0s + needed_separators + needed_digits;
result.str = push_array_no_zero(arena, U8, result.size + 1);
result.str[result.size] = 0;
}
// rjf: fill contents
{
U64 u64_reduce = u64;
U64 digits_until_separator = digit_group_size;
for (U64 idx = 0; idx < result.size; idx += 1)
{
if(digits_until_separator == 0 && digit_group_separator != 0) {
result.str[result.size - idx - 1] = digit_group_separator;
digits_until_separator = digit_group_size+1;
}
else {
result.str[result.size - idx - 1] = char_to_lower(integer_symbols[u64_reduce%radix]);
u64_reduce /= radix;
}
digits_until_separator -= 1;
if(u64_reduce == 0) {
break;
}
}
for(U64 leading_0_idx = 0; leading_0_idx < needed_leading_0s; leading_0_idx += 1)
{
result.str[prefix.size + leading_0_idx] = '0';
}
}
// rjf: fill prefix
if(prefix.size != 0)
{
memory_copy(result.str, prefix.str, prefix.size);
}
}
return result;
}
internal String8
String8
str8_from_s64(Arena *arena, S64 s64, U32 radix, U8 min_digits, U8 digit_group_separator)
{
String8 result = {0};
// TODO(rjf): preeeeetty sloppy...
if(s64 < 0)
{
Temp scratch = scratch_begin(&arena, 1);
String8 numeric_part = str8_from_u64(scratch.arena, (U64)(-s64), radix, min_digits, digit_group_separator);
result = push_str8f(arena, "-%S", numeric_part);
scratch_end(scratch);
}
else
{
result = str8_from_u64(arena, (U64)s64, radix, min_digits, digit_group_separator);
}
return result;
String8 result = {0};
// TODO(rjf): preeeeetty sloppy...
if(s64 < 0) {
TempArena scratch = scratch_begin( & arena, 1);
String8 numeric_part = str8_from_u64(scratch.arena, (U64)(-s64), radix, min_digits, digit_group_separator);
result = push_str8f(arena, "-%S", numeric_part);
scratch_end(scratch);
}
else {
result = str8_from_u64(arena, (U64)s64, radix, min_digits, digit_group_separator);
}
return result;
}
////////////////////////////////
@@ -482,96 +442,48 @@ str8_from_s64(Arena *arena, S64 s64, U32 radix, U8 min_digits, U8 digit_group_se
internal F64
f64_from_str8(String8 string)
{
// TODO(rjf): crappy implementation for now that just uses atof.
F64 result = 0;
if(string.size > 0)
{
// rjf: find starting pos of numeric string, as well as sign
F64 sign = +1.0;
//U64 first_numeric = 0;
if(string.str[0] == '-')
{
//first_numeric = 1;
sign = -1.0;
}
else if(string.str[0] == '+')
{
//first_numeric = 1;
sign = 1.0;
}
// rjf: gather numerics
U64 num_valid_chars = 0;
char buffer[64];
for(U64 idx = 0; idx < string.size && num_valid_chars < sizeof(buffer)-1; idx += 1)
{
if(char_is_digit(string.str[idx], 10) || string.str[idx] == '.')
{
buffer[num_valid_chars] = string.str[idx];
num_valid_chars += 1;
}
}
// rjf: null-terminate (the reason for all of this!!!!!!)
buffer[num_valid_chars] = 0;
// rjf: do final conversion
result = sign * atof(buffer);
}
return result;
// TODO(rjf): crappy implementation for now that just uses atof.
F64 result = 0;
if (string.size > 0)
{
// rjf: find starting pos of numeric string, as well as sign
F64 sign = +1.0;
//U64 first_numeric = 0;
if(string.str[0] == '-')
{
//first_numeric = 1;
sign = -1.0;
}
else if(string.str[0] == '+')
{
//first_numeric = 1;
sign = 1.0;
}
// rjf: gather numerics
U64 num_valid_chars = 0;
char buffer[64];
for(U64 idx = 0; idx < string.size && num_valid_chars < sizeof(buffer)-1; idx += 1)
{
if(char_is_digit(string.str[idx], 10) || string.str[idx] == '.')
{
buffer[num_valid_chars] = string.str[idx];
num_valid_chars += 1;
}
}
// rjf: null-terminate (the reason for all of this!!!!!!)
buffer[num_valid_chars] = 0;
// rjf: do final conversion
result = sign * atof(buffer);
}
return result;
}
////////////////////////////////
//~ rjf: String List Construction Functions
internal String8Node*
str8_list_push_node(String8List *list, String8Node *node){
SLLQueuePush(list->first, list->last, node);
list->node_count += 1;
list->total_size += node->string.size;
return(node);
}
internal String8Node*
str8_list_push_node_set_string(String8List *list, String8Node *node, String8 string){
SLLQueuePush(list->first, list->last, node);
list->node_count += 1;
list->total_size += string.size;
node->string = string;
return(node);
}
internal String8Node*
str8_list_push_node_front(String8List *list, String8Node *node){
SLLQueuePushFront(list->first, list->last, node);
list->node_count += 1;
list->total_size += node->string.size;
return(node);
}
internal String8Node*
str8_list_push_node_front_set_string(String8List *list, String8Node *node, String8 string){
SLLQueuePushFront(list->first, list->last, node);
list->node_count += 1;
list->total_size += string.size;
node->string = string;
return(node);
}
internal String8Node*
str8_list_push(Arena *arena, String8List *list, String8 string){
String8Node *node = push_array_no_zero(arena, String8Node, 1);
str8_list_push_node_set_string(list, node, string);
return(node);
}
internal String8Node*
str8_list_push_front(Arena *arena, String8List *list, String8 string){
String8Node *node = push_array_no_zero(arena, String8Node, 1);
str8_list_push_node_front_set_string(list, node, string);
return(node);
}
internal void
str8_list_concat_in_place(String8List *list, String8List *to_push){
if(to_push->node_count != 0){
+127 -30
View File
@@ -282,55 +282,152 @@ str8_chop(String8 str, U64 amt){
MD_API String8 push_str8_cat (Arena* arena, String8 s1, String8 s2);
MD_API String8 push_str8_copy(Arena* arena, String8 s);
MD_API String8 push_str8fv (Arena* arena, char* fmt, va_list args);
MD_API String8 push_str8f (Arena* arena, char* fmt, ...);
String8 push_str8f (Arena* arena, char* fmt, ...);
String8 str8__cat (String8 s1, String8 s2, AllocatorInfo ainfo);
String8 str8__copy(String8 s, AllocatorInfo ainfo);
String8 str8fv(AllocatorInfo ainfo, char* fmt, va_list args);
String8 str8f (AllocatorInfo afino, char* fmt, ...);
MD_API String8 str8__cat (String8 s1, String8 s2, AllocatorInfo ainfo);
MD_API String8 str8__copy(String8 s, AllocatorInfo ainfo);
MD_API String8 str8fv (AllocatorInfo ainfo, char* fmt, va_list args);
String8 str8f (AllocatorInfo ainfo, char* fmt, ...);
#define str8_cat(s1, s2, ...) str8__cat (s1, s2, (AllocatorInfo) {__VA_ARGS__})
#define str8_copy(s, ...) str8__copy(s, (AllocatorInfo) {__VA_ARGS__})
inline String8
push_str8f(Arena *arena, char *fmt, ...){
va_list args;
va_start(args, fmt);
String8 result = push_str8fv(arena, fmt, args);
va_end(args);
return(result);
}
inline String8
str8f(AllocatorInfo ainfo, char *fmt, ...){
va_list args;
va_start(args, fmt);
String8 result = str8fv(ainfo, fmt, args);
va_end(args);
return(result);
}
////////////////////////////////
//~ rjf: String <=> Integer Conversions
//- rjf: string -> integer
internal S64 sign_from_str8 (String8 string, String8 *string_tail);
internal B32 str8_is_integer (String8 string, U32 radix);
internal U64 u64_from_str8 (String8 string, U32 radix);
internal S64 s64_from_str8 (String8 string, U32 radix);
internal B32 try_u64_from_str8_c_rules(String8 string, U64 *x);
internal B32 try_s64_from_str8_c_rules(String8 string, S64 *x);
MD_API S64 sign_from_str8 (String8 string, String8* string_tail);
MD_API B32 str8_is_integer (String8 string, U32 radix);
MD_API U64 u64_from_str8 (String8 string, U32 radix);
S64 s64_from_str8 (String8 string, U32 radix);
MD_API B32 try_u64_from_str8_c_rules(String8 string, U64* x);
B32 try_s64_from_str8_c_rules(String8 string, S64* x);
//- rjf: integer -> string
internal String8 str8_from_memory_size(Arena *arena, U64 z);
internal String8 str8_from_u64 (Arena *arena, U64 u64, U32 radix, U8 min_digits, U8 digit_group_separator);
internal String8 str8_from_s64 (Arena *arena, S64 s64, U32 radix, U8 min_digits, U8 digit_group_separator);
String8 str8_from_memory_size(Arena *arena, U64 z);
MD_API String8 str8_from_u64 (Arena *arena, U64 u64, U32 radix, U8 min_digits, U8 digit_group_separator);
MD_API String8 str8_from_s64 (Arena *arena, S64 s64, U32 radix, U8 min_digits, U8 digit_group_separator);
inline U64
u64_from_str8(String8 string, U32 radix) {
U64 x = 0;
if (1 < radix && radix <= 16) {
for (U64 i = 0; i < string.size; i += 1) {
x *= radix;
x += integer_symbol_reverse[string.str[i]&0x7F];
}
}
return(x);
}
inline S64
s64_from_str8(String8 string, U32 radix) {
S64 sign = sign_from_str8(string, &string);
S64 x = (S64)u64_from_str8(string, radix) * sign;
return(x);
}
inline B32
try_s64_from_str8_c_rules(String8 string, S64 *x) {
String8 string_tail = {0};
S64 sign = sign_from_str8(string, &string_tail);
U64 x_u64 = 0;
B32 is_integer = try_u64_from_str8_c_rules(string_tail, &x_u64);
*x = x_u64*sign;
return(is_integer);
}
////////////////////////////////
//~ rjf: String <=> Float Conversions
internal F64 f64_from_str8(String8 string);
F64 f64_from_str8(String8 string);
////////////////////////////////
//~ rjf: String List Construction Functions
internal String8Node* str8_list_push_node (String8List *list, String8Node *node);
internal String8Node* str8_list_push_node_set_string (String8List *list, String8Node *node, String8 string);
internal String8Node* str8_list_push_node_front (String8List *list, String8Node *node);
internal String8Node* str8_list_push_node_front_set_string(String8List *list, String8Node *node, String8 string);
internal String8Node* str8_list_push (Arena *arena, String8List *list, String8 string);
internal String8Node* str8_list_push_front (Arena *arena, String8List *list, String8 string);
internal void str8_list_concat_in_place (String8List *list, String8List *to_push);
internal String8Node* str8_list_push_aligner (Arena *arena, String8List *list, U64 min, U64 align);
internal String8Node* str8_list_pushf (Arena *arena, String8List *list, char *fmt, ...);
internal String8Node* str8_list_push_frontf (Arena *arena, String8List *list, char *fmt, ...);
internal String8List str8_list_copy (Arena *arena, String8List *list);
#define str8_list_first(list) ((list)->first ? (list)->first->string : str8_zero())
String8Node* str8_list_push_node (String8List* list, String8Node* node);
String8Node* str8_list_push_node_set_string (String8List* list, String8Node* node, String8 string);
String8Node* str8_list_push_node_front (String8List* list, String8Node* node);
String8Node* str8_list_push_node_front_set_string(String8List* list, String8Node* node, String8 string);
void str8_list_concat_in_place (String8List *list, String8List* to_push);
inline String8Node*
str8_list_push_node(String8List* list, String8Node* node){
sll_queue_push(list->first, list->last, node);
list->node_count += 1;
list->total_size += node->string.size;
return(node);
}
inline String8Node*
str8_list_push_node_set_string(String8List* list, String8Node* node, String8 string) {
sll_queue_push(list->first, list->last, node);
list->node_count += 1;
list->total_size += string.size;
node->string = string;
return(node);
}
inline String8Node*
str8_list_push_node_front(String8List* list, String8Node* node) {
sll_queue_push_front(list->first, list->last, node);
list->node_count += 1;
list->total_size += node->string.size;
return(node);
}
inline String8Node*
str8_list_push_node_front_set_string(String8List* list, String8Node* node, String8 string) {
sll_queue_push_front(list->first, list->last, node);
list->node_count += 1;
list->total_size += string.size;
node->string = string;
return(node);
}
String8Node* str8_list_push (Arena* arena, String8List* list, String8 string);
String8Node* str8_list_push_front (Arena* arena, String8List* list, String8 string);
String8Node* str8_list_push_aligner(Arena* arena, String8List* list, U64 min, U64 align);
String8Node* str8_list_pushf (Arena* arena, String8List* list, char* fmt, ...);
String8Node* str8_list_push_frontf (Arena* arena, String8List* list, char* fmt, ...);
String8List str8_list_copy (Arena* arena, String8List* list);
inline String8Node*
str8_list_push(Arena* arena, String8List* list, String8 string) {
String8Node* node = push_array_no_zero(arena, String8Node, 1);
str8_list_push_node_set_string(list, node, string);
return(node);
}
inline String8Node*
str8_list_push_front(Arena* arena, String8List* list, String8 string) {
String8Node *node = push_array_no_zero(arena, String8Node, 1);
str8_list_push_node_front_set_string(list, node, string);
return(node);
}
////////////////////////////////
//~ rjf: String Splitting & Joining
@@ -479,9 +576,9 @@ struct String8TxtPtPair
////////////////////////////////
//~ rjf: Text Path Helpers
internal String8TxtPtPair str8_txt_pt_pair_from_string(String8 string);
String8TxtPtPair str8_txt_pt_pair_from_string(String8 string);
////////////////////////////////
//~ rjf: Text Wrapping
internal String8List wrapped_lines_from_string(Arena *arena, String8 string, U64 first_line_max_width, U64 max_width, U64 wrap_indent);
String8List wrapped_lines_from_string(Arena *arena, String8 string, U64 first_line_max_width, U64 max_width, U64 wrap_indent);
+43 -67
View File
@@ -1,87 +1,63 @@
#ifdef INTELLISENSE_DIRECTIVES
# include "thread_context.h"
#endif
// Copyright (c) 2024 Epic Games Tools
// Licensed under the MIT license (https://opensource.org/license/mit/)
////////////////////////////////
// NOTE(allen): Thread Context Functions
C_LINKAGE thread_static TCTX* tctx_thread_local;
#if !BUILD_SUPPLEMENTARY_UNIT
C_LINKAGE thread_static TCTX* tctx_thread_local = 0;
thread_static TCTX* tctx_thread_local;
#if ! MD_BUILD_SUPPLEMENTARY_UNIT
thread_static TCTX* tctx_thread_local = 0;
#endif
internal void
tctx_init_and_equip(TCTX *tctx){
MemoryZeroStruct(tctx);
Arena **arena_ptr = tctx->arenas;
for (U64 i = 0; i < ArrayCount(tctx->arenas); i += 1, arena_ptr += 1){
*arena_ptr = arena_alloc();
}
tctx_thread_local = tctx;
void
tctx_init_and_equip(TCTX* tctx){
memory_zero_struct(tctx);
Arena** arena_ptr = tctx->arenas;
for (U64 i = 0; i < array_count(tctx->arenas); i += 1, arena_ptr += 1) {
*arena_ptr = arena_alloc();
}
tctx_thread_local = tctx;
}
internal void
tctx_release(void)
{
for(U64 i = 0; i < ArrayCount(tctx_thread_local->arenas); i += 1)
{
void
tctx_release(void) {
for (U64 i = 0; i < array_count(tctx_thread_local->arenas); i += 1) {
arena_release(tctx_thread_local->arenas[i]);
}
}
internal TCTX*
TCTX*
tctx_get_equipped(void){
return(tctx_thread_local);
}
internal Arena*
tctx_get_scratch(Arena **conflicts, U64 count){
TCTX *tctx = tctx_get_equipped();
Arena *result = 0;
Arena **arena_ptr = tctx->arenas;
for (U64 i = 0; i < ArrayCount(tctx->arenas); i += 1, arena_ptr += 1){
Arena **conflict_ptr = conflicts;
B32 has_conflict = 0;
for (U64 j = 0; j < count; j += 1, conflict_ptr += 1){
if (*arena_ptr == *conflict_ptr){
has_conflict = 1;
break;
}
}
if (!has_conflict){
result = *arena_ptr;
break;
}
}
return(result);
}
Arena*
tctx_get_scratch(Arena** conflicts, U64 count)
{
TCTX* tctx = tctx_get_equipped();
internal void
tctx_set_thread_name(String8 string){
TCTX *tctx = tctx_get_equipped();
U64 size = ClampTop(string.size, sizeof(tctx->thread_name));
MemoryCopy(tctx->thread_name, string.str, size);
tctx->thread_name_size = size;
}
internal String8
tctx_get_thread_name(void){
TCTX *tctx = tctx_get_equipped();
String8 result = str8(tctx->thread_name, tctx->thread_name_size);
return(result);
}
internal void
tctx_write_srcloc(char *file_name, U64 line_number){
TCTX *tctx = tctx_get_equipped();
tctx->file_name = file_name;
tctx->line_number = line_number;
}
internal void
tctx_read_srcloc(char **file_name, U64 *line_number){
TCTX *tctx = tctx_get_equipped();
*file_name = tctx->file_name;
*line_number = tctx->line_number;
Arena* result = 0;
Arena** arena_ptr = tctx->arenas;
for (U64 i = 0; i < array_count(tctx->arenas); i += 1, arena_ptr += 1)
{
Arena** conflict_ptr = conflicts;
B32 has_conflict = 0;
for (U64 j = 0; j < count; j += 1, conflict_ptr += 1)
{
if (*arena_ptr == *conflict_ptr) {
has_conflict = 1;
break;
}
}
if ( ! has_conflict){
result = *arena_ptr;
break;
}
}
return(result);
}
+47 -19
View File
@@ -1,9 +1,7 @@
#ifdef INTELLISENSE_DIRECTIVES
# pragma once
# include "linkage.h"
# include "base_types.h"
# include "strings.h"
# include "arena.h"
# include "string.h"
#endif
// Copyright (c) 2024 Epic Games Tools
@@ -15,30 +13,60 @@
typedef struct TCTX TCTX;
struct TCTX
{
Arena* arenas[2];
U8 thread_name[32];
U64 thread_name_size;
char* file_name;
U64 line_number;
AllocatorInfo ainfos[2];
Arena* arenas[2];
U8 thread_name[32];
U64 thread_name_size;
char* file_name;
U64 line_number;
};
////////////////////////////////
// NOTE(allen): Thread Context Functions
internal void tctx_init_and_equip(TCTX *tctx);
internal void tctx_release(void);
internal TCTX* tctx_get_equipped(void);
MD_API void tctx_init_and_equip(TCTX *tctx, AllocatorInfo ainfo);
MD_API void tctx_release(void);
MD_API TCTX* tctx_get_equipped(void);
internal Arena* tctx_get_scratch(Arena** conflicts, U64 count);
MD_API Arena* tctx_get_scratch(Arena** conflicts, U64 count);
internal void tctx_set_thread_name(String8 name);
internal String8 tctx_get_thread_name(void);
void tctx_set_thread_name(String8 name);
String8 tctx_get_thread_name(void);
internal void tctx_write_srcloc(char* file_name, U64 line_number);
internal void tctx_read_srcloc (char** file_name, U64* line_number);
#define tctx_write_this_srcloc() tctx_write_srcloc(__FILE__, __LINE__)
void tctx_write_srcloc(char* file_name, U64 line_number);
void tctx_read_srcloc (char** file_name, U64* line_number);
#define tctx_write_this_srcloc() tctx_write_srcloc(__FILE__, __LINE__)
#define scratch_begin(conflicts, count) temp_begin(tctx_get_scratch((conflicts), (count)))
#define scratch_end(scratch) temp_end(scratch)
inline void
tctx_set_thread_name(String8 string){
TCTX* tctx = tctx_get_equipped();
U64 size = clamp_top(string.size, sizeof(tctx->thread_name));
memory_copy(tctx->thread_name, string.str, size);
tctx->thread_name_size = size;
}
inline String8
tctx_get_thread_name(void) {
TCTX* tctx = tctx_get_equipped();
String8 result = str8(tctx->thread_name, tctx->thread_name_size);
return(result);
}
inline void
tctx_write_srcloc(char *file_name, U64 line_number){
TCTX *tctx = tctx_get_equipped();
tctx->file_name = file_name;
tctx->line_number = line_number;
}
inline void
tctx_read_srcloc(char** file_name, U64* line_number){
TCTX* tctx = tctx_get_equipped();
*file_name = tctx->file_name;
*line_number = tctx->line_number;
}
+1
View File
@@ -21,6 +21,7 @@ MD_NS_BEGIN
#include "base/memory.h"
#include "base/memory_substrate.h"
#include "base/arena.h"
#include "base/thread_context.h"
#include "base/space.h"
#include "base/math.h"
#include "base/toolchain.h"