improvements

This commit is contained in:
Judah Caruso 2026-02-20 00:23:09 -07:00
parent 5744fff316
commit 0474c59df8
3 changed files with 16 additions and 17 deletions

15
do.ps1
View file

@ -216,17 +216,16 @@ switch ($command) {
}
{($_ -eq "run") -or ($_ -eq "r")} {
$binary = Join-Path $OUT_DIR ($EXE_NAME + (Get-Ext $HOST_OS));
if (-not (Test-Path $binary)) {
$release = $rest[0] -eq "release" -or $rest[0] -eq "fast";
&"./do.ps1" build if ($release) { "release" } else { "" };
}
Invoke-Expression $binary | Write-Host;
$release = $rest[0] -eq "release" -or $rest[0] -eq "fast";
&"./do.ps1" build if ($release) { "release" } else { "" };
if ($LASTEXITCODE -eq 0) {
Invoke-Expression $binary | Write-Host;
}
}
{($_ -eq "run-wasm") -or ($_ -eq "rw")} {
if (-not (Test-Path (Join-Path $OUT_DIR "p2601.wasm"))) {
&"./do.ps1" build-cross wasm32-emscripten;
}
&"./do.ps1" build-cross wasm32-emscripten;
$cmd = "$ZIG run " + (Join-Path $DEPS_DIR "tinyhttp.zig");
Write-Host $cmd;

View file

@ -2,8 +2,8 @@ typedef enum { arena__alloc, arena__reset, arena__save, arena__restore, arena__r
typedef closure(void*, arena__action, uword, uword, void*, const char*, sword) Arena;
#define arena_new(A, T) cast(T*, A(arena__alloc, sizeof(T), alignof(T), 0, __FILE__, __LINE__))
#define arena_make(A, C, T) cast(T*, A(arena__alloc, sizeof(T) * (C), alignof(T), 0, __FILE__, __LINE__))
#define arena_new(A, T) cast(T*, A(arena__alloc, sizeof(T), ualign_of(T), 0, __FILE__, __LINE__))
#define arena_make(A, C, T) cast(T*, A(arena__alloc, sizeof(T) * (C), ualign_of(T), 0, __FILE__, __LINE__))
#define arena_reset(A) A(arena__reset, 0, 0, 0, __FILE__, __LINE__)
#define arena_release(A) A(arena__release, 0, 0, 0, __FILE__, __LINE__)
#define arena_save(A, SP) A(arena__save, 0, 0, (SP), __FILE__, __LINE__)

View file

@ -47,17 +47,17 @@ typedef struct { u8* data; uword count; } string;
#define string_from_const(S) (string){ .data = (S), .count = count_of((S)) }
#define string_with_count(P, C) (string){ .data = (P), .count = (C) }
#define size_of(T) cast(uword, sizeof(T))
#define usize_of(T) cast(uword, sizeof(T))
#define ssize_of(T) cast(sword, sizeof(T))
#define align_of(T) cast(uword, alignof(T))
#define ualign_of(T) cast(uword, alignof(T))
#define salign_of(T) cast(sword, alignof(T))
#define count_of(P) (size_of(P) / size_of((P)[0]))
#define count_of(P) (usize_of(P) / usize_of((P)[0]))
// Thanks azmr
#define cast(to_type, expr) ((to_type)(expr))
#define chkcast(to_type, from_type, expr) _Generic(expr, from_type: (to_type)(expr))
#define ptrcast(to_type, from_type, expr) _Generic(expr, from_type: (to_type)(uintptr_t)(expr))
#define bitcast(to_type, from_type, expr) (((union { from_type from; to_type to; }){_Generic(expr, from_type: expr)}).to)
// Thanks azmr
#define safecast(to_type, from_type, expr) _Generic(expr, from_type: cast(to_type, expr))
#define ptrcast(to_type, from_type, expr) _Generic(expr, from_type: cast(to_type, cast(uaddr, expr)))
#define bitcast(to_type, from_type, expr) (((union { from_type from; to_type to; }){_Generic(expr, from_type: expr)}).to)
#define procedure(ret_type, ...) typeof(ret_type(__VA_ARGS__))*
#define closure(ret_type, ...) typeof(ret_type(__VA_ARGS__))^