finished with base?

This commit is contained in:
2025-02-07 17:11:28 -05:00
parent 4ba6e69156
commit d7498d9511
13 changed files with 268 additions and 122 deletions
+2 -1
View File
@@ -46,7 +46,8 @@
"wmmintrin.h": "c",
"thread": "c",
"cmath": "c",
"string.h": "c"
"string.h": "c",
"time.h": "c"
},
"workbench.colorCustomizations": {
"activityBar.activeBackground": "#713fb8",
+34
View File
@@ -0,0 +1,34 @@
#ifdef INTELLISENSE_DIRECTIVES
# pragma once
#endif
#include "context_cracking.h"
#include "platform.h"
#include "linkage.h"
#include "macros.h"
#include "generic_macros.h"
#include "profiling.h"
#include "namespace.h"
MD_NS_BEGIN
#include "base_types.h"
#include "ring.h"
#include "debug.h"
#include "memory.h"
#include "memory_substrate.h"
#include "arena.h"
#include "space.h"
#include "math.h"
#include "sort.h"
#include "toolchain.h"
#include "strings.h"
#include "thread_context.h"
#include "command_line.h"
#include "markup.h"
#include "logger.h"
#include "entry_point.h"
#include "time.h"
#include "file.h"
MD_NS_END
+2 -1
View File
@@ -19,7 +19,7 @@ void main_thread_base_entry_point(MainThread_EntryPointProc* entry_point, char**
#endif
ThreadNameF("[main thread]");
// TODO(Ed): Review
// TODO(Ed): Review?
TempArena scratch = scratch_begin(0, 0);
String8List command_line_argument_strings = os_string_list_from_argcv(scratch.arena, (int)arguments_count, arguments);
@@ -43,6 +43,7 @@ void main_thread_base_entry_point(MainThread_EntryPointProc* entry_point, char**
void
supplement_thread_base_entry_point(SupplementThread_EntryPointProc* entry_point, void* params)
{
// TODO(Ed): Review?
TCTX tctx;
tctx_init_and_equip(&tctx);
entry_point(params);
+5 -5
View File
@@ -10,14 +10,14 @@
typedef U32 FilePropertyFlags;
enum
{
FilePropertyFlag_IsFolder = (1 << 0),
FilePropertyFlag_IsFolder = (1 << 0),
};
typedef struct FileProperties FileProperties;
struct FileProperties
{
U64 size;
DenseTime modified;
DenseTime created;
FilePropertyFlags flags;
U64 size;
DenseTime modified;
DenseTime created;
FilePropertyFlags flags;
};
+29
View File
@@ -22,6 +22,35 @@ log_select(Log* log) {
log_active = log;
}
////////////////////////////////
//~ rjf: Log Building
void
log_msg(LogMsgKind kind, String8 string) {
if(log_active != 0 && log_active->top_scope != 0) {
String8 string_copy = push_str8_copy(log_active->arena, string);
str8_list_push(log_active->arena, &log_active->top_scope->strings[kind], string_copy);
}
}
void
log_msgf(LogMsgKind kind, char *fmt, ...) {
if(log_active != 0)
{
// TODO(Ed): Review
TempArena scratch = scratch_begin(0, 0);
va_list args;
va_start(args, fmt);
String8 string = push_str8fv(scratch.arena, fmt, args);
log_msg(kind, string);
va_end(args);
scratch_end(scratch);
}
}
////////////////////////////////
//~ rjf: Log Scopes
+2 -27
View File
@@ -68,33 +68,8 @@ inline void log_release(Log* log) { arena_release(log->arena); }
////////////////////////////////
//~ rjf: Log Building
void log_msg (LogMsgKind kind, String8 string);
void log_msgf(LogMsgKind kind, char* fmt, ...);
inline void
log_msg(LogMsgKind kind, String8 string) {
if(log_active != 0 && log_active->top_scope != 0) {
String8 string_copy = push_str8_copy(log_active->arena, string);
str8_list_push(log_active->arena, &log_active->top_scope->strings[kind], string_copy);
}
}
inline void
log_msgf(LogMsgKind kind, char *fmt, ...) {
if(log_active != 0)
{
// TODO(Ed): Review
TempArena scratch = scratch_begin(0, 0);
va_list args;
va_start(args, fmt);
String8 string = push_str8fv(scratch.arena, fmt, args);
log_msg(kind, string);
va_end(args);
scratch_end(scratch);
}
}
MD_API void log_msg (LogMsgKind kind, String8 string);
MD_API void log_msgf(LogMsgKind kind, char* fmt, ...);
#define log_info(s) log_msg (LogMsgKind_Info, (s))
#define log_infof(fmt, ...) log_msgf(LogMsgKind_Info, (fmt), __VA_ARGS__)
+36 -3
View File
@@ -6,8 +6,41 @@
////////////////////////////////
//~ rjf: Non-Fancy Ring Buffer Reads/Writes
internal U64 ring_write(U8*ring_base, U64 ring_size, U64 ring_pos, void* src_data, U64 src_data_size);
internal U64 ring_read (U8*ring_base, U64 ring_size, U64 ring_pos, void* dst_data, U64 read_size);
U64 ring_write(U8* ring_base, U64 ring_size, U64 ring_pos, void* src_data, U64 src_data_size);
U64 ring_read (U8* ring_base, U64 ring_size, U64 ring_pos, void* dst_data, U64 read_size);
#define ring_write_struct(ring_base, ring_size, ring_pos, ptr) ring_write((ring_base), (ring_size), (ring_pos), (ptr), sizeof(*(ptr)))
#define ring_read_struct(ring_base, ring_size, ring_pos, ptr) ring_read((ring_base), (ring_size), (ring_pos), (ptr), sizeof(*(ptr)))
#define ring_read_struct(ring_base, ring_size, ring_pos, ptr) ring_read ((ring_base), (ring_size), (ring_pos), (ptr), sizeof(*(ptr)))
////////////////////////////////
//~ rjf: Non-Fancy Ring Buffer Reads/Writes
inline U64
ring_write(U8* ring_base, U64 ring_size, U64 ring_pos, void* src_data, U64 src_data_size) {
assert(src_data_size <= ring_size);
{
U64 ring_off = ring_pos % ring_size;
U64 bytes_before_split = ring_size - ring_off;
U64 pre_split_bytes = min(bytes_before_split, src_data_size);
U64 pst_split_bytes = src_data_size - pre_split_bytes;
void* pre_split_data = src_data;
void* pst_split_data = ((U8*)src_data + pre_split_bytes);
memory_copy(ring_base + ring_off, pre_split_data, pre_split_bytes);
memory_copy(ring_base + 0, pst_split_data, pst_split_bytes);
}
return src_data_size;
}
inline U64
ring_read(U8* ring_base, U64 ring_size, U64 ring_pos, void* dst_data, U64 read_size) {
assert(read_size <= ring_size);
{
U64 ring_off = ring_pos % ring_size;
U64 bytes_before_split = ring_size-ring_off;
U64 pre_split_bytes = min(bytes_before_split, read_size);
U64 pst_split_bytes = read_size - pre_split_bytes;
memory_copy(dst_data, ring_base+ring_off, pre_split_bytes);
memory_copy((U8*)dst_data + pre_split_bytes, ring_base + 0, pst_split_bytes);
}
return read_size;
}
+5 -3
View File
@@ -1,8 +1,10 @@
#ifdef INTELLISENSE_DIRECTIVES
# include "platform.h"
#endif
////////////////////////////////
//~ rjf: Sorts
#ifndef quick_sort
#define quick_sort(ptr, count, element_size, cmp_function) qsort((ptr), (count), (element_size), (int (*)(const void *, const void *))(cmp_function))
#endif
+4 -4
View File
@@ -197,10 +197,10 @@ push_str8fv(Arena* arena, char* fmt, va_list args){
#if MD_DONT_MAP_ARENA_TO_ALLOCATOR_IMPL
va_list args2;
va_copy(args2, args);
U32 needed_bytes = raddbg_vsnprintf(0, 0, fmt, args) + 1;
U32 needed_bytes = md_vsnprintf(0, 0, fmt, args) + 1;
String8 result = {0};
result.str = push_array_no_zero(arena, U8, needed_bytes);
result.size = raddbg_vsnprintf((char*)result.str, needed_bytes, fmt, args2);
result.size = md_vsnprintf((char*)result.str, needed_bytes, fmt, args2);
result.str[result.size] = 0;
va_end(args2);
return(result);
@@ -236,10 +236,10 @@ 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;
U32 needed_bytes = md_vsnprintf(0, 0, fmt, args) + 1;
String8 result = {0};
result.str = alloc_array_no_zero(ainfo, U8, needed_bytes);
result.size = raddbg_vsnprintf((char*)result.str, needed_bytes, fmt, args2);
result.size = md_vsnprintf((char*)result.str, needed_bytes, fmt, args2);
result.str[result.size] = 0;
va_end(args2);
return(result);
+1 -1
View File
@@ -19,7 +19,7 @@
////////////////////////////////
//~ rjf: Third Party Includes
#define STB_SPRINTF_DECORATE(name) raddbg_##name
#define STB_SPRINTF_DECORATE(name) md_##name
#include "third_party/stb/stb_sprintf.h"
////////////////////////////////
+58
View File
@@ -0,0 +1,58 @@
#ifdef INTELLISENSE_DIRECTIVES
# include "debug.h"
# include "time.h"
#endif
DateTime
date_time_from_unix_time(U64 unix_time)
{
DateTime date = {0};
date.year = 1970;
date.day = 1 + (unix_time / 86400);
date.sec = (U32) unix_time % 60;
date.min = (U32)(unix_time / 60) % 60;
date.hour = (U32)(unix_time / 3600) % 24;
for(;;)
{
for(date.month = 0; date.month < 12; ++date.month)
{
U64 c = 0;
switch(date.month)
{
case Month_Jan: c = 31; break;
case Month_Feb:
{
if((date.year % 4 == 0) && ((date.year % 100) != 0 || (date.year % 400) == 0))
{
c = 29;
}
else
{
c = 28;
}
} break;
case Month_Mar: c = 31; break;
case Month_Apr: c = 30; break;
case Month_May: c = 31; break;
case Month_Jun: c = 30; break;
case Month_Jul: c = 31; break;
case Month_Aug: c = 31; break;
case Month_Sep: c = 30; break;
case Month_Oct: c = 31; break;
case Month_Nov: c = 30; break;
case Month_Dec: c = 31; break;
default: invalid_path;
}
if(date.day <= c)
{
goto exit;
}
date.day -= c;
}
++date.year;
}
exit:;
return date;
}
+87 -42
View File
@@ -8,55 +8,55 @@
typedef enum WeekDay
{
WeekDay_Sun,
WeekDay_Mon,
WeekDay_Tue,
WeekDay_Wed,
WeekDay_Thu,
WeekDay_Fri,
WeekDay_Sat,
WeekDay_COUNT,
WeekDay_Sun,
WeekDay_Mon,
WeekDay_Tue,
WeekDay_Wed,
WeekDay_Thu,
WeekDay_Fri,
WeekDay_Sat,
WeekDay_COUNT,
}
WeekDay;
typedef enum Month
{
Month_Jan,
Month_Feb,
Month_Mar,
Month_Apr,
Month_May,
Month_Jun,
Month_Jul,
Month_Aug,
Month_Sep,
Month_Oct,
Month_Nov,
Month_Dec,
Month_COUNT,
Month_Jan,
Month_Feb,
Month_Mar,
Month_Apr,
Month_May,
Month_Jun,
Month_Jul,
Month_Aug,
Month_Sep,
Month_Oct,
Month_Nov,
Month_Dec,
Month_COUNT,
}
Month;
typedef struct DateTime DateTime;
struct DateTime
{
U16 micro_sec; // [0,999]
U16 msec; // [0,999]
U16 sec; // [0,60]
U16 min; // [0,59]
U16 hour; // [0,24]
U16 day; // [0,30]
union
{
WeekDay week_day;
U32 wday;
};
union
{
Month month;
U32 mon;
};
U32 year; // 1 = 1 CE, 0 = 1 BC
U16 micro_sec; // [0,999]
U16 msec; // [0,999]
U16 sec; // [0,60]
U16 min; // [0,59]
U16 hour; // [0,24]
U16 day; // [0,30]
union
{
WeekDay week_day;
U32 wday;
};
union
{
Month month;
U32 mon;
};
U32 year; // 1 = 1 CE, 0 = 1 BC
};
typedef U64 DenseTime;
@@ -64,7 +64,52 @@ typedef U64 DenseTime;
////////////////////////////////
//~ rjf: Time Functions
internal DenseTime dense_time_from_date_time(DateTime date_time);
internal DateTime date_time_from_dense_time(DenseTime time);
internal DateTime date_time_from_micro_seconds(U64 time);
internal DateTime date_time_from_unix_time(U64 unix_time);
DenseTime dense_time_from_date_time (DateTime date_time);
DateTime date_time_from_dense_time (DenseTime time);
DateTime date_time_from_micro_seconds(U64 time);
DateTime date_time_from_unix_time (U64 unix_time);
////////////////////////////////
//~ rjf: Time Functions
inline DenseTime
dense_time_from_date_time(DateTime date_time) {
DenseTime result = 0;
result += date_time.year; result *= 12;
result += date_time.mon; result *= 31;
result += date_time.day; result *= 24;
result += date_time.hour; result *= 60;
result += date_time.min; result *= 61;
result += date_time.sec; result *= 1000;
result += date_time.msec;
return(result);
}
inline DateTime
date_time_from_dense_time(DenseTime time) {
DateTime result = {0};
result.msec = time % 1000; time /= 1000;
result.sec = time % 61; time /= 61;
result.min = time % 60; time /= 60;
result.hour = time % 24; time /= 24;
result.day = time % 31; time /= 31;
result.mon = time % 12; time /= 12;
assert(time <= MAX_U32);
result.year = (U32)time;
return(result);
}
inline DateTime
date_time_from_micro_seconds(U64 time){
DateTime result = {0};
result.micro_sec = time % 1000; time /= 1000;
result.msec = time % 1000; time /= 1000;
result.sec = time % 60; time /= 60;
result.min = time % 60; time /= 60;
result.hour = time % 24; time /= 24;
result.day = time % 31; time /= 31;
result.mon = time % 12; time /= 12;
assert(time <= MAX_U32);
result.year = (U32)time;
return(result);
}
+3 -35
View File
@@ -1,41 +1,9 @@
#ifdef INTELLISENSE_DIRECTIVES
#pragma once
# pragma once
#endif
// metadesk header: intended for "As-Is" library usage
// base
#include "base/context_cracking.h"
#include "base/platform.h"
#include "base/linkage.h"
#include "base/macros.h"
#include "base/generic_macros.h"
#include "base/profiling.h"
#include "base/namespace.h"
MD_NS_BEGIN
#include "base/base_types.h"
#include "base/debug.h"
#include "base/memory.h"
#include "base/memory_substrate.h"
#include "base/arena.h"
#include "base/space.h"
#include "base/math.h"
#include "base/toolchain.h"
#include "base/strings.h"
#include "base/thread_context.h"
#include "base/command_line.h"
#include "base/markup.h"
#include "base/logger.h"
#include "base/entry_point.h"
MD_NS_END
#include "base/base.h"
#include "os/os.h"
// mdesk
// metagen