diff options
Diffstat (limited to 'library')
| -rw-r--r-- | library/arena.c | 81 | ||||
| -rw-r--r-- | library/arena.h | 69 | ||||
| -rw-r--r-- | library/base.h | 42 | ||||
| -rw-r--r-- | library/clang-format | 104 | ||||
| -rw-r--r-- | library/clangd | 59 |
5 files changed, 0 insertions, 355 deletions
diff --git a/library/arena.c b/library/arena.c deleted file mode 100644 index 39711d5..0000000 --- a/library/arena.c +++ /dev/null | |||
| @@ -1,81 +0,0 @@ | |||
| 1 | #include <assert.h> | ||
| 2 | #include <dirent.h> | ||
| 3 | #include <fcntl.h> | ||
| 4 | #include <stdint.h> | ||
| 5 | #include <string.h> | ||
| 6 | #include <sys/mman.h> | ||
| 7 | #include <sys/stat.h> | ||
| 8 | #include <unistd.h> | ||
| 9 | |||
| 10 | #include "arena.h" | ||
| 11 | |||
| 12 | mem_arena * | ||
| 13 | arena_create(u64 capacity) | ||
| 14 | { | ||
| 15 | mem_arena *arena = mmap(0, capacity, PROT_READ | PROT_WRITE | PROT_EXEC, | ||
| 16 | MAP_SHARED | MAP_ANONYMOUS, -1, 0); | ||
| 17 | if (arena == MAP_FAILED) | ||
| 18 | { | ||
| 19 | assert(0); | ||
| 20 | } | ||
| 21 | |||
| 22 | arena->capacity = capacity; | ||
| 23 | arena->pos = ARENA_BASE_POS; | ||
| 24 | |||
| 25 | return arena; | ||
| 26 | } | ||
| 27 | |||
| 28 | // make it a void pointer to allow implicit conversion | ||
| 29 | void | ||
| 30 | arena_destroy(mem_arena *arena) | ||
| 31 | { | ||
| 32 | munmap(arena, arena->capacity); | ||
| 33 | } | ||
| 34 | |||
| 35 | void * | ||
| 36 | arena_push(mem_arena *arena, u64 size, b32 non_zero) | ||
| 37 | { | ||
| 38 | u64 pos_aligned = ALIGN_UP_POW2(arena->pos, ARENA_ALIGN); | ||
| 39 | u64 new_pos = pos_aligned + size; | ||
| 40 | |||
| 41 | if (new_pos > arena->capacity) | ||
| 42 | { | ||
| 43 | assert(0); | ||
| 44 | return NULL; | ||
| 45 | } | ||
| 46 | |||
| 47 | arena->pos = new_pos; | ||
| 48 | // cast to u8 to be able to do pointer arithemtic | ||
| 49 | u8 *out = (u8 *)arena + pos_aligned; | ||
| 50 | |||
| 51 | if (!non_zero) | ||
| 52 | { | ||
| 53 | memset(out, 0, size); | ||
| 54 | } | ||
| 55 | return out; | ||
| 56 | } | ||
| 57 | void | ||
| 58 | arena_pop(mem_arena *arena, u64 size) | ||
| 59 | { | ||
| 60 | size = MIN(size, arena->pos - ARENA_BASE_POS); | ||
| 61 | arena->pos -= size; | ||
| 62 | } | ||
| 63 | |||
| 64 | void | ||
| 65 | arena_pop_to(mem_arena *arena, u64 pos) | ||
| 66 | { | ||
| 67 | u64 size = pos < arena->pos ? arena->pos - pos : 0; | ||
| 68 | arena_pop(arena, size); | ||
| 69 | } | ||
| 70 | |||
| 71 | void | ||
| 72 | arena_clear(mem_arena *arena) | ||
| 73 | { | ||
| 74 | arena_pop_to(arena, ARENA_BASE_POS); | ||
| 75 | } | ||
| 76 | |||
| 77 | #define PUSH_STRUCT(arena, T) (T *)arena_push((arena), sizeof(T), 0) | ||
| 78 | #define PUSH_STRUCT_NZ(arena, T) (T *)arena_push((arena), sizeof(T), 1) | ||
| 79 | #define PUSH_ARRAY(arena, T, n) (T *)arena_push((arena), sizeof(T) * (n), 0) | ||
| 80 | #define PUSH_ARRAY_NZ(arena, T, n) (T *)arena_push((arena), sizeof(T) * (n), 1) | ||
| 81 | |||
diff --git a/library/arena.h b/library/arena.h deleted file mode 100644 index 330023e..0000000 --- a/library/arena.h +++ /dev/null | |||
| @@ -1,69 +0,0 @@ | |||
| 1 | #ifndef ARENA_H | ||
| 2 | #define ARENA_H | ||
| 3 | |||
| 4 | #include "base.h" | ||
| 5 | |||
| 6 | /** | ||
| 7 | * Arena Helper macro's | ||
| 8 | * */ | ||
| 9 | |||
| 10 | #define MIN(a, b) (((a) < (b)) ? (a) : (b)) | ||
| 11 | #define MAX(a, b) (((a) > (b)) ? (a) : (b)) | ||
| 12 | #define ALIGN_UP_POW2(n, p) (((u64)(n) + ((u64)(p) - 1)) & (~((u64)(p) - 1))) | ||
| 13 | |||
| 14 | |||
| 15 | |||
| 16 | /* | ||
| 17 | * Represents a disk partition with major/minor device numbers and block count. | ||
| 18 | */ | ||
| 19 | |||
| 20 | /** | ||
| 21 | * replacing malloc/free with arena allocaters | ||
| 22 | * | ||
| 23 | * */ | ||
| 24 | |||
| 25 | #define ARENA_BASE_POS (sizeof(mem_arena)) | ||
| 26 | // void * for the size of a pointer on the machine, 64/32bit comp | ||
| 27 | #define ARENA_ALIGN (sizeof(void *)) | ||
| 28 | |||
| 29 | |||
| 30 | static inline u64 KiB(u64 n) { return n << 10; } | ||
| 31 | static inline u64 MiB(u64 n) { return n << 20; } | ||
| 32 | static inline u64 GiB(u64 n) { return n << 30; } | ||
| 33 | |||
| 34 | typedef struct mem_arena mem_arena; | ||
| 35 | |||
| 36 | |||
| 37 | struct mem_arena | ||
| 38 | { | ||
| 39 | u64 capacity; | ||
| 40 | u64 pos; | ||
| 41 | } ; | ||
| 42 | |||
| 43 | // arena prototypes | ||
| 44 | mem_arena * | ||
| 45 | arena_create(u64 capacity); | ||
| 46 | // make it a void pointer to allow implicit conversion | ||
| 47 | void | ||
| 48 | arena_destroy(mem_arena *arena); | ||
| 49 | |||
| 50 | void * | ||
| 51 | arena_push(mem_arena *arena, u64 size, b32 non_zero); | ||
| 52 | |||
| 53 | void | ||
| 54 | arena_pop(mem_arena *arena, u64 size); | ||
| 55 | |||
| 56 | void | ||
| 57 | arena_pop_to(mem_arena *arena, u64 pos); | ||
| 58 | |||
| 59 | void | ||
| 60 | arena_clear(mem_arena *arena); | ||
| 61 | |||
| 62 | |||
| 63 | #define PUSH_STRUCT(arena, T) (T *)arena_push((arena), sizeof(T), 0) | ||
| 64 | #define PUSH_STRUCT_NZ(arena, T) (T *)arena_push((arena), sizeof(T), 1) | ||
| 65 | #define PUSH_ARRAY(arena, T, n) (T *)arena_push((arena), sizeof(T) * (n), 0) | ||
| 66 | #define PUSH_ARRAY_NZ(arena, T, n) (T *)arena_push((arena), sizeof(T) * (n), 1) | ||
| 67 | |||
| 68 | |||
| 69 | #endif | ||
diff --git a/library/base.h b/library/base.h deleted file mode 100644 index 74b6303..0000000 --- a/library/base.h +++ /dev/null | |||
| @@ -1,42 +0,0 @@ | |||
| 1 | #ifndef BASE_H | ||
| 2 | #define BASE_H | ||
| 3 | |||
| 4 | #include <stddef.h> | ||
| 5 | #include <stdint.h> | ||
| 6 | |||
| 7 | #define OK 0 | ||
| 8 | #define ERR_IO 1 | ||
| 9 | #define ERR_PARSE 2 | ||
| 10 | #define ERR_PERM 3 | ||
| 11 | #define ERR_INVALID 4 | ||
| 12 | |||
| 13 | enum { | ||
| 14 | BUFFER_SIZE_SMALL = 128, | ||
| 15 | BUFFER_SIZE_DEFAULT = 256, | ||
| 16 | BUFFER_SIZE_LARGE = 512, | ||
| 17 | PATH_MAX_LEN = 4096 | ||
| 18 | }; | ||
| 19 | |||
| 20 | typedef uint64_t u64; | ||
| 21 | typedef uint32_t u32; | ||
| 22 | typedef uint16_t u16; | ||
| 23 | typedef uint8_t u8; | ||
| 24 | |||
| 25 | typedef int8_t i8; | ||
| 26 | typedef int16_t i16; | ||
| 27 | typedef int32_t i32; | ||
| 28 | typedef int64_t i64; | ||
| 29 | |||
| 30 | typedef float f32; | ||
| 31 | typedef double f64; | ||
| 32 | |||
| 33 | typedef i32 b32; | ||
| 34 | typedef i16 b16; | ||
| 35 | typedef u8 b8; | ||
| 36 | |||
| 37 | #define TRUE 1 | ||
| 38 | #define FALSE 0 | ||
| 39 | |||
| 40 | |||
| 41 | |||
| 42 | #endif | ||
diff --git a/library/clang-format b/library/clang-format deleted file mode 100644 index 3c61d5e..0000000 --- a/library/clang-format +++ /dev/null | |||
| @@ -1,104 +0,0 @@ | |||
| 1 | BasedOnStyle: LLVM | ||
| 2 | Language: C | ||
| 3 | |||
| 4 | # ------------------------------------------------------------------- | ||
| 5 | # Indentation & layout | ||
| 6 | # ------------------------------------------------------------------- | ||
| 7 | IndentWidth: 2 | ||
| 8 | TabWidth: 2 | ||
| 9 | UseTab: Never | ||
| 10 | ContinuationIndentWidth: 2 | ||
| 11 | |||
| 12 | IndentCaseLabels: true | ||
| 13 | IndentGotoLabels: true | ||
| 14 | IndentPPDirectives: None | ||
| 15 | IndentExternBlock: NoIndent | ||
| 16 | |||
| 17 | # ------------------------------------------------------------------- | ||
| 18 | # Line breaking | ||
| 19 | # ------------------------------------------------------------------- | ||
| 20 | ColumnLimit: 0 | ||
| 21 | |||
| 22 | AllowAllParametersOfDeclarationOnNextLine: false | ||
| 23 | AllowAllArgumentsOnNextLine: false | ||
| 24 | |||
| 25 | AllowShortFunctionsOnASingleLine: false | ||
| 26 | AllowShortIfStatementsOnASingleLine: Never | ||
| 27 | AllowShortLoopsOnASingleLine: false | ||
| 28 | AllowShortBlocksOnASingleLine: Never | ||
| 29 | AllowShortCaseLabelsOnASingleLine: false | ||
| 30 | |||
| 31 | AlwaysBreakAfterReturnType: All | ||
| 32 | AlwaysBreakTemplateDeclarations: No # harmless for C | ||
| 33 | |||
| 34 | BreakBeforeBinaryOperators: None | ||
| 35 | |||
| 36 | # ------------------------------------------------------------------- | ||
| 37 | # Braces (Allman style) | ||
| 38 | # ------------------------------------------------------------------- | ||
| 39 | BreakBeforeBraces: Allman | ||
| 40 | |||
| 41 | BraceWrapping: | ||
| 42 | AfterCaseLabel: true | ||
| 43 | BeforeElse: true | ||
| 44 | BeforeCatch: true | ||
| 45 | SplitEmptyFunction: true | ||
| 46 | SplitEmptyRecord: true | ||
| 47 | SplitEmptyNamespace: true | ||
| 48 | |||
| 49 | # NOTE: | ||
| 50 | # AfterControlStatement / AfterFunction / AfterStruct / AfterEnum / AfterUnion | ||
| 51 | # are IMPLIED by Allman and must NOT be redundantly specified. | ||
| 52 | |||
| 53 | # ------------------------------------------------------------------- | ||
| 54 | # Spacing | ||
| 55 | # ------------------------------------------------------------------- | ||
| 56 | SpaceBeforeParens: ControlStatements | ||
| 57 | SpaceBeforeAssignmentOperators: true | ||
| 58 | SpaceBeforeRangeBasedForLoopColon: true # ignored in C, harmless | ||
| 59 | |||
| 60 | SpacesInParentheses: false | ||
| 61 | SpacesInSquareBrackets: false | ||
| 62 | SpacesInAngles: false | ||
| 63 | SpaceInEmptyParentheses: false | ||
| 64 | SpacesBeforeTrailingComments: 1 | ||
| 65 | |||
| 66 | PointerAlignment: Right | ||
| 67 | DerivePointerAlignment: false | ||
| 68 | |||
| 69 | # ------------------------------------------------------------------- | ||
| 70 | # Alignment (explicitly disabled) | ||
| 71 | # ------------------------------------------------------------------- | ||
| 72 | AlignAfterOpenBracket: DontAlign | ||
| 73 | AlignOperands: false | ||
| 74 | AlignTrailingComments: false | ||
| 75 | AlignConsecutiveAssignments: false | ||
| 76 | AlignConsecutiveDeclarations: false | ||
| 77 | AlignEscapedNewlines: DontAlign | ||
| 78 | |||
| 79 | # ------------------------------------------------------------------- | ||
| 80 | # Comments | ||
| 81 | # ------------------------------------------------------------------- | ||
| 82 | ReflowComments: false | ||
| 83 | CommentPragmas: '^ dont touch:' | ||
| 84 | KeepEmptyLinesAtTheStartOfBlocks: false | ||
| 85 | MaxEmptyLinesToKeep: 1 | ||
| 86 | |||
| 87 | # ------------------------------------------------------------------- | ||
| 88 | # Includes | ||
| 89 | # ------------------------------------------------------------------- | ||
| 90 | SortIncludes: Never | ||
| 91 | IncludeBlocks: Preserve | ||
| 92 | |||
| 93 | # ------------------------------------------------------------------- | ||
| 94 | # Macros & preprocessor | ||
| 95 | # ------------------------------------------------------------------- | ||
| 96 | MacroBlockBegin: '' | ||
| 97 | MacroBlockEnd: '' | ||
| 98 | SpaceAfterCStyleCast: false | ||
| 99 | |||
| 100 | # ------------------------------------------------------------------- | ||
| 101 | # C-specific | ||
| 102 | # ------------------------------------------------------------------- | ||
| 103 | Cpp11BracedListStyle: false | ||
| 104 | DisableFormat: false | ||
diff --git a/library/clangd b/library/clangd deleted file mode 100644 index 624678a..0000000 --- a/library/clangd +++ /dev/null | |||
| @@ -1,59 +0,0 @@ | |||
| 1 | CompileFlags: | ||
| 2 | Add: | ||
| 3 | - -std=c99 | ||
| 4 | - -xc | ||
| 5 | |||
| 6 | - -Iinclude | ||
| 7 | |||
| 8 | - -Wall | ||
| 9 | - -Wextra | ||
| 10 | - -Wpedantic | ||
| 11 | - -Wshadow | ||
| 12 | - -Wconversion | ||
| 13 | - -Wsign-conversion | ||
| 14 | - -Wmissing-declarations | ||
| 15 | - -Wundef | ||
| 16 | - -Wpointer-arith | ||
| 17 | - -Wcast-align | ||
| 18 | - -Wcast-qual | ||
| 19 | - -Wwrite-strings | ||
| 20 | - -Wswitch-enum | ||
| 21 | - -Wformat=2 | ||
| 22 | - -Wstrict-aliasing=2 | ||
| 23 | - -Werror=implicit-function-declaration | ||
| 24 | - -Werror=implicit-int | ||
| 25 | - -Werror=incompatible-pointer-types | ||
| 26 | - -Werror=return-type | ||
| 27 | - -Wformat-security | ||
| 28 | - -Wnull-dereference | ||
| 29 | - -Wmisleading-indentation | ||
| 30 | |||
| 31 | - -Wunused | ||
| 32 | - -Wuninitialized | ||
| 33 | - -Werror | ||
| 34 | - -Wdouble-promotion | ||
| 35 | - -Wstrict-overflow=2 | ||
| 36 | |||
| 37 | - -D_POSIX_C_SOURCE=200809L | ||
| 38 | - "-I/include" | ||
| 39 | |||
| 40 | Remove: | ||
| 41 | - -std=* | ||
| 42 | - -O* | ||
| 43 | - -march=* | ||
| 44 | - -mtune=* | ||
| 45 | |||
| 46 | |||
| 47 | Hover: | ||
| 48 | ShowAKA: true | ||
| 49 | |||
| 50 | InlayHints: | ||
| 51 | Enabled: true | ||
| 52 | ParameterNames: true | ||
| 53 | DeducedTypes: true | ||
| 54 | |||
| 55 | Completion: | ||
| 56 | AllScopes: true | ||
| 57 | |||
| 58 | Index: | ||
| 59 | Background: Build | ||
