aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNicholas Noll <nbnoll@eml.cc>2020-04-19 09:29:12 -0700
committerNicholas Noll <nbnoll@eml.cc>2020-04-19 09:29:12 -0700
commitdf2a9476a1767bdce83e081470b31ffb89749034 (patch)
treeab7fea866bbab3b4ac77ac720b9e92fcf9ea5710
parent60ce7fba21a6d37c0acbe152039fbc3d0e692bf0 (diff)
chore: reorganized header structure and updated makefile
-rw-r--r--Makefile2
-rw-r--r--include/.include/map.h (renamed from include/map.h)0
-rw-r--r--include/.include/str.h (renamed from include/str.h)0
-rw-r--r--include/libn.h74
-rw-r--r--include/u.h74
-rw-r--r--sys/rules.mk3
6 files changed, 80 insertions, 73 deletions
diff --git a/Makefile b/Makefile
index f276d13..1a21e76 100644
--- a/Makefile
+++ b/Makefile
@@ -5,7 +5,7 @@ AS := nasm
# All needed build directories
INC_DIR := include
-SRC_DIR := src
+SRC_DIR := sys
BIN_DIR := bin
LIB_DIR := lib
OBJ_DIR := build
diff --git a/include/map.h b/include/.include/map.h
index f81dc0f..f81dc0f 100644
--- a/include/map.h
+++ b/include/.include/map.h
diff --git a/include/str.h b/include/.include/str.h
index 85051e4..85051e4 100644
--- a/include/str.h
+++ b/include/.include/str.h
diff --git a/include/libn.h b/include/libn.h
new file mode 100644
index 0000000..aad359e
--- /dev/null
+++ b/include/libn.h
@@ -0,0 +1,74 @@
+#pragma once
+
+// ------------------------------------------------------------------------
+// Standard library
+
+#include <assert.h>
+#include <stdlib.h>
+#include <string.h>
+#include <math.h>
+#include <ctype.h>
+#include <stdio.h>
+
+#include <unistd.h>
+#include <sys/stat.h>
+#include <sys/types.h>
+#include <fcntl.h>
+
+// ----------------------------------------------------------------------------
+// Dynamic array.
+
+typedef struct bufHdr
+{
+ vlong len;
+ vlong cap;
+ byte buf[];
+} bufHdr;
+
+#define _bufHdr(s) ((bufHdr*)((uint8*)(s)-offsetof(bufHdr, buf)))
+#define buflen(s) ((s) ? (_bufHdr(s)->len) : 0)
+#define bufcap(s) ((s) ? (_bufHdr(s)->cap) : 0)
+#define bufend(s) ((s) + buflen(s))
+#define bufsize(s) ((s) ? (buflen(s) * sizeof((s)[0])) : 0)
+
+#define buffree(s) ((s) ? (free(_bufHdr(s)), (s) = nil) : 0)
+#define buffit(s, n) ((n) <= bufcap(s) ? 0 : ((s) = bufgrow((s), (n), sizeof(*(s)))))
+
+#define bufresize(s, n) \
+ do { \
+ (buffit(s, n)); \
+ ((_bufHdr(s)->len) = (n)); \
+ } while (0)
+
+#define bufpush(s, ...) (buffit((s), 1 + buflen(s)), (s)[_bufHdr(s)->len++] = (__VA_ARGS__))
+
+#define bufpop(s, i) (_bufpop((s), (i), sizeof(*(s))), (s)[_bufHdr(s)->len])
+
+void* bufgrow(void*, vlong, vlong);
+void _bufpop(void*, int, vlong);
+
+// -----------------------------------------------------------------------------
+// Co-routines
+
+typedef struct coro coro;
+
+coro* coro·new(uintptr stk, uintptr (*func)(coro*, uintptr));
+uintptr coro·yield(coro *c, uintptr arg);
+error coro·free(coro *c);
+
+// -----------------------------------------------------------------------------
+// Strings
+
+#include ".include/str.h"
+
+// -----------------------------------------------------------------------------
+// Maps or dictionaries
+
+#include ".include/map.h"
+
+// -----------------------------------------------------------------------------
+// Error handling functions.
+
+void errorf(const byte* fmt, ...);
+
+#define panicf(...) (errorf(__VA_ARGS__), assert(0))
diff --git a/include/u.h b/include/u.h
index c03d545..28bc2e4 100644
--- a/include/u.h
+++ b/include/u.h
@@ -1,27 +1,15 @@
#pragma once
// ------------------------------------------------------------------------
-// Standard library
+// Freestanding headers
+#include <stdarg.h>
#include <stdint.h>
#include <stddef.h>
#include <stdbool.h>
-#include <stdarg.h>
#include <float.h>
#include <limits.h>
-#include <assert.h>
-#include <stdlib.h>
-#include <string.h>
-#include <math.h>
-#include <ctype.h>
-#include <stdio.h>
-
-#include <unistd.h>
-#include <sys/stat.h>
-#include <sys/types.h>
-#include <fcntl.h>
-
// ------------------------------------------------------------------------
// Modern type aliases
@@ -55,57 +43,6 @@ typedef void* Iface;
#define nil NULL
-// ----------------------------------------------------------------------------
-// Dynamic array.
-
-typedef struct bufHdr
-{
- vlong len;
- vlong cap;
- byte buf[];
-} bufHdr;
-
-#define _bufHdr(s) ((bufHdr*)((uint8*)(s)-offsetof(bufHdr, buf)))
-#define buflen(s) ((s) ? (_bufHdr(s)->len) : 0)
-#define bufcap(s) ((s) ? (_bufHdr(s)->cap) : 0)
-#define bufend(s) ((s) + buflen(s))
-#define bufsize(s) ((s) ? (buflen(s) * sizeof((s)[0])) : 0)
-
-#define buffree(s) ((s) ? (free(_bufHdr(s)), (s) = nil) : 0)
-#define buffit(s, n) ((n) <= bufcap(s) ? 0 : ((s) = bufgrow((s), (n), sizeof(*(s)))))
-
-#define bufresize(s, n) \
- do { \
- (buffit(s, n)); \
- ((_bufHdr(s)->len) = (n)); \
- } while (0)
-
-#define bufpush(s, ...) (buffit((s), 1 + buflen(s)), (s)[_bufHdr(s)->len++] = (__VA_ARGS__))
-
-#define bufpop(s, i) (_bufpop((s), (i), sizeof(*(s))), (s)[_bufHdr(s)->len])
-
-void* bufgrow(void*, vlong, vlong);
-void _bufpop(void*, int, vlong);
-
-// -----------------------------------------------------------------------------
-// Co-routines
-
-typedef struct coro coro;
-
-coro* coro·new(uintptr stk, uintptr (*func)(coro*, uintptr));
-uintptr coro·yield(coro *c, uintptr arg);
-error coro·free(coro *c);
-
-// -----------------------------------------------------------------------------
-// Strings
-
-#include "str.h"
-
-// -----------------------------------------------------------------------------
-// Maps or dictionaries
-
-#include "map.h"
-
// ------------------------------------------------------------------
// Global macros
@@ -119,10 +56,3 @@ error coro·free(coro *c);
#define MAX(x, y) ((x) >= (y) ? (x) : (y))
#define MIN(x, y) ((x) < (y) ? (x) : (y))
-
-// -----------------------------------------------------------------------------
-// Error handling functions.
-
-void errorf(const byte* fmt, ...);
-
-#define panicf(...) (errorf(__VA_ARGS__), assert(0))
diff --git a/sys/rules.mk b/sys/rules.mk
index b4b0159..90a2d96 100644
--- a/sys/rules.mk
+++ b/sys/rules.mk
@@ -7,6 +7,9 @@ d := $(DIR)
DIR := $(d)/libc
include $(DIR)/rules.mk
+DIR := $(d)/libn
+include $(DIR)/rules.mk
+
DIR := $(d)/cc
include $(DIR)/rules.mk