aboutsummaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
authorNicholas Noll <nbnoll@eml.cc>2021-12-05 15:17:44 -0800
committerNicholas Noll <nbnoll@eml.cc>2021-12-05 15:17:44 -0800
commitb48327d357e0818d1a6ae2a064cfa7d1567e1242 (patch)
tree4677f228a9846937a7ec71c72a1ab63ab69d68ab /include
parentc200dd832789afa298ba45e0b9efdec96c0e92cc (diff)
feat(huge): huge refactor (in progress).
Commented out libc includes to uncover all explicit dependencies. A large fraction has now been ported over (no testing). I did not port over the command line tools, such as the rc shell. These will be done independently - as of now I just want the library to stand independent. Compilation currently fails due to the lack of math functions.
Diffstat (limited to 'include')
-rw-r--r--include/base.h10
-rw-r--r--include/base/fs.h2
-rw-r--r--include/base/io.h3
-rw-r--r--include/base/macro/map.h20
-rw-r--r--include/base/memory.h19
-rw-r--r--include/base/string.h4
-rw-r--r--include/base/utf.h4
-rw-r--r--include/sys.h10
-rw-r--r--include/u.h5
9 files changed, 54 insertions, 23 deletions
diff --git a/include/base.h b/include/base.h
index f7a1024..801b06c 100644
--- a/include/base.h
+++ b/include/base.h
@@ -8,6 +8,13 @@
// TODO: remove dependency system headers
#include <assert.h>
+/* remaining libc functions we depend upon */
+void *malloc(uintptr size);
+void *calloc(uintptr n, uintptr size);
+void *realloc(void *ptr, uintptr size);
+void free(void *ptr);
+void abort(void);
+#if 0
#include <stdlib.h>
#include <string.h>
#include <math.h>
@@ -18,10 +25,11 @@
#include <pwd.h>
#include <unistd.h>
#include <fcntl.h>
-#include <sys/stat.h>
#include <sys/types.h>
typedef wchar_t wchar;
+#endif
+#include <sys/stat.h>
/* must be included first */
#include <base/memory.h>
diff --git a/include/base/fs.h b/include/base/fs.h
index dc6ef9e..0c77f3a 100644
--- a/include/base/fs.h
+++ b/include/base/fs.h
@@ -36,6 +36,6 @@ void fs·fini(fs·Walker *);
void fs·walk(fs·Walker *);
/* small utilities */
-int fs·exists(byte *path, int flag);
+int fs·access(byte *path, int flag);
byte *fs·dirname(byte *path);
byte *fs·basename(byte *path);
diff --git a/include/base/io.h b/include/base/io.h
index 04b596f..8b26761 100644
--- a/include/base/io.h
+++ b/include/base/io.h
@@ -124,3 +124,6 @@ intptr io·offset(io·Header *io);
int io·print(io·Header *io, char *fmt, ...);
int io·vprint(io·Header *io, char *fmt, va_list args);
+
+/* simple i/o */
+int io·puts(char *s);
diff --git a/include/base/macro/map.h b/include/base/macro/map.h
index d7b9e89..1f07eab 100644
--- a/include/base/macro/map.h
+++ b/include/base/macro/map.h
@@ -44,7 +44,7 @@ static const double HASHFILL = 0.77;
#define MAP_RESET(map) \
if((map) && (map)->flag){ \
- memset((map)->flag, 0xAA, map·flagsize((map)->cap)*sizeof(int32)); \
+ mem·set((map)->flag, map·flagsize((map)->cap)*sizeof(int32), 0xAA); \
(map)->len = (map)->occ = 0; \
}
@@ -85,14 +85,14 @@ static const double HASHFILL = 0.77;
else{ \
new_flags = (mem).alloc((heap), map·flagsize(newcap), sizeof(int32)); \
if(!new_flags) return -1; \
- memset(new_flags, 0xaa, map·flagsize(newcap) * sizeof(int32)); \
+ mem·set(new_flags, map·flagsize(newcap) * sizeof(int32), 0xAA); \
if((map)->cap < newcap){ /* expand */ \
key_t *new_keys = (mem).alloc((heap), newcap, sizeof(key_t)); \
if(!new_keys){ \
(mem).free((heap), new_flags); \
return -1; \
} \
- memcpy(new_keys, (map)->key, sizeof(key_t) * (map)->cap); \
+ mem·copy(new_keys, sizeof(key_t) * (map)->cap, (map)->key); \
(mem).free((heap), (map)->key); \
(map)->key = new_keys; \
val_t *new_vals = (mem).alloc((heap), newcap, sizeof(val_t)); \
@@ -100,7 +100,7 @@ static const double HASHFILL = 0.77;
(mem).free((heap), new_flags); \
return -1; \
} \
- memcpy(new_vals, (map)->val, sizeof(val_t) * (map)->cap); \
+ mem·copy(new_vals, sizeof(val_t) * (map)->cap, (map)->val); \
(mem).free((heap), (map)->val); \
(map)->val = new_vals; \
} \
@@ -144,12 +144,12 @@ static const double HASHFILL = 0.77;
} \
if((map)->cap > newcap){ /* shrink the hash table */ \
key_t *new_keys = (mem).alloc((heap), newcap, sizeof(key_t)); \
- memcpy(new_keys, (map)->key, sizeof(key_t) * (map)->cap); \
+ mem·copy(new_keys, sizeof(key_t) * (map)->cap, (map)->key); \
(mem).free((heap), (map)->key); \
(map)->key = new_keys; \
\
val_t *new_vals = (mem).alloc((heap), newcap, sizeof(val_t)); \
- memcpy(new_vals, (map)->val, sizeof(val_t) * (map)->cap); \
+ mem·copy(new_vals, sizeof(val_t) * (map)->cap, (map)->val); \
(mem).free((heap), (map)->val); \
(map)->val = new_vals; \
} \
@@ -240,7 +240,7 @@ static const double HASHFILL = 0.77;
#define SET_RESET(set) \
if ((set) && (set)->flag) { \
- memset((set)->flag, 0xAA, map·flagsize((set)->cap) * sizeof(int32)); \
+ mem·set((set)->flag, map·flagsize((set)->cap) * sizeof(int32), 0xAA); \
(set)->len = (set)->occ = 0; \
}
@@ -281,14 +281,14 @@ static const double HASHFILL = 0.77;
else{ \
new_flags = mem.alloc((heap), map·flagsize(newcap), sizeof(int32)); \
if(!new_flags) return -1; \
- memset(new_flags, 0xaa, map·flagsize(newcap) * sizeof(int32)); \
+ mem·set(new_flags, 0xaa, map·flagsize(newcap) * sizeof(int32)); \
if((set)->cap < newcap) { /* expand */ \
key_t *new_keys = mem.alloc((heap), newcap, sizeof(key_t)); \
if(!new_keys){ \
mem.free((heap), new_flags); \
return -1; \
} \
- memcpy(new_keys, (set)->key, sizeof(key_t) * (set)->cap); \
+ mem·copy(new_keys, sizeof(key_t) * (set)->cap, (set)->key); \
mem.free((heap), (set)->key); \
(set)->key = new_keys; \
} \
@@ -324,7 +324,7 @@ static const double HASHFILL = 0.77;
} \
if((set)->cap > newcap) { /* shrink the hash table */ \
key_t *new_keys = mem.alloc((heap), newcap, sizeof(key_t)); \
- memcpy(new_keys, (set)->key, sizeof(key_t) * (set)->cap); \
+ mem·copy(new_keys, sizeof(key_t) * (set)->cap, (set)->key); \
mem.free((heap), (set)->key); \
(set)->key = new_keys; \
} \
diff --git a/include/base/memory.h b/include/base/memory.h
index 767e948..6bf3cbc 100644
--- a/include/base/memory.h
+++ b/include/base/memory.h
@@ -8,6 +8,7 @@ int mem·move(void *dst, uintptr size, void *src);
int mem·copy(void *dst, uintptr size, void *src);
int mem·compare(void *, uintptr size, void *);
void *mem·findc(void *dst, uintptr len, int c);
+void *mem·rfindc(void *dst, uintptr len, int c);
int mem·set(void *dst, uintptr size, int val);
int mem·set64(void *dst, uintptr size, uint64 val);
@@ -49,23 +50,25 @@ typedef struct mem·Pool mem·Pool;
typedef struct mem·Arena mem·Arena;
typedef struct mem·Allocator {
- void *(*alloc)(void *heap, uint n, ulong size);
- void *(*realloc)(void *iface, void *ptr, uint n, ulong size);
+ void *(*alloc)(void *heap, long n, uintptr size);
+ void *(*realloc)(void *heap, void *ptr, long n, uintptr size);
void (*free)(void *heap, void *ptr);
} mem·Allocator;
-extern mem·Allocator base·Memory; /* standard allocator */
+/* standard allocator */
+extern mem·Allocator base·Memory;
/* pool allocator (manages free list) */
-mem·Pool *mem·makepool(mem·Allocator from, void*);
-void mem·freepool(mem·Pool);
+mem·Pool *mem·makepool(mem·Allocator from, void*, char *name, int flags, intptr maxsize, intptr mincore);
+void mem·freepool(mem·Pool *);
-void *mem·poolalloc(mem·Pool *, uintptr n, uintptr size);
-void *mem·poolrealloc(mem·Pool *, void *, uintptr n, uintptr size);
+void *mem·poolalloc(mem·Pool *, long n, uintptr size);
+void *mem·poolrealloc(mem·Pool *, void *, long n, uintptr size);
void mem·poolfree(mem·Pool *, void *);
/* simple arena allocator (heterogeneous bump) */
mem·Arena *mem·makearena(mem·Allocator from, void*);
-void *mem·arenaalloc(mem·Arena *A, uint n, ulong size);
+void *mem·arenaalloc(mem·Arena *A, long n, ulong size);
void mem·freearena(mem·Arena *A);
+
extern mem·Allocator mem·ArenaAllocator;
diff --git a/include/base/string.h b/include/base/string.h
index a6d6612..238ebf9 100644
--- a/include/base/string.h
+++ b/include/base/string.h
@@ -9,6 +9,10 @@ char *str·findc(char *s, int c);
char *str·nfindc(char *s, intptr n, int c);
char *str·efindc(char *s, char *e, int c);
+char *str·rfindc(char *s, int c);
+char *str·nrfindc(char *s, intptr n, int c);
+char *str·erfindc(char *s, char *e, int c);
+
char *str·find(char *s, char *sub);
char *str·nfind(char *s, intptr n, char *sub);
char *str·efind(char *s, char *e, char *sub);
diff --git a/include/base/utf.h b/include/base/utf.h
index 0419d1a..19f345f 100644
--- a/include/base/utf.h
+++ b/include/base/utf.h
@@ -21,7 +21,7 @@ int utf8·encode(rune *, char *); // encode 1 rune from rune stream, s
int utf8·decodeprev(char *s, rune *r); // decode 1 rune from char stream, reading backwards, store into rune, return number of bytes
char *utf8·find(char *s, rune); // find rune in char stream
-char *utf8·findlast(char* s, rune); // find last rune in char stream
+char *utf8·rfind(char* s, rune); // find last rune in char stream
int utf8·fullrune(char *, int); // XXX: odd function...
@@ -30,6 +30,8 @@ int utf8·isdigit(rune r);
int utf8·isspace(rune r);
int utf8·istitle(rune r);
int utf8·ispunct(rune r);
+int utf8·isupper(rune r);
+int utf8·islower(rune r);
rune utf8·toupper(rune r);
rune utf8·tolower(rune r);
diff --git a/include/sys.h b/include/sys.h
index e983f2a..95ed93c 100644
--- a/include/sys.h
+++ b/include/sys.h
@@ -35,11 +35,15 @@ char *sys·errormsg(int num);
/* file operations */
int sys·open(char *path, int flag, int mode, int *fd);
+int sys·openat(int dirfd, char *path, int flags, int mode, int *fd);
int sys·close(int fd);
-int sys·write(int fd, uintptr len, void *buf, intptr *nw);
-int sys·read(int fd, uintptr len, void *buf, intptr *nr);
+int sys·write(int fd, void *buf, uintptr len, intptr *nw);
+int sys·read(int fd, void *buf, uintptr len, intptr *nr);
int sys·seek(int fd, intptr offset, int from, intptr *pos);
+int sys·access(char *path, int mode);
+int sys·accessat(int dirfd, char *path, int mode, int flags);
+
int sys·info(char *path, sys·Info *ret);
int sys·infofd(int fd, sys·Info *ret);
int sys·infoat(int dirfd, char *path, int flag, uint mask, sys·Info *ret);
@@ -47,6 +51,8 @@ int sys·infoat(int dirfd, char *path, int flag, uint mask, sys·Info *ret);
int sys·dup(int from, int to);
/* directory operations */
+int sys·cwd(char *buf, uintptr size);
+
int sys·chdir(char *path);
int sys·chdirfd(int fd);
int sys·mkdir(char *path, uint mode);
diff --git a/include/u.h b/include/u.h
index fe251ac..01741f8 100644
--- a/include/u.h
+++ b/include/u.h
@@ -61,6 +61,7 @@ typedef __builtin_va_list va_list;
#define true 1
#define false 0
#define nil ((void*)0)
+#define EOF (-1)
/* limits */
#define CHAR_BIT 8
@@ -105,6 +106,10 @@ typedef __builtin_va_list va_list;
#define PATH_MAX 4096
+#define NAN (0.0f/0.0f)
+#define INFINITY 1e5000f
+#define HUGE_VAL ((double)INFINITY)
+
// ------------------------------------------------------------------
// global macros