summaryrefslogtreecommitdiff
path: root/library
diff options
context:
space:
mode:
Diffstat (limited to 'library')
-rw-r--r--library/arena.c81
-rw-r--r--library/arena.h69
-rw-r--r--library/base.h42
-rw-r--r--library/clang-format104
-rw-r--r--library/clangd59
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
12mem_arena *
13arena_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
29void
30arena_destroy(mem_arena *arena)
31{
32 munmap(arena, arena->capacity);
33}
34
35void *
36arena_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}
57void
58arena_pop(mem_arena *arena, u64 size)
59{
60 size = MIN(size, arena->pos - ARENA_BASE_POS);
61 arena->pos -= size;
62}
63
64void
65arena_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
71void
72arena_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
30static inline u64 KiB(u64 n) { return n << 10; }
31static inline u64 MiB(u64 n) { return n << 20; }
32static inline u64 GiB(u64 n) { return n << 30; }
33
34typedef struct mem_arena mem_arena;
35
36
37struct mem_arena
38{
39 u64 capacity;
40 u64 pos;
41} ;
42
43// arena prototypes
44mem_arena *
45arena_create(u64 capacity);
46// make it a void pointer to allow implicit conversion
47void
48arena_destroy(mem_arena *arena);
49
50void *
51arena_push(mem_arena *arena, u64 size, b32 non_zero);
52
53void
54arena_pop(mem_arena *arena, u64 size);
55
56void
57arena_pop_to(mem_arena *arena, u64 pos);
58
59void
60arena_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
13enum {
14 BUFFER_SIZE_SMALL = 128,
15 BUFFER_SIZE_DEFAULT = 256,
16 BUFFER_SIZE_LARGE = 512,
17 PATH_MAX_LEN = 4096
18};
19
20typedef uint64_t u64;
21typedef uint32_t u32;
22typedef uint16_t u16;
23typedef uint8_t u8;
24
25typedef int8_t i8;
26typedef int16_t i16;
27typedef int32_t i32;
28typedef int64_t i64;
29
30typedef float f32;
31typedef double f64;
32
33typedef i32 b32;
34typedef i16 b16;
35typedef 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 @@
1BasedOnStyle: LLVM
2Language: C
3
4# -------------------------------------------------------------------
5# Indentation & layout
6# -------------------------------------------------------------------
7IndentWidth: 2
8TabWidth: 2
9UseTab: Never
10ContinuationIndentWidth: 2
11
12IndentCaseLabels: true
13IndentGotoLabels: true
14IndentPPDirectives: None
15IndentExternBlock: NoIndent
16
17# -------------------------------------------------------------------
18# Line breaking
19# -------------------------------------------------------------------
20ColumnLimit: 0
21
22AllowAllParametersOfDeclarationOnNextLine: false
23AllowAllArgumentsOnNextLine: false
24
25AllowShortFunctionsOnASingleLine: false
26AllowShortIfStatementsOnASingleLine: Never
27AllowShortLoopsOnASingleLine: false
28AllowShortBlocksOnASingleLine: Never
29AllowShortCaseLabelsOnASingleLine: false
30
31AlwaysBreakAfterReturnType: All
32AlwaysBreakTemplateDeclarations: No # harmless for C
33
34BreakBeforeBinaryOperators: None
35
36# -------------------------------------------------------------------
37# Braces (Allman style)
38# -------------------------------------------------------------------
39BreakBeforeBraces: Allman
40
41BraceWrapping:
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# -------------------------------------------------------------------
56SpaceBeforeParens: ControlStatements
57SpaceBeforeAssignmentOperators: true
58SpaceBeforeRangeBasedForLoopColon: true # ignored in C, harmless
59
60SpacesInParentheses: false
61SpacesInSquareBrackets: false
62SpacesInAngles: false
63SpaceInEmptyParentheses: false
64SpacesBeforeTrailingComments: 1
65
66PointerAlignment: Right
67DerivePointerAlignment: false
68
69# -------------------------------------------------------------------
70# Alignment (explicitly disabled)
71# -------------------------------------------------------------------
72AlignAfterOpenBracket: DontAlign
73AlignOperands: false
74AlignTrailingComments: false
75AlignConsecutiveAssignments: false
76AlignConsecutiveDeclarations: false
77AlignEscapedNewlines: DontAlign
78
79# -------------------------------------------------------------------
80# Comments
81# -------------------------------------------------------------------
82ReflowComments: false
83CommentPragmas: '^ dont touch:'
84KeepEmptyLinesAtTheStartOfBlocks: false
85MaxEmptyLinesToKeep: 1
86
87# -------------------------------------------------------------------
88# Includes
89# -------------------------------------------------------------------
90SortIncludes: Never
91IncludeBlocks: Preserve
92
93# -------------------------------------------------------------------
94# Macros & preprocessor
95# -------------------------------------------------------------------
96MacroBlockBegin: ''
97MacroBlockEnd: ''
98SpaceAfterCStyleCast: false
99
100# -------------------------------------------------------------------
101# C-specific
102# -------------------------------------------------------------------
103Cpp11BracedListStyle: false
104DisableFormat: 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 @@
1CompileFlags:
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
47Hover:
48 ShowAKA: true
49
50InlayHints:
51 Enabled: true
52 ParameterNames: true
53 DeducedTypes: true
54
55Completion:
56 AllScopes: true
57
58Index:
59 Background: Build