mirror of
https://github.com/Ed94/metadesk.git
synced 2026-08-07 16:18:49 +00:00
progress on strings.h/c started to look at thread_context.h/c
This commit is contained in:
@@ -2,6 +2,17 @@
|
|||||||
# pragma once
|
# pragma once
|
||||||
#endif
|
#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
|
#pragma region Compiler Vendor
|
||||||
|
|
||||||
#if defined( _MSC_VER )
|
#if defined( _MSC_VER )
|
||||||
|
|||||||
+50
-138
@@ -1,6 +1,7 @@
|
|||||||
#ifdef INTELLISENSE_DIRECTIVES
|
#ifdef INTELLISENSE_DIRECTIVES
|
||||||
#pragma once
|
# pragma once
|
||||||
#include "base/strings.h"
|
# include "strings.h"
|
||||||
|
# include "thread_context.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// Copyright (c) 2024 Epic Games Tools
|
// Copyright (c) 2024 Epic Games Tools
|
||||||
@@ -150,7 +151,7 @@ str8_skip_chop_whitespace(String8 string)
|
|||||||
}
|
}
|
||||||
for (; opl > first; ){
|
for (; opl > first; ){
|
||||||
opl -= 1;
|
opl -= 1;
|
||||||
if ( ! char_is_space(*opl)){ opl += 1; break; }
|
if ( ! char_is_space(*opl)) { opl += 1; break; }
|
||||||
}
|
}
|
||||||
String8 result = str8_range(first, opl);
|
String8 result = str8_range(first, opl);
|
||||||
return(result);
|
return(result);
|
||||||
@@ -171,7 +172,7 @@ push_str8_cat(Arena* arena, String8 s1, String8 s2)
|
|||||||
return(str);
|
return(str);
|
||||||
}
|
}
|
||||||
|
|
||||||
internal String8
|
String8
|
||||||
push_str8_copy(Arena *arena, String8 s){
|
push_str8_copy(Arena *arena, String8 s){
|
||||||
String8 str;
|
String8 str;
|
||||||
str.size = s.size;
|
str.size = s.size;
|
||||||
@@ -181,7 +182,7 @@ push_str8_copy(Arena *arena, String8 s){
|
|||||||
return(str);
|
return(str);
|
||||||
}
|
}
|
||||||
|
|
||||||
internal String8
|
String8
|
||||||
push_str8fv(Arena *arena, char *fmt, va_list args){
|
push_str8fv(Arena *arena, char *fmt, va_list args){
|
||||||
va_list args2;
|
va_list args2;
|
||||||
va_copy(args2, args);
|
va_copy(args2, args);
|
||||||
@@ -194,15 +195,6 @@ push_str8fv(Arena *arena, char *fmt, va_list args){
|
|||||||
return(result);
|
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
|
String8
|
||||||
str8__cat(String8 s1, String8 s2, AllocatorInfo ainfo)
|
str8__cat(String8 s1, String8 s2, AllocatorInfo ainfo)
|
||||||
{
|
{
|
||||||
@@ -226,8 +218,8 @@ str8__copy(String8 s, AllocatorInfo ainfo)
|
|||||||
return(str);
|
return(str);
|
||||||
}
|
}
|
||||||
|
|
||||||
internal String8
|
String8
|
||||||
push_str8fv(AllocatorInfo ainfo, char *fmt, va_list args){
|
str8fv(AllocatorInfo ainfo, char *fmt, va_list args){
|
||||||
va_list args2;
|
va_list args2;
|
||||||
va_copy(args2, args);
|
va_copy(args2, args);
|
||||||
U32 needed_bytes = raddbg_vsnprintf(0, 0, fmt, args) + 1;
|
U32 needed_bytes = raddbg_vsnprintf(0, 0, fmt, args) + 1;
|
||||||
@@ -244,88 +236,72 @@ push_str8fv(AllocatorInfo ainfo, char *fmt, va_list args){
|
|||||||
|
|
||||||
//- rjf: string -> integer
|
//- rjf: string -> integer
|
||||||
|
|
||||||
internal S64
|
S64
|
||||||
sign_from_str8(String8 string, String8 *string_tail){
|
sign_from_str8(String8 string, String8* string_tail)
|
||||||
|
{
|
||||||
// count negative signs
|
// count negative signs
|
||||||
U64 neg_count = 0;
|
U64 neg_count = 0;
|
||||||
U64 i = 0;
|
U64 i = 0;
|
||||||
for (; i < string.size; i += 1){
|
for (; i < string.size; i += 1){
|
||||||
if (string.str[i] == '-'){
|
if (string.str[i] == '-') {
|
||||||
neg_count += 1;
|
neg_count += 1;
|
||||||
}
|
}
|
||||||
else if (string.str[i] != '+'){
|
else if (string.str[i] != '+') {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// output part of string after signs
|
// output part of string after signs
|
||||||
*string_tail = str8_skip(string, i);
|
*string_tail = str8_skip(string, i);
|
||||||
|
|
||||||
// output integer sign
|
// output integer sign
|
||||||
S64 sign = (neg_count & 1)?-1:+1;
|
S64 sign = (neg_count & 1)?-1:+1;
|
||||||
return(sign);
|
return(sign);
|
||||||
}
|
}
|
||||||
|
|
||||||
internal B32
|
B32
|
||||||
str8_is_integer(String8 string, U32 radix){
|
str8_is_integer(String8 string, U32 radix){
|
||||||
B32 result = 0;
|
B32 result = 0;
|
||||||
if (string.size > 0){
|
if (string.size > 0 && (1 < radix && radix <= 16)) {
|
||||||
if (1 < radix && radix <= 16){
|
|
||||||
result = 1;
|
result = 1;
|
||||||
for (U64 i = 0; i < string.size; i += 1){
|
for (U64 i = 0; i < string.size; i += 1) {
|
||||||
U8 c = string.str[i];
|
U8 c = string.str[i];
|
||||||
if (!(c < 0x80) || integer_symbol_reverse[c] >= radix){
|
if ( ! (c < 0x80) || integer_symbol_reverse[c] >= radix){
|
||||||
result = 0;
|
result = 0;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
return(result);
|
return(result);
|
||||||
}
|
}
|
||||||
|
|
||||||
internal U64
|
B32
|
||||||
u64_from_str8(String8 string, U32 radix){
|
try_u64_from_str8_c_rules(String8 string, U64 *x)
|
||||||
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;
|
B32 is_integer = 0;
|
||||||
if (str8_is_integer(string, 10)){
|
if (str8_is_integer(string, 10)) {
|
||||||
is_integer = 1;
|
is_integer = 1;
|
||||||
*x = u64_from_str8(string, 10);
|
*x = u64_from_str8(string, 10);
|
||||||
}
|
}
|
||||||
else{
|
else
|
||||||
|
{
|
||||||
String8 hex_string = str8_skip(string, 2);
|
String8 hex_string = str8_skip(string, 2);
|
||||||
if (str8_match(str8_prefix(string, 2), str8_lit("0x"), 0) &&
|
if (str8_match(str8_prefix(string, 2), str8_lit("0x"), 0) &&
|
||||||
str8_is_integer(hex_string, 0x10)){
|
str8_is_integer(hex_string, 0x10))
|
||||||
|
{
|
||||||
is_integer = 1;
|
is_integer = 1;
|
||||||
*x = u64_from_str8(hex_string, 0x10);
|
*x = u64_from_str8(hex_string, 0x10);
|
||||||
}
|
}
|
||||||
else if (str8_match(str8_prefix(string, 2), str8_lit("0b"), 0) &&
|
else if (str8_match(str8_prefix(string, 2), str8_lit("0b"), 0) &&
|
||||||
str8_is_integer(hex_string, 2)){
|
str8_is_integer(hex_string, 2))
|
||||||
|
{
|
||||||
is_integer = 1;
|
is_integer = 1;
|
||||||
*x = u64_from_str8(hex_string, 2);
|
*x = u64_from_str8(hex_string, 2);
|
||||||
}
|
}
|
||||||
else{
|
else
|
||||||
|
{
|
||||||
String8 oct_string = str8_skip(string, 1);
|
String8 oct_string = str8_skip(string, 1);
|
||||||
if (str8_match(str8_prefix(string, 1), str8_lit("0"), 0) &&
|
if (str8_match(str8_prefix(string, 1), str8_lit("0"), 0) &&
|
||||||
str8_is_integer(hex_string, 010)){
|
str8_is_integer(hex_string, 010))
|
||||||
|
{
|
||||||
is_integer = 1;
|
is_integer = 1;
|
||||||
*x = u64_from_str8(oct_string, 010);
|
*x = u64_from_str8(oct_string, 010);
|
||||||
}
|
}
|
||||||
@@ -334,28 +310,18 @@ try_u64_from_str8_c_rules(String8 string, U64 *x){
|
|||||||
return(is_integer);
|
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);
|
|
||||||
}
|
|
||||||
|
|
||||||
//- rjf: integer -> string
|
//- rjf: integer -> string
|
||||||
|
|
||||||
internal String8
|
String8
|
||||||
str8_from_memory_size(Arena *arena, U64 z){
|
str8_from_memory_size(Arena *arena, U64 z) {
|
||||||
String8 result = {0};
|
String8 result = {0};
|
||||||
if (z < KB(1)){
|
if (z < KB(1)) {
|
||||||
result = push_str8f(arena, "%llu b", z);
|
result = push_str8f(arena, "%llu b", z);
|
||||||
}
|
}
|
||||||
else if (z < MB(1)){
|
else if (z < MB(1)) {
|
||||||
result = push_str8f(arena, "%llu.%02llu Kb", z/KB(1), ((100*z)/KB(1))%100);
|
result = push_str8f(arena, "%llu.%02llu Kb", z/KB(1), ((100*z)/KB(1))%100);
|
||||||
}
|
}
|
||||||
else if (z < GB(1)){
|
else if (z < GB(1)) {
|
||||||
result = push_str8f(arena, "%llu.%02llu Mb", z/MB(1), ((100*z)/MB(1))%100);
|
result = push_str8f(arena, "%llu.%02llu Mb", z/MB(1), ((100*z)/MB(1))%100);
|
||||||
}
|
}
|
||||||
else{
|
else{
|
||||||
@@ -364,7 +330,7 @@ str8_from_memory_size(Arena *arena, U64 z){
|
|||||||
return(result);
|
return(result);
|
||||||
}
|
}
|
||||||
|
|
||||||
internal String8
|
String8
|
||||||
str8_from_u64(Arena *arena, U64 u64, U32 radix, U8 min_digits, U8 digit_group_separator)
|
str8_from_u64(Arena *arena, U64 u64, U32 radix, U8 min_digits, U8 digit_group_separator)
|
||||||
{
|
{
|
||||||
String8 result = {0};
|
String8 result = {0};
|
||||||
@@ -386,7 +352,7 @@ str8_from_u64(Arena *arena, U64 u64, U32 radix, U8 min_digits, U8 digit_group_se
|
|||||||
case 2:
|
case 2:
|
||||||
case 8:
|
case 8:
|
||||||
case 16:
|
case 16:
|
||||||
{digit_group_size = 4;}break;
|
{digit_group_size = 4;} break;
|
||||||
}
|
}
|
||||||
|
|
||||||
// rjf: prep
|
// rjf: prep
|
||||||
@@ -398,8 +364,7 @@ str8_from_u64(Arena *arena, U64 u64, U32 radix, U8 min_digits, U8 digit_group_se
|
|||||||
for(;;)
|
for(;;)
|
||||||
{
|
{
|
||||||
u64_reduce /= radix;
|
u64_reduce /= radix;
|
||||||
if(u64_reduce == 0)
|
if(u64_reduce == 0) {
|
||||||
{
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
needed_digits += 1;
|
needed_digits += 1;
|
||||||
@@ -407,7 +372,7 @@ str8_from_u64(Arena *arena, U64 u64, U32 radix, U8 min_digits, U8 digit_group_se
|
|||||||
}
|
}
|
||||||
needed_leading_0s = (min_digits > needed_digits) ? min_digits - needed_digits : 0;
|
needed_leading_0s = (min_digits > needed_digits) ? min_digits - needed_digits : 0;
|
||||||
U64 needed_separators = 0;
|
U64 needed_separators = 0;
|
||||||
if(digit_group_separator != 0)
|
if (digit_group_separator != 0)
|
||||||
{
|
{
|
||||||
needed_separators = (needed_digits+needed_leading_0s)/digit_group_size;
|
needed_separators = (needed_digits+needed_leading_0s)/digit_group_size;
|
||||||
if(needed_separators > 0 && (needed_digits+needed_leading_0s)%digit_group_size == 0)
|
if(needed_separators > 0 && (needed_digits+needed_leading_0s)%digit_group_size == 0)
|
||||||
@@ -424,21 +389,18 @@ str8_from_u64(Arena *arena, U64 u64, U32 radix, U8 min_digits, U8 digit_group_se
|
|||||||
{
|
{
|
||||||
U64 u64_reduce = u64;
|
U64 u64_reduce = u64;
|
||||||
U64 digits_until_separator = digit_group_size;
|
U64 digits_until_separator = digit_group_size;
|
||||||
for(U64 idx = 0; idx < result.size; idx += 1)
|
for (U64 idx = 0; idx < result.size; idx += 1)
|
||||||
{
|
|
||||||
if(digits_until_separator == 0 && digit_group_separator != 0)
|
|
||||||
{
|
{
|
||||||
|
if(digits_until_separator == 0 && digit_group_separator != 0) {
|
||||||
result.str[result.size - idx - 1] = digit_group_separator;
|
result.str[result.size - idx - 1] = digit_group_separator;
|
||||||
digits_until_separator = digit_group_size+1;
|
digits_until_separator = digit_group_size+1;
|
||||||
}
|
}
|
||||||
else
|
else {
|
||||||
{
|
|
||||||
result.str[result.size - idx - 1] = char_to_lower(integer_symbols[u64_reduce%radix]);
|
result.str[result.size - idx - 1] = char_to_lower(integer_symbols[u64_reduce%radix]);
|
||||||
u64_reduce /= radix;
|
u64_reduce /= radix;
|
||||||
}
|
}
|
||||||
digits_until_separator -= 1;
|
digits_until_separator -= 1;
|
||||||
if(u64_reduce == 0)
|
if(u64_reduce == 0) {
|
||||||
{
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -451,26 +413,24 @@ str8_from_u64(Arena *arena, U64 u64, U32 radix, U8 min_digits, U8 digit_group_se
|
|||||||
// rjf: fill prefix
|
// rjf: fill prefix
|
||||||
if(prefix.size != 0)
|
if(prefix.size != 0)
|
||||||
{
|
{
|
||||||
MemoryCopy(result.str, prefix.str, prefix.size);
|
memory_copy(result.str, prefix.str, prefix.size);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
internal String8
|
String8
|
||||||
str8_from_s64(Arena *arena, S64 s64, U32 radix, U8 min_digits, U8 digit_group_separator)
|
str8_from_s64(Arena *arena, S64 s64, U32 radix, U8 min_digits, U8 digit_group_separator)
|
||||||
{
|
{
|
||||||
String8 result = {0};
|
String8 result = {0};
|
||||||
// TODO(rjf): preeeeetty sloppy...
|
// TODO(rjf): preeeeetty sloppy...
|
||||||
if(s64 < 0)
|
if(s64 < 0) {
|
||||||
{
|
TempArena scratch = scratch_begin( & arena, 1);
|
||||||
Temp scratch = scratch_begin(&arena, 1);
|
|
||||||
String8 numeric_part = str8_from_u64(scratch.arena, (U64)(-s64), radix, min_digits, digit_group_separator);
|
String8 numeric_part = str8_from_u64(scratch.arena, (U64)(-s64), radix, min_digits, digit_group_separator);
|
||||||
result = push_str8f(arena, "-%S", numeric_part);
|
result = push_str8f(arena, "-%S", numeric_part);
|
||||||
scratch_end(scratch);
|
scratch_end(scratch);
|
||||||
}
|
}
|
||||||
else
|
else {
|
||||||
{
|
|
||||||
result = str8_from_u64(arena, (U64)s64, radix, min_digits, digit_group_separator);
|
result = str8_from_u64(arena, (U64)s64, radix, min_digits, digit_group_separator);
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
@@ -484,7 +444,7 @@ f64_from_str8(String8 string)
|
|||||||
{
|
{
|
||||||
// TODO(rjf): crappy implementation for now that just uses atof.
|
// TODO(rjf): crappy implementation for now that just uses atof.
|
||||||
F64 result = 0;
|
F64 result = 0;
|
||||||
if(string.size > 0)
|
if (string.size > 0)
|
||||||
{
|
{
|
||||||
// rjf: find starting pos of numeric string, as well as sign
|
// rjf: find starting pos of numeric string, as well as sign
|
||||||
F64 sign = +1.0;
|
F64 sign = +1.0;
|
||||||
@@ -524,54 +484,6 @@ f64_from_str8(String8 string)
|
|||||||
////////////////////////////////
|
////////////////////////////////
|
||||||
//~ rjf: String List Construction Functions
|
//~ 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
|
internal void
|
||||||
str8_list_concat_in_place(String8List *list, String8List *to_push){
|
str8_list_concat_in_place(String8List *list, String8List *to_push){
|
||||||
if(to_push->node_count != 0){
|
if(to_push->node_count != 0){
|
||||||
|
|||||||
+127
-30
@@ -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_cat (Arena* arena, String8 s1, String8 s2);
|
||||||
MD_API String8 push_str8_copy(Arena* arena, String8 s);
|
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_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);
|
MD_API String8 str8__cat (String8 s1, String8 s2, AllocatorInfo ainfo);
|
||||||
String8 str8__copy(String8 s, AllocatorInfo ainfo);
|
MD_API String8 str8__copy(String8 s, AllocatorInfo ainfo);
|
||||||
|
MD_API String8 str8fv (AllocatorInfo ainfo, char* fmt, va_list args);
|
||||||
String8 str8fv(AllocatorInfo ainfo, char* fmt, va_list args);
|
String8 str8f (AllocatorInfo ainfo, char* fmt, ...);
|
||||||
String8 str8f (AllocatorInfo afino, char* fmt, ...);
|
|
||||||
|
|
||||||
#define str8_cat(s1, s2, ...) str8__cat (s1, s2, (AllocatorInfo) {__VA_ARGS__})
|
#define str8_cat(s1, s2, ...) str8__cat (s1, s2, (AllocatorInfo) {__VA_ARGS__})
|
||||||
#define str8_copy(s, ...) str8__copy(s, (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 Conversions
|
||||||
|
|
||||||
//- rjf: string -> integer
|
//- rjf: string -> integer
|
||||||
internal S64 sign_from_str8 (String8 string, String8 *string_tail);
|
MD_API S64 sign_from_str8 (String8 string, String8* string_tail);
|
||||||
internal B32 str8_is_integer (String8 string, U32 radix);
|
MD_API B32 str8_is_integer (String8 string, U32 radix);
|
||||||
internal U64 u64_from_str8 (String8 string, U32 radix);
|
MD_API U64 u64_from_str8 (String8 string, U32 radix);
|
||||||
internal S64 s64_from_str8 (String8 string, U32 radix);
|
S64 s64_from_str8 (String8 string, U32 radix);
|
||||||
internal B32 try_u64_from_str8_c_rules(String8 string, U64 *x);
|
MD_API B32 try_u64_from_str8_c_rules(String8 string, U64* x);
|
||||||
internal B32 try_s64_from_str8_c_rules(String8 string, S64 *x);
|
B32 try_s64_from_str8_c_rules(String8 string, S64* x);
|
||||||
|
|
||||||
//- rjf: integer -> string
|
//- rjf: integer -> string
|
||||||
internal String8 str8_from_memory_size(Arena *arena, U64 z);
|
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);
|
MD_API 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);
|
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
|
//~ rjf: String <=> Float Conversions
|
||||||
|
|
||||||
internal F64 f64_from_str8(String8 string);
|
F64 f64_from_str8(String8 string);
|
||||||
|
|
||||||
////////////////////////////////
|
////////////////////////////////
|
||||||
//~ rjf: String List Construction Functions
|
//~ 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())
|
#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
|
//~ rjf: String Splitting & Joining
|
||||||
|
|
||||||
@@ -479,9 +576,9 @@ struct String8TxtPtPair
|
|||||||
////////////////////////////////
|
////////////////////////////////
|
||||||
//~ rjf: Text Path Helpers
|
//~ 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
|
//~ 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);
|
||||||
|
|||||||
+30
-54
@@ -1,87 +1,63 @@
|
|||||||
|
#ifdef INTELLISENSE_DIRECTIVES
|
||||||
|
# include "thread_context.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
// Copyright (c) 2024 Epic Games Tools
|
// Copyright (c) 2024 Epic Games Tools
|
||||||
// Licensed under the MIT license (https://opensource.org/license/mit/)
|
// Licensed under the MIT license (https://opensource.org/license/mit/)
|
||||||
|
|
||||||
////////////////////////////////
|
////////////////////////////////
|
||||||
// NOTE(allen): Thread Context Functions
|
// NOTE(allen): Thread Context Functions
|
||||||
|
|
||||||
C_LINKAGE thread_static TCTX* tctx_thread_local;
|
thread_static TCTX* tctx_thread_local;
|
||||||
#if !BUILD_SUPPLEMENTARY_UNIT
|
|
||||||
C_LINKAGE thread_static TCTX* tctx_thread_local = 0;
|
#if ! MD_BUILD_SUPPLEMENTARY_UNIT
|
||||||
|
thread_static TCTX* tctx_thread_local = 0;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
internal void
|
void
|
||||||
tctx_init_and_equip(TCTX *tctx){
|
tctx_init_and_equip(TCTX* tctx){
|
||||||
MemoryZeroStruct(tctx);
|
memory_zero_struct(tctx);
|
||||||
Arena **arena_ptr = tctx->arenas;
|
Arena** arena_ptr = tctx->arenas;
|
||||||
for (U64 i = 0; i < ArrayCount(tctx->arenas); i += 1, arena_ptr += 1){
|
for (U64 i = 0; i < array_count(tctx->arenas); i += 1, arena_ptr += 1) {
|
||||||
*arena_ptr = arena_alloc();
|
*arena_ptr = arena_alloc();
|
||||||
}
|
}
|
||||||
tctx_thread_local = tctx;
|
tctx_thread_local = tctx;
|
||||||
}
|
}
|
||||||
|
|
||||||
internal void
|
void
|
||||||
tctx_release(void)
|
tctx_release(void) {
|
||||||
{
|
for (U64 i = 0; i < array_count(tctx_thread_local->arenas); i += 1) {
|
||||||
for(U64 i = 0; i < ArrayCount(tctx_thread_local->arenas); i += 1)
|
|
||||||
{
|
|
||||||
arena_release(tctx_thread_local->arenas[i]);
|
arena_release(tctx_thread_local->arenas[i]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
internal TCTX*
|
TCTX*
|
||||||
tctx_get_equipped(void){
|
tctx_get_equipped(void){
|
||||||
return(tctx_thread_local);
|
return(tctx_thread_local);
|
||||||
}
|
}
|
||||||
|
|
||||||
internal Arena*
|
Arena*
|
||||||
tctx_get_scratch(Arena **conflicts, U64 count){
|
tctx_get_scratch(Arena** conflicts, U64 count)
|
||||||
TCTX *tctx = tctx_get_equipped();
|
{
|
||||||
|
TCTX* tctx = tctx_get_equipped();
|
||||||
|
|
||||||
Arena *result = 0;
|
Arena* result = 0;
|
||||||
Arena **arena_ptr = tctx->arenas;
|
Arena** arena_ptr = tctx->arenas;
|
||||||
for (U64 i = 0; i < ArrayCount(tctx->arenas); i += 1, arena_ptr += 1){
|
for (U64 i = 0; i < array_count(tctx->arenas); i += 1, arena_ptr += 1)
|
||||||
Arena **conflict_ptr = conflicts;
|
{
|
||||||
|
Arena** conflict_ptr = conflicts;
|
||||||
B32 has_conflict = 0;
|
B32 has_conflict = 0;
|
||||||
for (U64 j = 0; j < count; j += 1, conflict_ptr += 1){
|
for (U64 j = 0; j < count; j += 1, conflict_ptr += 1)
|
||||||
if (*arena_ptr == *conflict_ptr){
|
{
|
||||||
|
if (*arena_ptr == *conflict_ptr) {
|
||||||
has_conflict = 1;
|
has_conflict = 1;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!has_conflict){
|
if ( ! has_conflict){
|
||||||
result = *arena_ptr;
|
result = *arena_ptr;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return(result);
|
return(result);
|
||||||
}
|
}
|
||||||
|
|
||||||
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;
|
|
||||||
}
|
|
||||||
|
|||||||
+39
-11
@@ -1,9 +1,7 @@
|
|||||||
#ifdef INTELLISENSE_DIRECTIVES
|
#ifdef INTELLISENSE_DIRECTIVES
|
||||||
# pragma once
|
# pragma once
|
||||||
# include "linkage.h"
|
|
||||||
# include "base_types.h"
|
|
||||||
# include "strings.h"
|
|
||||||
# include "arena.h"
|
# include "arena.h"
|
||||||
|
# include "string.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// Copyright (c) 2024 Epic Games Tools
|
// Copyright (c) 2024 Epic Games Tools
|
||||||
@@ -15,6 +13,7 @@
|
|||||||
typedef struct TCTX TCTX;
|
typedef struct TCTX TCTX;
|
||||||
struct TCTX
|
struct TCTX
|
||||||
{
|
{
|
||||||
|
AllocatorInfo ainfos[2];
|
||||||
Arena* arenas[2];
|
Arena* arenas[2];
|
||||||
|
|
||||||
U8 thread_name[32];
|
U8 thread_name[32];
|
||||||
@@ -27,18 +26,47 @@ struct TCTX
|
|||||||
////////////////////////////////
|
////////////////////////////////
|
||||||
// NOTE(allen): Thread Context Functions
|
// NOTE(allen): Thread Context Functions
|
||||||
|
|
||||||
internal void tctx_init_and_equip(TCTX *tctx);
|
MD_API void tctx_init_and_equip(TCTX *tctx, AllocatorInfo ainfo);
|
||||||
internal void tctx_release(void);
|
MD_API void tctx_release(void);
|
||||||
internal TCTX* tctx_get_equipped(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);
|
void tctx_set_thread_name(String8 name);
|
||||||
internal String8 tctx_get_thread_name(void);
|
String8 tctx_get_thread_name(void);
|
||||||
|
|
||||||
internal void tctx_write_srcloc(char* file_name, U64 line_number);
|
void tctx_write_srcloc(char* file_name, U64 line_number);
|
||||||
internal void tctx_read_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 tctx_write_this_srcloc() tctx_write_srcloc(__FILE__, __LINE__)
|
||||||
|
|
||||||
#define scratch_begin(conflicts, count) temp_begin(tctx_get_scratch((conflicts), (count)))
|
#define scratch_begin(conflicts, count) temp_begin(tctx_get_scratch((conflicts), (count)))
|
||||||
#define scratch_end(scratch) temp_end(scratch)
|
#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;
|
||||||
|
}
|
||||||
|
|||||||
@@ -21,6 +21,7 @@ MD_NS_BEGIN
|
|||||||
#include "base/memory.h"
|
#include "base/memory.h"
|
||||||
#include "base/memory_substrate.h"
|
#include "base/memory_substrate.h"
|
||||||
#include "base/arena.h"
|
#include "base/arena.h"
|
||||||
|
#include "base/thread_context.h"
|
||||||
#include "base/space.h"
|
#include "base/space.h"
|
||||||
#include "base/math.h"
|
#include "base/math.h"
|
||||||
#include "base/toolchain.h"
|
#include "base/toolchain.h"
|
||||||
|
|||||||
Reference in New Issue
Block a user