diff options
| author | Martin Kagamino Lehoux <martin@lehoux.net> | 2026-04-08 13:14:27 +0200 |
|---|---|---|
| committer | Martin Kagamino Lehoux <martin@lehoux.net> | 2026-04-08 13:15:01 +0200 |
| commit | cf534d762754860ed5b714974f99acd282d48b3b (patch) | |
| tree | bf22341cedfb50ee7bcd4e15f85add2329783f31 /include | |
| parent | 630fcb1846aed16b9ab62bcf700f668883f4521f (diff) | |
Restructure into src/{std,json}/
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Diffstat (limited to 'include')
| -rw-r--r-- | include/assert.h | 15 | ||||
| -rw-r--r-- | include/json.h | 34 | ||||
| -rw-r--r-- | include/log.h | 10 | ||||
| -rw-r--r-- | include/memory.h | 16 | ||||
| -rw-r--r-- | include/str.h | 30 | ||||
| -rw-r--r-- | include/testing.h | 36 | ||||
| -rw-r--r-- | include/time.h | 20 | ||||
| -rw-r--r-- | include/types.h | 16 | ||||
| -rw-r--r-- | include/vec.h | 18 |
9 files changed, 0 insertions, 195 deletions
diff --git a/include/assert.h b/include/assert.h deleted file mode 100644 index aa62bd1..0000000 --- a/include/assert.h +++ /dev/null @@ -1,15 +0,0 @@ -#pragma once - -#include <stdio.h> -#include <stdlib.h> - -#define assert(condition, ...) \ - do { \ - if (!(condition)) { \ - fprintf(stderr, "Assertion failed: %s:%d in %s(): ", __FILE__, \ - __LINE__, __func__); \ - fprintf(stderr, __VA_ARGS__); \ - fprintf(stderr, "\n"); \ - abort(); \ - } \ - } while (0) diff --git a/include/json.h b/include/json.h deleted file mode 100644 index 52566ab..0000000 --- a/include/json.h +++ /dev/null @@ -1,34 +0,0 @@ -#pragma once -#include "../include/memory.h" -#include "../include/str.h" -#include "../include/vec.h" - -typedef struct { - Vec keys; // Vec<Str> - Vec values; // Vec<JSON> - size len; -} JSONObject; -typedef enum { - JSON_NULL, - JSON_BOOL, - JSON_INTEGER, - JSON_FLOAT, - JSON_STRING, - JSON_ARRAY, - JSON_OBJECT -} JSONType; -typedef struct { - JSONType type; - union { - bool boolean; - i32 integer; - f32 floating; - Vec array; // Vec<JSON> - StrView string; - JSONObject object; - } as; -} JSON; -JSON *JSONObject_get(JSONObject obj, Str key); -i32 JSON_fprint(FILE *w, JSON json); -JSON JSON_parse(Arena *a, byte *src, uptr len); -JSON JSON_Int(Arena *a, i32 val); diff --git a/include/log.h b/include/log.h deleted file mode 100644 index 1458f03..0000000 --- a/include/log.h +++ /dev/null @@ -1,10 +0,0 @@ - -#include "types.h" - -typedef enum { INFO } LogLevel; - -typedef struct { - LogLevel level; -} Logger; - -void info(Logger l, const byte *name, const byte *str, ...); diff --git a/include/memory.h b/include/memory.h deleted file mode 100644 index d202e97..0000000 --- a/include/memory.h +++ /dev/null @@ -1,16 +0,0 @@ -#pragma once -#include <stddef.h> - -#include "types.h" - -typedef struct { - size cap; - byte *beg; - byte *end; -} Arena; - -Arena Arena_new(size cap); -#define new(a, T, n) (T *)alloc(a, n, sizeof(T), _Alignof(T)) -void *alloc(Arena *a, size count, size tsize, size align); -size Arena_get_used(Arena a); -void Arena_reset(Arena *a); diff --git a/include/str.h b/include/str.h deleted file mode 100644 index 2d2eb93..0000000 --- a/include/str.h +++ /dev/null @@ -1,30 +0,0 @@ -#pragma once -#include <stddef.h> -#include <stdint.h> -#include <stdio.h> - -#include "../include/memory.h" -#include "../include/types.h" - -typedef struct { - byte *data; - size len; -} Str; -u64 Str_hash64(Str s); -Str Str_copy(Arena *a, byte *data, size len); -i32 Str_fprint(FILE *w, Str s); - -typedef struct { - byte *data; - size len; -} StrView; -StrView Str_view(byte *data, size len); -Str StrView_copy(Arena *a, StrView s); - -// Macros working with both types -// Returns 1 if strings are equal, 0 otherwise -#define Str_equals(a, b) \ - ((a).len == (b).len) && (!(a).len || !memcmp((a).data, (b).data, (a).len)) -#define Str_fprint(w, s) fprintf(w, "%.*s", (i32)(s).len, (s).data) -#define S(s) \ - (Str) { s, lengthof(s) } diff --git a/include/testing.h b/include/testing.h deleted file mode 100644 index 1ca460b..0000000 --- a/include/testing.h +++ /dev/null @@ -1,36 +0,0 @@ -#pragma once -#include <stdio.h> -#include <string.h> - -#include "../include/memory.h" - -typedef struct { - size size; - byte *content; -} MemoryFile; -MemoryFile load_file(Arena *a, const char *filename); - -#define t_assert_equal(a, b) \ - if (!(a == b)) { \ - fprintf(stderr, \ - "Assertion failed: %d (%s) != %d (%s) at %s:%d in %s()\n", \ - (i32)a, #a, (i32)b, #b, __FILE__, __LINE__, __func__); \ - return 1; \ - } - -#define t_assert_fequal(a, b) \ - if ((a - b) > 1e-6 || (b - a) > 1e-6) { \ - fprintf(stderr, \ - "Assertion failed: %f (%s) != %f (%s) at %s:%d in %s()\n", a, \ - #a, b, #b, __FILE__, __LINE__, __func__); \ - return 1; \ - } - -#define t_assert_strequal(a, b) \ - if ((a.len != b.len) || (a.len && memcmp(a.data, b.data, a.len))) { \ - fprintf(stderr, \ - "Assertion failed: %.*s (%s) != %.*s (%s) at %s:%d in %s()\n", \ - (i32)a.len, a.data, #a, (i32)b.len, b.data, #b, __FILE__, \ - __LINE__, __func__); \ - return 1; \ - } diff --git a/include/time.h b/include/time.h deleted file mode 100644 index 26bbf20..0000000 --- a/include/time.h +++ /dev/null @@ -1,20 +0,0 @@ -#pragma once - -#include "types.h" - -typedef struct { - u64 s; - u64 ns; -} Time; - -typedef struct { - u64 s; - u64 ns; -} Duration; - -Time Time_get(); -f32 Time_ms(Time time); -Duration Time_diff(Time end, Time start); -f32 Duration_ms(Duration duration); -Duration Duration_from_ms(f32 ms); -Duration Duration_diff(Duration a, Duration b); diff --git a/include/types.h b/include/types.h deleted file mode 100644 index 6df9510..0000000 --- a/include/types.h +++ /dev/null @@ -1,16 +0,0 @@ -#include <immintrin.h> -#include <stdbool.h> -#include <stddef.h> -#include <stdint.h> - -typedef ptrdiff_t size; -typedef char byte; -typedef uintptr_t uptr; -typedef int32_t i32; -typedef uint64_t u64; -typedef float f32; -typedef __m256i bytex32; - -#define sizeof(x) (size)sizeof(x) -#define countof(a) (sizeof(a) / sizeof(*(a))) -#define lengthof(s) (countof(s) - 1) diff --git a/include/vec.h b/include/vec.h deleted file mode 100644 index 8ff0332..0000000 --- a/include/vec.h +++ /dev/null @@ -1,18 +0,0 @@ -#pragma once -#include <stddef.h> -#include <stdint.h> - -#include "../include/memory.h" -#include "../include/types.h" - -typedef struct { - void *data; - size len; - size cap; - size tsize; - size align; -} Vec; -#define Vec_new(a, T, cap) _Vec_new(a, sizeof(T), cap, _Alignof(T)) -Vec _Vec_new(Arena *a, size tsize, size cap, size align); -void Vec_push(Arena *a, Vec *v, void *data); -#define Vec_get(v, T, pos) (T *)(v.data + v.tsize * pos) |
