From aa064359cb514251a73b53de3e530fa89f687ab7 Mon Sep 17 00:00:00 2001 From: Nicholas Noll Date: Tue, 21 Apr 2020 12:38:03 -0700 Subject: feat: added allocator interface to allow for flexible library interfaces --- .gitignore | 1 + bin/initmk | 2 +- compile_commands.json | 68 +++++++++++++++++++++++++++++++++++++-------------- include/libn.h | 12 +++++++++ sys/rules.mk | 6 +++-- 5 files changed, 68 insertions(+), 21 deletions(-) diff --git a/.gitignore b/.gitignore index 43e0b14..90ea2fd 100644 --- a/.gitignore +++ b/.gitignore @@ -3,3 +3,4 @@ dep/ build/ vendor/ sys/cc +sys/nixos diff --git a/bin/initmk b/bin/initmk index ca3f92a..1f01443 100755 --- a/bin/initmk +++ b/bin/initmk @@ -36,7 +36,7 @@ BINS := $(BINS) $(BINS_$(d)) $(LIBS_$(d)): $(OBJS_$(d)) $(ARCHIVE) -$(BINS_$(d)): $(OBJ_DIR)/libn/test.o +$(BINS_$(d)): $(OBJS_$(d)) $(LINK) # ---- Pop off stack ---- diff --git a/compile_commands.json b/compile_commands.json index 31a2936..99168be 100644 --- a/compile_commands.json +++ b/compile_commands.json @@ -7,13 +7,16 @@ "-fno-strict-aliasing", "-fwrapv", "-fms-extensions", + "-ffreestanding", + "-fno-builtin", + "-nostdlib", "-Iinclude", "-o", - "build/libn/error.o", - "sys/libn/error.c" + "build/libc/string.o", + "sys/libc/string.c" ], "directory": "/home/nolln/root", - "file": "sys/libn/error.c" + "file": "sys/libc/string.c" }, { "arguments": [ @@ -25,11 +28,11 @@ "-fms-extensions", "-Iinclude", "-o", - "build/libn/coro.o", - "sys/libn/coro.c" + "build/libn/test.o", + "sys/libn/test.c" ], "directory": "/home/nolln/root", - "file": "sys/libn/coro.c" + "file": "sys/libn/test.c" }, { "arguments": [ @@ -60,11 +63,27 @@ "-fms-extensions", "-Iinclude", "-o", - "build/libn/string.o", - "sys/libn/string.c" + "build/libn/error.o", + "sys/libn/error.c" ], "directory": "/home/nolln/root", - "file": "sys/libn/string.c" + "file": "sys/libn/error.c" + }, + { + "arguments": [ + "clang", + "-c", + "-g", + "-fno-strict-aliasing", + "-fwrapv", + "-fms-extensions", + "-Iinclude", + "-o", + "build/libn/bufio.o", + "sys/libn/bufio.c" + ], + "directory": "/home/nolln/root", + "file": "sys/libn/bufio.c" }, { "arguments": [ @@ -92,11 +111,11 @@ "-fms-extensions", "-Iinclude", "-o", - "build/libn/test.o", - "sys/libn/test.c" + "build/libn/io.o", + "sys/libn/io.c" ], "directory": "/home/nolln/root", - "file": "sys/libn/test.c" + "file": "sys/libn/io.c" }, { "arguments": [ @@ -106,15 +125,28 @@ "-fno-strict-aliasing", "-fwrapv", "-fms-extensions", - "-ffreestanding", - "-fno-builtin", - "-nostdlib", "-Iinclude", "-o", - "build/libc/string.o", - "sys/libc/string.c" + "build/libn/coro.o", + "sys/libn/coro.c" ], "directory": "/home/nolln/root", - "file": "sys/libc/string.c" + "file": "sys/libn/coro.c" + }, + { + "arguments": [ + "clang", + "-c", + "-g", + "-fno-strict-aliasing", + "-fwrapv", + "-fms-extensions", + "-Iinclude", + "-o", + "build/libn/string.o", + "sys/libn/string.c" + ], + "directory": "/home/nolln/root", + "file": "sys/libn/string.c" } ] \ No newline at end of file diff --git a/include/libn.h b/include/libn.h index 64e2e70..74e230e 100644 --- a/include/libn.h +++ b/include/libn.h @@ -47,6 +47,18 @@ typedef struct bufHdr void* bufgrow(void*, vlong, vlong); void _bufpop(void*, int, vlong); +// ----------------------------------------------------------------------------- +// Memory allocation + +// TODO: Think about interface here. +typedef struct Allocator { + void *(*alloc)(ulong size); + void *(*realloc)(void *ptr, ulong size); + void (*free)(void *ptr); +} Allocator; + +static Allocator mem·sys = { .alloc = &malloc, .realloc = &realloc, .free = &free}; + // ----------------------------------------------------------------------------- // Co-routines diff --git a/sys/rules.mk b/sys/rules.mk index 362edcd..d7ca408 100644 --- a/sys/rules.mk +++ b/sys/rules.mk @@ -4,14 +4,16 @@ DIRSTACK_$(SP) := $(d) d := $(DIR) # Iterate through subdirectory tree + DIR := $(d)/libc include $(DIR)/rules.mk DIR := $(d)/libn include $(DIR)/rules.mk -# ---- Pop off stack ---- --include $(DEPS_$(d)) +DIR := $(d)/libbio +include $(DIR)/rules.mk +# ---- Pop off stack ---- d := $(DIRSTACK_$(SP)) SP := $(basename $(SP)) -- cgit v1.2.1