summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.gitignore3
-rw-r--r--.idea/workspace.xml102
-rw-r--r--base.c172
3 files changed, 105 insertions, 172 deletions
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..ec5545e
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,3 @@
+idea/
+idea
+idea/*
diff --git a/.idea/workspace.xml b/.idea/workspace.xml
new file mode 100644
index 0000000..47a4672
--- /dev/null
+++ b/.idea/workspace.xml
@@ -0,0 +1,102 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project version="4">
+ <component name="AutoImportSettings">
+ <option name="autoReloadType" value="SELECTIVE" />
+ </component>
+ <component name="BackendCodeEditorMiscSettings">
+ <option name="/Default/Environment/Hierarchy/GeneratedFilesCacheKey/Timestamp/@EntryValue" value="4" type="long" />
+ <option name="/Default/Housekeeping/FeatureSuggestion/FeatureSuggestionManager/DisabledSuggesters/=SwitchToGoToActionSuggester/@EntryIndexedValue" value="true" type="bool" />
+ </component>
+ <component name="ChangeListManager">
+ <list default="true" id="4e2e747b-4cf7-4326-a0ab-4428fecfc88f" name="Changes" comment="" />
+ <option name="SHOW_DIALOG" value="false" />
+ <option name="HIGHLIGHT_CONFLICTS" value="true" />
+ <option name="HIGHLIGHT_NON_ACTIVE_CHANGELIST" value="false" />
+ <option name="LAST_RESOLUTION" value="IGNORE" />
+ </component>
+ <component name="Git.Settings">
+ <option name="RECENT_GIT_ROOT_PATH" value="$PROJECT_DIR$" />
+ </component>
+ <component name="MacroExpansionManager">
+ <option name="directoryName" value="tzFWBH8r" />
+ </component>
+ <component name="ProjectColorInfo">{
+ &quot;customColor&quot;: &quot;&quot;,
+ &quot;associatedIndex&quot;: 4
+}</component>
+ <component name="ProjectId" id="37WXJwlfHgfbTUSQajVrapU6YHf" />
+ <component name="ProjectViewState">
+ <option name="autoscrollToSource" value="true" />
+ <option name="hideEmptyMiddlePackages" value="true" />
+ <option name="showLibraryContents" value="true" />
+ </component>
+ <component name="PropertiesComponent"><![CDATA[{
+ "keyToString": {
+ "C/C++ File.main.c.executor": "Debug",
+ "C/C++ File.main.cpp.executor": "Debug",
+ "ModuleVcsDetector.initialDetectionPerformed": "true",
+ "RunOnceActivity.RadMigrateCodeStyle": "true",
+ "RunOnceActivity.ShowReadmeOnStart": "true",
+ "RunOnceActivity.cidr.known.project.marker": "true",
+ "RunOnceActivity.readMode.enableVisualFormatting": "true",
+ "RunOnceActivity.typescript.service.memoryLimit.init": "true",
+ "cf.advertisement.text.overridden": "true",
+ "cf.first.check.clang-format": "false",
+ "cidr.known.project.marker": "true",
+ "git-widget-placeholder": "main",
+ "nodejs_package_manager_path": "npm",
+ "org.rust.first.attach.projects": "true",
+ "settings.editor.selected.configurable": "preferences.lookFeel",
+ "vue.rearranger.settings.migration": "true"
+ }
+}]]></component>
+ <component name="RunManager" selected="C/C++ File.main.c">
+ <configuration name="main.c" type="CppFileRunConfiguration" factoryName="CppFileRunConfiguration" REDIRECT_INPUT="false" ELEVATE="false" USE_EXTERNAL_CONSOLE="false" EMULATE_TERMINAL="false" PASS_PARENT_ENVS_2="true" PROJECT_NAME="x11-programming" TARGET_NAME="main.c" CONFIG_NAME="main.c">
+ <option name="compilerOptions" value="-lX11" />
+ <option name="sourceFile" value="main.c" />
+ <method v="2">
+ <option name="com.jetbrains.cidr.cpp.runfile.CppFileBuildBeforeRunTaskProvider$BasicBuildBeforeRunTask" enabled="true" />
+ </method>
+ </configuration>
+ <configuration name="main.cpp" type="CppFileRunConfiguration" factoryName="CppFileRunConfiguration" nameIsGenerated="true" REDIRECT_INPUT="false" ELEVATE="false" USE_EXTERNAL_CONSOLE="false" EMULATE_TERMINAL="false" PASS_PARENT_ENVS_2="true" PROJECT_NAME="x11-programming" TARGET_NAME="main.cpp" CONFIG_NAME="main.cpp">
+ <option name="compilerOptions" value="-lX11" />
+ <option name="sourceFile" value="main.cpp" />
+ <method v="2">
+ <option name="com.jetbrains.cidr.cpp.runfile.CppFileBuildBeforeRunTaskProvider$BasicBuildBeforeRunTask" enabled="true" />
+ </method>
+ </configuration>
+ <list>
+ <item itemvalue="C/C++ File.main.c" />
+ <item itemvalue="C/C++ File.main.cpp" />
+ </list>
+ </component>
+ <component name="RustProjectSettings">
+ <option name="toolchainHomeDirectory" value="/usr/bin" />
+ </component>
+ <component name="TaskManager">
+ <task active="true" id="Default" summary="Default task">
+ <changelist id="4e2e747b-4cf7-4326-a0ab-4428fecfc88f" name="Changes" comment="" />
+ <created>1767019734019</created>
+ <option name="number" value="Default" />
+ <option name="presentableId" value="Default" />
+ <updated>1767019734019</updated>
+ <workItem from="1767019735790" duration="556000" />
+ <workItem from="1767037529556" duration="1209000" />
+ <workItem from="1767098248582" duration="514000" />
+ <workItem from="1767099177012" duration="1625000" />
+ <workItem from="1767120425134" duration="4461000" />
+ </task>
+ <servers />
+ </component>
+ <component name="TypeScriptGeneratedFilesManager">
+ <option name="version" value="3" />
+ </component>
+ <component name="XDebuggerManager">
+ <watches-manager>
+ <configuration name="CppFileRunConfiguration">
+ <watch expression="gc" language="C++" />
+ <watch expression="color" language="C++" />
+ </configuration>
+ </watches-manager>
+ </component>
+</project> \ No newline at end of file
diff --git a/base.c b/base.c
deleted file mode 100644
index 519e644..0000000
--- a/base.c
+++ /dev/null
@@ -1,172 +0,0 @@
-#include <sys/mman.h>
-#include <stddef.h>
-#include <stdint.h>
-#include <string.h>
-#include <assert.h>
-
-#define OK 0
-#define ERR_IO 1
-#define ERR_PARSE 2
-#define ERR_PERM 3
-#define ERR_INVALID 4
-
-enum
-{
- BUFFER_SIZE_SMALL = 128,
- BUFFER_SIZE_DEFAULT = 256,
- BUFFER_SIZE_LARGE = 512,
- PATH_MAX_LEN = 4096
-};
-
-typedef uint64_t u64;
-typedef uint32_t u32;
-typedef uint16_t u16;
-typedef uint8_t u8;
-
-typedef int8_t i8;
-typedef int16_t i16;
-typedef int32_t i32;
-typedef int64_t i64;
-
-typedef i16 b16;
-typedef i32 b32;
-
-static inline u64
-KiB(u64 n)
-{
- return n << 10;
-}
-static inline u64
-MiB(u64 n)
-{
- return n << 20;
-}
-static inline u64
-GiB(u64 n)
-{
- return n << 30;
-}
-
-typedef struct mem_arena mem_arena;
-mem_arena *
-arena_create(u64 capacity);
-void
-arena_destroy(mem_arena *arena);
-void
-arena_clear(mem_arena *arena);
-
-/**
- * Arena Helper macro's
- * */
-
-#define MIN(a, b) (((a) < (b)) ? (a) : (b))
-#define MAX(a, b) (((a) > (b)) ? (a) : (b))
-#define ALIGN_UP_POW2(n, p) (((u64)(n) + ((u64)(p) - 1)) & (~((u64)(p) - 1)))
-
-/*
- * Represents a disk partition with major/minor device numbers and block count.
- */
-
-/**
- * replacing malloc/free with arena allocaters
- *
- * */
-
-#define ARENA_BASE_POS (sizeof(mem_arena))
-// void * for the size of a pointer on the machine, 64/32bit comp
-#define ARENA_ALIGN (sizeof(void *))
-
-struct mem_arena
-{
- u64 capacity;
- u64 pos;
-};
-
-// arena prototypes
-mem_arena *
-arena_create(u64 capacity);
-// make it a void pointer to allow implicit conversion
-void
-arena_destroy(mem_arena *arena);
-
-void *
-arena_push(mem_arena *arena, u64 size, b32 non_zero);
-
-void
-arena_pop(mem_arena *arena, u64 size);
-
-void
-arena_pop_to(mem_arena *arena, u64 pos);
-
-void
-arena_clear(mem_arena *arena);
-
-mem_arena *
-arena_create(u64 capacity)
-{
- mem_arena *arena = mmap(0, capacity, PROT_READ | PROT_WRITE | PROT_EXEC,
- MAP_SHARED | MAP_ANONYMOUS, -1, 0);
- if (arena == MAP_FAILED)
- {
- assert(0);
- }
-
- arena->capacity = capacity;
- arena->pos = ARENA_BASE_POS;
-
- return arena;
-}
-
-// make it a void pointer to allow implicit conversion
-void
-arena_destroy(mem_arena *arena)
-{
- munmap(arena, arena->capacity);
-}
-
-void *
-arena_push(mem_arena *arena, u64 size, b32 non_zero)
-{
- u64 pos_aligned = ALIGN_UP_POW2(arena->pos, ARENA_ALIGN);
- u64 new_pos = pos_aligned + size;
-
- if (new_pos > arena->capacity)
- {
- assert(0);
- return NULL;
- }
-
- arena->pos = new_pos;
- // cast to u8 to be able to do pointer arithemtic
- u8 *out = (u8 *)arena + pos_aligned;
-
- if (!non_zero)
- {
- memset(out, 0, size);
- }
- return out;
-}
-void
-arena_pop(mem_arena *arena, u64 size)
-{
- size = MIN(size, arena->pos - ARENA_BASE_POS);
- arena->pos -= size;
-}
-
-void
-arena_pop_to(mem_arena *arena, u64 pos)
-{
- u64 size = pos < arena->pos ? arena->pos - pos : 0;
- arena_pop(arena, size);
-}
-
-void
-arena_clear(mem_arena *arena)
-{
- arena_pop_to(arena, ARENA_BASE_POS);
-}
-
-#define PUSH_STRUCT(arena, T) (T *)arena_push((arena), sizeof(T), 0)
-#define PUSH_STRUCT_NZ(arena, T) (T *)arena_push((arena), sizeof(T), 1)
-#define PUSH_ARRAY(arena, T, n) (T *)arena_push((arena), sizeof(T) * (n), 0)
-#define PUSH_ARRAY_NZ(arena, T, n) (T *)arena_push((arena), sizeof(T) * (n), 1)