aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNicholas Noll <nbnoll@eml.cc>2020-04-21 12:38:03 -0700
committerNicholas Noll <nbnoll@eml.cc>2020-04-21 12:38:03 -0700
commitaa064359cb514251a73b53de3e530fa89f687ab7 (patch)
tree0e16ab88b16c26dbda88a1349adf61331521ac60
parent06f60ae1b3c7d11092a5433186360fcbb1221309 (diff)
feat: added allocator interface to allow for flexible library interfaces
-rw-r--r--.gitignore1
-rwxr-xr-xbin/initmk2
-rw-r--r--compile_commands.json68
-rw-r--r--include/libn.h12
-rw-r--r--sys/rules.mk6
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
@@ -48,6 +48,18 @@ 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
typedef struct Coro Coro;
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))