metaprogram bootstrapping
This commit is contained in:
parent
c306b2435d
commit
cc0896cd93
65
build.bat
65
build.bat
@ -4,54 +4,29 @@ cd /D "%~dp0"
|
||||
if not exist build mkdir build
|
||||
pushd build
|
||||
|
||||
::::::::::::::::::::::::::::::::
|
||||
::~ Unpack args
|
||||
set program_build_cmd=meta.exe %*
|
||||
set meta_build_cmd=cl.exe ../src/meta/meta.c /Od /Z7 /nologo /link /DEBUG:FULL /INCREMENTAL:NO
|
||||
set meta_rebuild_code=995692758
|
||||
|
||||
for %%a in (%*) do set "%%a=1"
|
||||
|
||||
if "%~1" == "" (
|
||||
echo [No arguments provided, assuming default `pp` build]
|
||||
set meta=1
|
||||
set pp=1
|
||||
)
|
||||
|
||||
if "%~1" == "release" if "%~2" == "" (
|
||||
echo [No arguments provided, assuming default 'pp' build]
|
||||
set meta=1
|
||||
set pp=1
|
||||
)
|
||||
|
||||
if not "%release%" == "1" set debug=1
|
||||
|
||||
if "%release%" == "1" echo [Release]
|
||||
if "%debug%" == "1" echo [Debug]
|
||||
|
||||
::::::::::::::::::::::::::::::::
|
||||
::~ Build meta program
|
||||
|
||||
if "%meta%" == "1" (
|
||||
echo [Building meta]
|
||||
|
||||
"cl" ../src/meta/meta.c /Od /Z7 /nologo /link /DEBUG:FULL /INCREMENTAL:NO
|
||||
|
||||
if not "!errorlevel!" == "0" (
|
||||
echo .
|
||||
echo Failed to build meta program
|
||||
exit /b 1
|
||||
::- Meta build
|
||||
:meta_build
|
||||
if not exist meta.exe (
|
||||
echo [Meta build]
|
||||
%meta_build_cmd%
|
||||
set "rc=!errorlevel!"
|
||||
if !rc! NEQ 0 (
|
||||
exit /b !rc!
|
||||
)
|
||||
)
|
||||
|
||||
::::::::::::::::::::::::::::::::
|
||||
::~ Build power play
|
||||
|
||||
if "%pp%" == "1" (
|
||||
echo [Building power play]
|
||||
|
||||
"meta.exe" pp
|
||||
|
||||
if not "!errorlevel!" == "0" (
|
||||
echo.
|
||||
echo Failed to run meta program
|
||||
exit /b 1
|
||||
::- Program build
|
||||
echo [Build]
|
||||
%program_build_cmd%
|
||||
set "rc=!errorlevel!"
|
||||
if !rc! NEQ 0 (
|
||||
if !rc! EQU %meta_rebuild_code% (
|
||||
del meta.exe
|
||||
goto meta_build
|
||||
)
|
||||
exit /b !rc!
|
||||
)
|
||||
|
||||
@ -2,7 +2,6 @@
|
||||
//~ Conversion helpers
|
||||
|
||||
//- Char conversion
|
||||
|
||||
String StringFromChar(Arena *arena, char c)
|
||||
{
|
||||
u8 *dst = PushStructNoZero(arena, u8);
|
||||
@ -15,7 +14,6 @@ String StringFromChar(Arena *arena, char c)
|
||||
}
|
||||
|
||||
//- Unsigned int conversion
|
||||
|
||||
String StringFromU64(Arena *arena, u64 n, u64 base, u64 zfill)
|
||||
{
|
||||
/* Base too large */
|
||||
@ -56,7 +54,6 @@ String StringFromU64(Arena *arena, u64 n, u64 base, u64 zfill)
|
||||
}
|
||||
|
||||
//- Signed int conversion
|
||||
|
||||
String StringFromI64(Arena *arena, i64 n, u64 base, u64 zfill)
|
||||
{
|
||||
u8 *final_text = PushDry(arena, u8);
|
||||
@ -78,7 +75,6 @@ String StringFromI64(Arena *arena, i64 n, u64 base, u64 zfill)
|
||||
}
|
||||
|
||||
//- Pointer conversion
|
||||
|
||||
String StringFromPtr(Arena *arena, void *ptr)
|
||||
{
|
||||
String prepend = PushString(arena, Lit("0x"));
|
||||
@ -91,24 +87,23 @@ String StringFromPtr(Arena *arena, void *ptr)
|
||||
}
|
||||
|
||||
//- Floating point conversion
|
||||
|
||||
String StringFromF64(Arena *arena, f64 f, u32 precision)
|
||||
{
|
||||
TempArena scratch = BeginScratch(arena);
|
||||
u8 *final_text = PushDry(arena, u8);
|
||||
u64 final_len = 0;
|
||||
String result = ZI;
|
||||
result.text = PushDry(arena, u8);
|
||||
|
||||
if (IsF32Nan(f))
|
||||
{
|
||||
final_len += PushString(arena, Lit("NaN")).len;
|
||||
result.len += PushString(arena, Lit("NaN")).len;
|
||||
}
|
||||
else if (f == F64Infinity)
|
||||
{
|
||||
final_len += PushString(arena, Lit("inf")).len;
|
||||
result.len += PushString(arena, Lit("inf")).len;
|
||||
}
|
||||
else if (f == -F64Infinity)
|
||||
{
|
||||
final_len += PushString(arena, Lit("-inf")).len;
|
||||
result.len += PushString(arena, Lit("-inf")).len;
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -116,7 +111,7 @@ String StringFromF64(Arena *arena, f64 f, u32 precision)
|
||||
{
|
||||
StringFromChar(arena, '-');
|
||||
f = -f;
|
||||
++final_len;
|
||||
++result.len;
|
||||
}
|
||||
|
||||
/* Add one half of next precision level to round up */
|
||||
@ -142,7 +137,7 @@ String StringFromF64(Arena *arena, f64 f, u32 precision)
|
||||
PushStructsNoZero(arena, u8, backwards_text_len);
|
||||
for (u64 i = backwards_text_len; i-- > 0;)
|
||||
{
|
||||
final_text[final_len++] = backwards_text[i];
|
||||
result.text[result.len++] = backwards_text[i];
|
||||
}
|
||||
}
|
||||
|
||||
@ -157,19 +152,36 @@ String StringFromF64(Arena *arena, f64 f, u32 precision)
|
||||
part_decimal -= digit;
|
||||
StringFromChar(arena, IntChars[digit % 10]);
|
||||
}
|
||||
final_len += (u64)precision + 1;
|
||||
result.len += (u64)precision + 1;
|
||||
}
|
||||
}
|
||||
|
||||
EndScratch(scratch);
|
||||
|
||||
return (String)
|
||||
{
|
||||
.len = final_len,
|
||||
.text = final_text
|
||||
};
|
||||
return result;
|
||||
}
|
||||
|
||||
//- Handle conversion
|
||||
String StringFromhandle(Arena *arena, u64 v0, u64 v1)
|
||||
{
|
||||
String result = ZI;
|
||||
result.text = PushDry(arena, u8);
|
||||
result.len += PushString(arena, Lit("h")).len;
|
||||
result.len += StringFromU64(arena, v0, 16, 0).len;
|
||||
result.len += PushString(arena, Lit("x")).len;
|
||||
result.len += StringFromU64(arena, v1, 16, 0).len;
|
||||
return result;
|
||||
}
|
||||
|
||||
//- Uid conversion
|
||||
String StringFromUid(Arena *arena, Uid uid)
|
||||
{
|
||||
String result = ZI;
|
||||
result.text = PushDry(arena, u8);
|
||||
result.len += StringFromU64(arena, (uid.hi >> 32), 16, 8).len;
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////
|
||||
//~ String helpers
|
||||
|
||||
@ -345,31 +357,6 @@ b32 EqString(String str1, String str2)
|
||||
return eq;
|
||||
}
|
||||
|
||||
i32 CmpString(String str1, String str2)
|
||||
{
|
||||
i32 result = 0;
|
||||
for (u64 i = 0; i < MinU64(str1.len, str2.len); ++i)
|
||||
{
|
||||
result = str1.text[i] - str2.text[i];
|
||||
if (result != 0)
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (result == 0)
|
||||
{
|
||||
if (str1.len > str2.len)
|
||||
{
|
||||
result = str1.text[str2.len];
|
||||
}
|
||||
else if (str2.len > str1.len)
|
||||
{
|
||||
result = str2.text[str1.len];
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
//- Match
|
||||
|
||||
b32 StringContains(String str, String substring)
|
||||
@ -591,6 +578,16 @@ String StringFormatV(Arena *arena, String fmt, va_list args)
|
||||
parsed_str = StringFromF64(arena, arg.value.f, arg.precision);
|
||||
} break;
|
||||
|
||||
case FmtKind_Handle:
|
||||
{
|
||||
parsed_str = StringFromhandle(arena, arg.value.handle.h64[0], arg.value.handle.h64[1]);
|
||||
} break;
|
||||
|
||||
case FmtKind_Uid:
|
||||
{
|
||||
parsed_str = StringFromUid(arena, arg.value.uid);
|
||||
} break;
|
||||
|
||||
case FmtKind_End:
|
||||
{
|
||||
/* Unexpected end. Not enough FMT args passed to function. */
|
||||
@ -636,7 +633,7 @@ String StringFormatV(Arena *arena, String fmt, va_list args)
|
||||
};
|
||||
}
|
||||
|
||||
String _StringFormat(Arena *arena, String fmt, ...)
|
||||
String StringFormat_(Arena *arena, String fmt, ...)
|
||||
{
|
||||
va_list args;
|
||||
va_start(args, fmt);
|
||||
|
||||
@ -86,6 +86,8 @@ String StringFromU64(Arena *arena, u64 n, u64 base, u64 zfill);
|
||||
String StringFromI64(Arena *arena, i64 n, u64 base, u64 zfill);
|
||||
String StringFromPtr(Arena *arena, void *ptr);
|
||||
String StringFromF64(Arena *arena, f64 f, u32 precision);
|
||||
String StringFromhandle(Arena *arena, u64 v0, u64 v1);
|
||||
String StringFromUid(Arena *arena, Uid uid);
|
||||
|
||||
////////////////////////////////
|
||||
//~ String helpers
|
||||
@ -98,7 +100,6 @@ StringArray SplitString(Arena *arena, String str, String delim);
|
||||
String IndentString(Arena *arena, String str, u32 indent);
|
||||
String LowerString(Arena *arena, String str);
|
||||
b32 EqString(String str1, String str2);
|
||||
i32 CmpString(String str1, String str2);
|
||||
b32 StringContains(String str, String substring);
|
||||
b32 StringStartsWith(String str, String substring);
|
||||
b32 StringEndsWith(String str, String substring);
|
||||
@ -134,9 +135,9 @@ String StringFromList(Arena *arena, StringList l, String separator);
|
||||
#define FmtEnd (FmtArg) {.kind = FmtKind_End}
|
||||
|
||||
//- Format functions
|
||||
#define StringF(arena, lit, ...) _StringFormat((arena), Lit(lit), __VA_ARGS__, FmtEnd)
|
||||
#define StringFormat(arena, fmt, ...) _StringFormat((arena), (fmt), __VA_ARGS__, FmtEnd)
|
||||
String _StringFormat(Arena *arena, String fmt, ...);
|
||||
#define StringF(arena, lit, ...) StringFormat_((arena), Lit(lit), __VA_ARGS__, FmtEnd)
|
||||
#define StringFormat(arena, fmt, ...) StringFormat_((arena), (fmt), __VA_ARGS__, FmtEnd)
|
||||
String StringFormat_(Arena *arena, String fmt, ...);
|
||||
String StringFormatV(Arena *arena, String fmt, va_list args);
|
||||
|
||||
////////////////////////////////
|
||||
|
||||
@ -1,11 +1,5 @@
|
||||
W32_SharedState W32_shared_state = ZI;
|
||||
|
||||
////////////////////////////////
|
||||
//~ Windows libs
|
||||
|
||||
#pragma comment(lib, "kernel32")
|
||||
#pragma comment(lib, "user32")
|
||||
|
||||
////////////////////////////////
|
||||
//~ @hookdef OS startup hook
|
||||
|
||||
@ -58,18 +52,8 @@ i16 ThreadId(void)
|
||||
|
||||
////////////////////////////////
|
||||
//~ @hookdef Randomness hooks
|
||||
////////////////////////////////
|
||||
//~ True randomness
|
||||
|
||||
#if PlatformIsWindows
|
||||
#if 0
|
||||
# define BCRYPT_RNG_ALG_HANDLE ((void *)0x00000081)
|
||||
u32 BCryptGenRandom(void *algorithm, u8 *buffer, u32 buffer_size, u32 flags);
|
||||
#endif
|
||||
void TrueRand(String buffer)
|
||||
{
|
||||
BCryptGenRandom(BCRYPT_RNG_ALG_HANDLE, (u8 *)buffer.text, buffer.len, 0);
|
||||
}
|
||||
#else
|
||||
# error TrueRand not implemented for this platform
|
||||
#endif
|
||||
|
||||
@ -1,3 +1,15 @@
|
||||
////////////////////////////////
|
||||
//~ Win32 libs
|
||||
|
||||
#ifndef BCRYPT_RNG_ALG_HANDLE
|
||||
#define BCRYPT_RNG_ALG_HANDLE ((void *)0x00000081)
|
||||
u32 BCryptGenRandom(void *algorithm, u8 *buffer, u32 buffer_size, u32 flags);
|
||||
#endif
|
||||
|
||||
#pragma comment(lib, "kernel32")
|
||||
#pragma comment(lib, "user32")
|
||||
#pragma comment(lib, "bcrypt")
|
||||
|
||||
////////////////////////////////
|
||||
//~ Shared state
|
||||
|
||||
|
||||
@ -1,19 +1,5 @@
|
||||
W32_SharedJobCtx W32_shared_job_ctx = ZI;
|
||||
|
||||
////////////////////////////////
|
||||
//~ Win32 libs
|
||||
|
||||
#pragma comment(lib, "kernel32")
|
||||
#pragma comment(lib, "user32")
|
||||
#pragma comment(lib, "shell32")
|
||||
#pragma comment(lib, "ole32")
|
||||
#pragma comment(lib, "winmm")
|
||||
#pragma comment(lib, "dwmapi")
|
||||
#pragma comment(lib, "bcrypt")
|
||||
#pragma comment(lib, "synchronization")
|
||||
#pragma comment(lib, "avrt")
|
||||
#pragma comment(lib, "ws2_32.lib")
|
||||
|
||||
////////////////////////////////
|
||||
//~ @hookdef Startup
|
||||
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
////////////////////////////////
|
||||
//~ Win32 headers
|
||||
//~ Win32 libs
|
||||
|
||||
#pragma warning(push, 0)
|
||||
# include <WinSock2.h>
|
||||
@ -9,11 +9,20 @@
|
||||
# include <ShlObj_core.h>
|
||||
# include <fileapi.h>
|
||||
# include <dwmapi.h>
|
||||
# include <bcrypt.h>
|
||||
# include <avrt.h>
|
||||
# include <shellapi.h>
|
||||
#pragma warning(pop)
|
||||
|
||||
#pragma comment(lib, "kernel32")
|
||||
#pragma comment(lib, "user32")
|
||||
#pragma comment(lib, "shell32")
|
||||
#pragma comment(lib, "ole32")
|
||||
#pragma comment(lib, "winmm")
|
||||
#pragma comment(lib, "dwmapi")
|
||||
#pragma comment(lib, "synchronization")
|
||||
#pragma comment(lib, "avrt")
|
||||
#pragma comment(lib, "ws2_32.lib")
|
||||
|
||||
////////////////////////////////
|
||||
//~ Thread types
|
||||
|
||||
|
||||
@ -12,20 +12,22 @@ Struct(GPU_Swapchain);
|
||||
//~ Queue types
|
||||
|
||||
#define GPU_MultiQueueEnabled !ProfilingIsEnabled
|
||||
typedef i32 GPU_QueueKind;
|
||||
Enum(GPU_QueueKind)
|
||||
{
|
||||
#if GPU_MultiQueueEnabled
|
||||
# define GPU_QueueKind_Direct 0
|
||||
# define GPU_QueueKind_Compute 1
|
||||
# define GPU_QueueKind_Copy 2
|
||||
# define GPU_QueueKind_BackgroundCopy 3
|
||||
# define GPU_NumQueues 4
|
||||
GPU_QueueKind_Direct = 0,
|
||||
GPU_QueueKind_Compute = 1,
|
||||
GPU_QueueKind_Copy = 2,
|
||||
GPU_QueueKind_BackgroundCopy = 3,
|
||||
GPU_NumQueues = 4
|
||||
#else
|
||||
# define GPU_QueueKind_Direct 0
|
||||
# define GPU_QueueKind_Compute 0
|
||||
# define GPU_QueueKind_Copy 0
|
||||
# define GPU_QueueKind_BackgroundCopy 0
|
||||
# define GPU_NumQueues 1
|
||||
GPU_QueueKind_Direct = 0,
|
||||
GPU_QueueKind_Compute = 0,
|
||||
GPU_QueueKind_Copy = 0,
|
||||
GPU_QueueKind_BackgroundCopy = 0,
|
||||
GPU_NumQueues = 1
|
||||
#endif
|
||||
};
|
||||
|
||||
////////////////////////////////
|
||||
//~ Format types
|
||||
|
||||
@ -1,5 +1,7 @@
|
||||
/* TODO: Move decls to meta.h */
|
||||
|
||||
#define MetaRebuildCode 0x3b5910d6
|
||||
|
||||
////////////////////////////////
|
||||
//~ Metaprogram default compiler definitions
|
||||
|
||||
@ -732,69 +734,70 @@ Error *PushError(Arena *arena, ErrorList *list, String file, i64 pos, String s)
|
||||
return e;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
////////////////////////////////
|
||||
//~ Entry point
|
||||
|
||||
i32 main(i32 argc, u8 **argv)
|
||||
{
|
||||
i32 ret = 0;
|
||||
|
||||
//- Startup
|
||||
StartupBase();
|
||||
OS_Startup();
|
||||
Arena *arena = AcquireArena(Gibi(64));
|
||||
|
||||
i32 ret = 0;
|
||||
ErrorList errors = ZI;
|
||||
|
||||
//- Unpack args
|
||||
StringList starting_layer_names = ZI;
|
||||
StringList args = ZI;
|
||||
i32 hyphens = 0;
|
||||
for (i32 i = 1; i < argc; ++i)
|
||||
{
|
||||
String arg = StringFromCstrNoLimit(argv[i]);
|
||||
if (EqString(arg, Lit("-")))
|
||||
{
|
||||
++hyphens;
|
||||
}
|
||||
else
|
||||
|
||||
//- Return if metaprogram is dirty
|
||||
{
|
||||
if (hyphens == 0)
|
||||
/* Read old metahash */
|
||||
u64 old_metahash = 0;
|
||||
if (F_IsFile(Lit("metahash.dat")))
|
||||
{
|
||||
PushStringToList(arena, &starting_layer_names, arg);
|
||||
String hashes_str = F_DataFromFile(arena, Lit("metahash.dat"));
|
||||
if (hashes_str.len == sizeof(old_metahash))
|
||||
{
|
||||
CopyBytes(&old_metahash, hashes_str.text, sizeof(old_metahash));
|
||||
}
|
||||
else
|
||||
{
|
||||
PushStringToList(arena, &args, arg);
|
||||
OS_Rm(Lit("metahash.dat"));
|
||||
}
|
||||
|
||||
/* Calculate new metahash */
|
||||
u64 new_metahash = 0;
|
||||
{
|
||||
StringList check_files = ZI;
|
||||
F_FilesFromDir(arena, &check_files, Lit("../src/meta"), F_IterFlag_Recurse);
|
||||
F_FilesFromDir(arena, &check_files, Lit("../src/prof"), F_IterFlag_Recurse);
|
||||
PushStringToList(arena, &check_files, Lit("../src/config.h"));
|
||||
for (StringListNode *n = check_files.first; n; n = n->next)
|
||||
{
|
||||
String file = n->s;
|
||||
new_metahash = RandU64FromSeeds(HashFnv64(new_metahash, file), OS_LastWriteTimestampFromPath(file));
|
||||
}
|
||||
}
|
||||
|
||||
ErrorList errors = ZI;
|
||||
/* Exit if metaprogram needs recompilation */
|
||||
if (old_metahash == 0 || old_metahash == new_metahash)
|
||||
{
|
||||
F_ClearWrite(Lit("metahash.dat"), StringFromStruct(&new_metahash));
|
||||
}
|
||||
else
|
||||
{
|
||||
Echo(Lit("Metaprogram is dirty"));
|
||||
return MetaRebuildCode;
|
||||
}
|
||||
}
|
||||
|
||||
//- Extract layer topography
|
||||
StringList src_dirs = ZI;
|
||||
StringList starting_layer_names = ZI;
|
||||
PushStringToList(arena, &src_dirs, Lit("../src"));
|
||||
PushStringToList(arena, &starting_layer_names, Lit("pp"));
|
||||
L_Topo topo = L_TopoFromLayerName(arena, starting_layer_names, src_dirs);
|
||||
|
||||
//- Process topo errors
|
||||
|
||||
@ -4,6 +4,7 @@
|
||||
#include "meta_base_memory.h"
|
||||
#include "meta_base_arena.h"
|
||||
#include "meta_base_math.h"
|
||||
#include "meta_base_rand.h"
|
||||
#include "meta_base_uni.h"
|
||||
#include "meta_base_string.h"
|
||||
#include "meta_base_util.h"
|
||||
@ -14,6 +15,7 @@
|
||||
#include "meta_base_memory.c"
|
||||
#include "meta_base_string.c"
|
||||
#include "meta_base_uni.c"
|
||||
#include "meta_base_rand.c"
|
||||
|
||||
//- Win32
|
||||
#if PlatformIsWindows
|
||||
|
||||
43
src/meta/meta_base/meta_base_rand.c
Normal file
43
src/meta/meta_base/meta_base_rand.c
Normal file
@ -0,0 +1,43 @@
|
||||
////////////////////////////////
|
||||
//~ Stateful randomness
|
||||
|
||||
u64 RandU64FromState(RandState *state)
|
||||
{
|
||||
u64 seed = state->seed;
|
||||
if (seed == 0)
|
||||
{
|
||||
TrueRand(StringFromStruct(&seed));
|
||||
state->seed = seed;
|
||||
}
|
||||
return seed ^ RandU64FromSeed(++state->counter);
|
||||
}
|
||||
|
||||
f64 RandF64FromState(RandState *state, f64 range_start, f64 range_end)
|
||||
{
|
||||
return range_start + (range_end - range_start) * ((f64)(RandU64FromState(state) % RandMaxF64) / (f64)RandMaxF64);
|
||||
}
|
||||
|
||||
////////////////////////////////
|
||||
//~ Seeded randomness
|
||||
|
||||
/* Based on Jon Maiga's "mx3"
|
||||
* https://jonkagstrom.com/mx3/mx3_rev2.html
|
||||
*/
|
||||
u64 RandU64FromSeed(u64 seed)
|
||||
{
|
||||
seed = (seed ^ (seed >> 32)) * 0xbea225f9eb34556d;
|
||||
seed = (seed ^ (seed >> 29)) * 0xbea225f9eb34556d;
|
||||
seed = (seed ^ (seed >> 32)) * 0xbea225f9eb34556d;
|
||||
seed = (seed ^ (seed >> 29));
|
||||
return seed;
|
||||
}
|
||||
|
||||
u64 RandU64FromSeeds(u64 seed_a, u64 seed_b)
|
||||
{
|
||||
return RandU64FromSeed((seed_a * 3) + seed_b);
|
||||
}
|
||||
|
||||
f64 RandF64FromSeed(u64 seed, f64 range_start, f64 range_end)
|
||||
{
|
||||
return range_start + (range_end - range_start) * ((f64)(RandU64FromSeed(seed) % RandMaxF64) / (f64)RandMaxF64);
|
||||
}
|
||||
23
src/meta/meta_base/meta_base_rand.h
Normal file
23
src/meta/meta_base/meta_base_rand.h
Normal file
@ -0,0 +1,23 @@
|
||||
////////////////////////////////
|
||||
//~ Rand types
|
||||
|
||||
Struct(RandState)
|
||||
{
|
||||
u64 seed; /* If a state's seed == 0 upon a call to a related function, it will be initialized using platform's true rng source */
|
||||
u64 counter;
|
||||
};
|
||||
|
||||
/* TODO: Use a value that gives good precision when dividing into range 0 -> 1 */
|
||||
#define RandMaxF64 U64Max
|
||||
|
||||
////////////////////////////////
|
||||
//~ Rand operations
|
||||
|
||||
//- Stateful randomness
|
||||
u64 RandU64FromState(RandState *state);
|
||||
f64 RandF64FromState(RandState *state, f64 range_start, f64 range_end);
|
||||
|
||||
//- Seeded randomness
|
||||
u64 RandU64FromSeed(u64 seed);
|
||||
u64 RandU64FromSeeds(u64 seed_a, u64 seed_b);
|
||||
f64 RandF64FromSeed(u64 seed, f64 range_start, f64 range_end);
|
||||
@ -345,31 +345,6 @@ b32 EqString(String str1, String str2)
|
||||
return eq;
|
||||
}
|
||||
|
||||
i32 CmpString(String str1, String str2)
|
||||
{
|
||||
i32 result = 0;
|
||||
for (u64 i = 0; i < MinU64(str1.len, str2.len); ++i)
|
||||
{
|
||||
result = str1.text[i] - str2.text[i];
|
||||
if (result != 0)
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (result == 0)
|
||||
{
|
||||
if (str1.len > str2.len)
|
||||
{
|
||||
result = str1.text[str2.len];
|
||||
}
|
||||
else if (str2.len > str1.len)
|
||||
{
|
||||
result = str2.text[str1.len];
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
//- Match
|
||||
|
||||
b32 StringContains(String str, String substring)
|
||||
@ -636,7 +611,7 @@ String StringFormatV(Arena *arena, String fmt, va_list args)
|
||||
};
|
||||
}
|
||||
|
||||
String _StringFormat(Arena *arena, String fmt, ...)
|
||||
String StringFormat_(Arena *arena, String fmt, ...)
|
||||
{
|
||||
va_list args;
|
||||
va_start(args, fmt);
|
||||
|
||||
@ -91,7 +91,6 @@ StringArray SplitString(Arena *arena, String str, String delim);
|
||||
String IndentString(Arena *arena, String str, u32 indent);
|
||||
String LowerString(Arena *arena, String str);
|
||||
b32 EqString(String str1, String str2);
|
||||
i32 CmpString(String str1, String str2);
|
||||
b32 StringContains(String str, String substring);
|
||||
b32 StringStartsWith(String str, String substring);
|
||||
b32 StringEndsWith(String str, String substring);
|
||||
@ -127,9 +126,9 @@ String Trim(String s, String pattern);
|
||||
#define FmtEnd (FmtArg) {.kind = FmtKind_End}
|
||||
|
||||
//- Format functions
|
||||
#define StringF(arena, lit, ...) _StringFormat((arena), Lit(lit), __VA_ARGS__, FmtEnd)
|
||||
#define StringFormat(arena, fmt, ...) _StringFormat((arena), (fmt), __VA_ARGS__, FmtEnd)
|
||||
String _StringFormat(Arena *arena, String fmt, ...);
|
||||
#define StringF(arena, lit, ...) StringFormat_((arena), Lit(lit), __VA_ARGS__, FmtEnd)
|
||||
#define StringFormat(arena, fmt, ...) StringFormat_((arena), (fmt), __VA_ARGS__, FmtEnd)
|
||||
String StringFormat_(Arena *arena, String fmt, ...);
|
||||
String StringFormatV(Arena *arena, String fmt, va_list args);
|
||||
|
||||
////////////////////////////////
|
||||
|
||||
@ -1,11 +1,5 @@
|
||||
W32_SharedState W32_shared_state = ZI;
|
||||
|
||||
////////////////////////////////
|
||||
//~ Windows libs
|
||||
|
||||
#pragma comment(lib, "kernel32")
|
||||
#pragma comment(lib, "user32")
|
||||
|
||||
////////////////////////////////
|
||||
//~ @hookdef OS startup hook
|
||||
|
||||
@ -55,3 +49,11 @@ i16 ThreadId(void)
|
||||
W32_SharedState *g = &W32_shared_state;
|
||||
return (i16)(i64)TlsGetValue(g->tls_index);
|
||||
}
|
||||
|
||||
////////////////////////////////
|
||||
//~ @hookdef Randomness hooks
|
||||
|
||||
void TrueRand(String buffer)
|
||||
{
|
||||
BCryptGenRandom(BCRYPT_RNG_ALG_HANDLE, (u8 *)buffer.text, buffer.len, 0);
|
||||
}
|
||||
|
||||
@ -1,3 +1,15 @@
|
||||
////////////////////////////////
|
||||
//~ Win32 libs
|
||||
|
||||
#ifndef BCRYPT_RNG_ALG_HANDLE
|
||||
#define BCRYPT_RNG_ALG_HANDLE ((void *)0x00000081)
|
||||
u32 BCryptGenRandom(void *algorithm, u8 *buffer, u32 buffer_size, u32 flags);
|
||||
#endif
|
||||
|
||||
#pragma comment(lib, "kernel32")
|
||||
#pragma comment(lib, "user32")
|
||||
#pragma comment(lib, "bcrypt")
|
||||
|
||||
////////////////////////////////
|
||||
//~ Shared state
|
||||
|
||||
|
||||
@ -38,14 +38,17 @@ String OS_ReadEntireFile(Arena *arena, OS_File file);
|
||||
void OS_ClearWriteFile(OS_File file, String data);
|
||||
void OS_DirContentsFromFullPath(Arena *arena, StringList *list, String path);
|
||||
String OS_GetFullPath(Arena *arena, String path);
|
||||
b32 OS_FileOrDirExists(String path);
|
||||
b32 OS_FileExists(String path);
|
||||
b32 OS_DirExists(String path);
|
||||
u64 OS_LastWriteTimestampFromPath(String path);
|
||||
|
||||
////////////////////////////////
|
||||
//~ @hookdecl Directory helpers
|
||||
|
||||
b32 OS_FileOrDirExists(String path);
|
||||
b32 OS_FileExists(String path);
|
||||
b32 OS_DirExists(String path);
|
||||
void OS_Mkdir(String path);
|
||||
void OS_RmDir(String path);
|
||||
void OS_Rm(String path);
|
||||
|
||||
////////////////////////////////
|
||||
//~ @hookdecl Shell operations
|
||||
|
||||
@ -1,9 +1,3 @@
|
||||
////////////////////////////////
|
||||
//~ Windows libs
|
||||
|
||||
#pragma comment(lib, "kernel32")
|
||||
#pragma comment(lib, "user32")
|
||||
|
||||
////////////////////////////////
|
||||
//~ @hookdef Startup hook
|
||||
|
||||
@ -118,16 +112,23 @@ String OS_GetFullPath(Arena *arena, String path)
|
||||
return res;
|
||||
}
|
||||
|
||||
////////////////////////////////
|
||||
//~ @hookdef Directory helper hooks
|
||||
|
||||
void OS_Mkdir(String path)
|
||||
u64 OS_LastWriteTimestampFromPath(String path)
|
||||
{
|
||||
TempArena scratch = BeginScratchNoConflict();
|
||||
u64 result = 0;
|
||||
WIN32_FILE_ATTRIBUTE_DATA a = ZI;
|
||||
wchar_t *path_wstr = WstrFromString(scratch.arena, path);
|
||||
CreateDirectoryW(path_wstr, 0);
|
||||
EndScratch(scratch);
|
||||
if (GetFileAttributesExW(path_wstr, GetFileExInfoStandard, &a))
|
||||
{
|
||||
result = ((ULONGLONG)a.ftLastWriteTime.dwHighDateTime << 32) |
|
||||
(ULONGLONG)a.ftLastWriteTime.dwLowDateTime;
|
||||
}
|
||||
EndScratch(scratch);
|
||||
return result;
|
||||
}
|
||||
|
||||
////////////////////////////////
|
||||
//~ @hookdef Directory helper hooks
|
||||
|
||||
b32 OS_FileOrDirExists(String path)
|
||||
{
|
||||
@ -156,6 +157,29 @@ b32 OS_DirExists(String path)
|
||||
return attributes != INVALID_FILE_ATTRIBUTES && (attributes & FILE_ATTRIBUTE_DIRECTORY);
|
||||
}
|
||||
|
||||
void OS_Mkdir(String path)
|
||||
{
|
||||
TempArena scratch = BeginScratchNoConflict();
|
||||
wchar_t *path_wstr = WstrFromString(scratch.arena, path);
|
||||
CreateDirectoryW(path_wstr, 0);
|
||||
EndScratch(scratch);
|
||||
}
|
||||
|
||||
void OS_RmDir(String dir)
|
||||
{
|
||||
TempArena scratch = BeginScratchNoConflict();
|
||||
wchar_t *path_wstr = WstrFromString(scratch.arena, dir);
|
||||
RemoveDirectory(path_wstr);
|
||||
EndScratch(scratch);
|
||||
}
|
||||
|
||||
void OS_Rm(String path)
|
||||
{
|
||||
TempArena scratch = BeginScratchNoConflict();
|
||||
wchar_t *path_wstr = WstrFromString(scratch.arena, path);
|
||||
DeleteFile(path_wstr);
|
||||
EndScratch(scratch);
|
||||
}
|
||||
|
||||
////////////////////////////////
|
||||
//~ @hookdef Shell hooks
|
||||
|
||||
@ -1 +1,7 @@
|
||||
#include <stdlib.h> /* _wfullpath */
|
||||
|
||||
////////////////////////////////
|
||||
//~ Win32 libs
|
||||
|
||||
#pragma comment(lib, "kernel32")
|
||||
#pragma comment(lib, "user32")
|
||||
|
||||
@ -1,19 +1,3 @@
|
||||
////////////////////////////////
|
||||
//~ Windows headers
|
||||
|
||||
#pragma warning(push, 0)
|
||||
# include <uuids.h>
|
||||
# include <mfapi.h>
|
||||
# include <mfidl.h>
|
||||
# include <mfreadwrite.h>
|
||||
# include <Shlwapi.h>
|
||||
# include <objidl.h>
|
||||
#pragma warning(pop)
|
||||
|
||||
#pragma comment(lib, "mfplat")
|
||||
#pragma comment(lib, "mfreadwrite")
|
||||
#pragma comment(lib, "shlwapi")
|
||||
|
||||
////////////////////////////////
|
||||
//~ Decode
|
||||
|
||||
|
||||
15
src/mp3/mp3_mmf/mp3_mmf.h
Normal file
15
src/mp3/mp3_mmf/mp3_mmf.h
Normal file
@ -0,0 +1,15 @@
|
||||
////////////////////////////////
|
||||
//~ Windows headers
|
||||
|
||||
#pragma warning(push, 0)
|
||||
# include <uuids.h>
|
||||
# include <mfapi.h>
|
||||
# include <mfidl.h>
|
||||
# include <mfreadwrite.h>
|
||||
# include <Shlwapi.h>
|
||||
# include <objidl.h>
|
||||
#pragma warning(pop)
|
||||
|
||||
#pragma comment(lib, "mfplat")
|
||||
#pragma comment(lib, "mfreadwrite")
|
||||
#pragma comment(lib, "shlwapi")
|
||||
@ -1,4 +1,7 @@
|
||||
@Layer mp3_mmf
|
||||
|
||||
//- Api
|
||||
@IncludeC mp3_mmf.h
|
||||
|
||||
//- Impl
|
||||
@IncludeC mp3_mmf.c
|
||||
|
||||
@ -1,19 +1,5 @@
|
||||
P_W32_SharedCtx P_W32_shared_ctx = ZI;
|
||||
|
||||
////////////////////////////////
|
||||
//~ Win32 libs
|
||||
|
||||
#pragma comment(lib, "kernel32")
|
||||
#pragma comment(lib, "user32")
|
||||
#pragma comment(lib, "shell32")
|
||||
#pragma comment(lib, "ole32")
|
||||
#pragma comment(lib, "winmm")
|
||||
#pragma comment(lib, "dwmapi")
|
||||
#pragma comment(lib, "bcrypt")
|
||||
#pragma comment(lib, "synchronization")
|
||||
#pragma comment(lib, "avrt")
|
||||
#pragma comment(lib, "ws2_32.lib")
|
||||
|
||||
////////////////////////////////
|
||||
//~ @hookdef Startup
|
||||
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
////////////////////////////////
|
||||
//~ Win32 headers
|
||||
//~ Win32 libs
|
||||
|
||||
#pragma warning(push, 0)
|
||||
# include <WinSock2.h>
|
||||
@ -9,11 +9,20 @@
|
||||
# include <ShlObj_core.h>
|
||||
# include <fileapi.h>
|
||||
# include <dwmapi.h>
|
||||
# include <bcrypt.h>
|
||||
# include <avrt.h>
|
||||
# include <shellapi.h>
|
||||
#pragma warning(pop)
|
||||
|
||||
#pragma comment(lib, "kernel32")
|
||||
#pragma comment(lib, "user32")
|
||||
#pragma comment(lib, "shell32")
|
||||
#pragma comment(lib, "ole32")
|
||||
#pragma comment(lib, "winmm")
|
||||
#pragma comment(lib, "dwmapi")
|
||||
#pragma comment(lib, "synchronization")
|
||||
#pragma comment(lib, "avrt")
|
||||
#pragma comment(lib, "ws2_32.lib")
|
||||
|
||||
////////////////////////////////
|
||||
//~ Window types
|
||||
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
////////////////////////////////
|
||||
//~ Win32 headers
|
||||
//~ Win32 libs
|
||||
|
||||
#pragma warning(push, 0)
|
||||
# include <initguid.h>
|
||||
|
||||
@ -3,12 +3,6 @@
|
||||
|
||||
TTF_DW_SharedState TTF_DW_shared_state = ZI;
|
||||
|
||||
////////////////////////////////
|
||||
//~ Win32 libs
|
||||
|
||||
#pragma comment(lib, "dwrite")
|
||||
#pragma comment(lib, "gdi32")
|
||||
|
||||
////////////////////////////////
|
||||
//~ @hookdef Startup
|
||||
|
||||
|
||||
@ -1,3 +1,14 @@
|
||||
////////////////////////////////
|
||||
//~ Win32 libs
|
||||
|
||||
#include <combaseapi.h>
|
||||
#include <dcommon.h>
|
||||
#include <initguid.h>
|
||||
#include <unknwn.h>
|
||||
|
||||
#pragma comment(lib, "dwrite")
|
||||
#pragma comment(lib, "gdi32")
|
||||
|
||||
////////////////////////////////
|
||||
//~ DirectWrite types
|
||||
|
||||
@ -5,12 +16,6 @@
|
||||
* https://github.com/mmozeiko/c_d2d_dwrite/blob/main/cdwrite.h
|
||||
*/
|
||||
|
||||
//- Windows headers
|
||||
#include <combaseapi.h>
|
||||
#include <dcommon.h>
|
||||
#include <initguid.h>
|
||||
#include <unknwn.h>
|
||||
|
||||
//- GUIDs
|
||||
DEFINE_GUID(IID_IDWriteFactory5, 0x958db99a, 0xbe2a, 0x4f09, 0xaf, 0x7d, 0x65, 0x18, 0x98, 0x03, 0xd1, 0xd3);
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user