aboutsummaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
authorNicholas <nbnoll@eml.cc>2021-11-11 17:07:44 -0800
committerNicholas <nbnoll@eml.cc>2021-11-11 17:07:44 -0800
commitb375f3cdedb5b0e08745d100b40e38d2f8396a58 (patch)
treea51d5763646ff482c26e79bfc1dcebccbe4812a7 /include
parent44b30ea0883af2827e618a45d472b47cf041a842 (diff)
parent9695ea005d4af93dcd60f74f10fd3c54499a182f (diff)
chore: merge master into laptop
Diffstat (limited to 'include')
-rw-r--r--include/base.h53
-rw-r--r--include/libfmt.h50
-rw-r--r--include/libutf.h2
3 files changed, 59 insertions, 46 deletions
diff --git a/include/base.h b/include/base.h
index b841040..ca229b3 100644
--- a/include/base.h
+++ b/include/base.h
@@ -51,7 +51,6 @@ void* ·bufgrow(void*, vlong, vlong);
// -----------------------------------------------------------------------------
// memory allocation
-// TODO(nnoll): Allow for nil iterfaces?
/* allocator interface */
typedef struct mem·Allocator {
void *(*alloc)(void *heap, uint n, ulong size);
@@ -66,7 +65,7 @@ typedef struct mem·Reallocator {
void (*free)(void *iface, void *ptr);
} mem·Reallocator;
-extern mem·Reallocator sys·Relocator;
+extern mem·Reallocator sys·FullMemory;
/* simple memory arena */
typedef struct mem·Arena mem·Arena;
@@ -94,23 +93,23 @@ error coro·free(Coro *c);
typedef byte* string;
-/* string helpers */
-string str·makecap(const byte *s, vlong len, vlong cap);
-string str·makelen(const byte *s, vlong len);
-string str·make(const byte *s);
-string str·makef(const byte *fmt, ...);
+/* augmented string functions */
+string str·makecap(const char *s, vlong len, vlong cap);
+string str·makelen(const char *s, vlong len);
+string str·make(const char *s);
+string str·makef(const char *fmt, ...);
void str·free(string s);
int str·len(const string s);
int str·cap(const string s);
void str·clear(string *s);
void str·grow(string *s, vlong delta);
void str·fit(string *s);
-int str·appendlen(string *s, vlong len, const byte *b);
-int str·append(string *s, const byte* b);
-int str·appendf(string *s, const byte* fmt, ...);
-int str·appendbyte(string *s, const byte b);
+int str·appendlen(string *s, vlong len, const char *b);
+int str·append(string *s, const char *b);
+int str·appendf(string *s, const char *fmt, ...);
+int str·appendbyte(string *s, const char b);
bool str·equals(const string s, const string t);
-int str·find(string s, const byte* substr);
+int str·find(string s, const char* substr);
void str·lower(string s);
void str·upper(string s);
int str·read(string s, int size, int n, void *buf);
@@ -118,6 +117,9 @@ void str·replace(string s, const byte* from, const byte* to);
string* str·split(string s, const byte* tok);
string str·join(vlong len, byte** fields, const byte* sep);
+/* raw C string functions */
+char *str·copyn(char *dst, char *src, int n);
+
// -----------------------------------------------------------------------------
// i/o
@@ -366,22 +368,22 @@ void vpanicf(byte *fmt, va_list args);
// -----------------------------------------------------------------------------
// sorting
-void sort·ints(uintptr n, int arr[]);
-void sort·int8s(uintptr n, int8 arr[]);
-void sort·int16s(uintptr n, int16 arr[]);
-void sort·int32s(uintptr n, int32 arr[]);
-void sort·int64s(uintptr n, int64 arr[]);
+void sort·int(uintptr n, int arr[]);
+void sort·int8(uintptr n, int8 arr[]);
+void sort·int16(uintptr n, int16 arr[]);
+void sort·int32(uintptr n, int32 arr[]);
+void sort·int64(uintptr n, int64 arr[]);
-void sort·uints(uintptr n, uint arr[]);
-void sort·uint8s(uintptr n, uint8 arr[]);
-void sort·uint16s(uintptr n, uint16 arr[]);
-void sort·uint32s(uintptr n, uint32 arr[]);
-void sort·uint64s(uintptr n, uint64 arr[]);
+void sort·uint(uintptr n, uint arr[]);
+void sort·uint8(uintptr n, uint8 arr[]);
+void sort·uint16(uintptr n, uint16 arr[]);
+void sort·uint32(uintptr n, uint32 arr[]);
+void sort·uint64(uintptr n, uint64 arr[]);
-void sort·floats(uintptr n, float arr[]);
-void sort·doubles(uintptr n, double arr[]);
+void sort·float(uintptr n, float arr[]);
+void sort·double(uintptr n, double arr[]);
-void sort·strings(uintptr n, byte* arr[]);
+void sort·string(uintptr n, byte* arr[]);
// -----------------------------------------------------------------------------
// fast random number generation
@@ -390,6 +392,7 @@ error rng·init(uint64 seed);
double rng·random(void);
double rng·exponential(double lambda);
bool rng·bernoulli(double f);
+double rng·normal(void);
uint64 rng·randi(int max);
uint64 rng·poisson(double mean);
diff --git a/include/libfmt.h b/include/libfmt.h
index 17effc6..7ba40a0 100644
--- a/include/libfmt.h
+++ b/include/libfmt.h
@@ -9,13 +9,21 @@ struct fmt·State
char *cur;
char *end;
} buffer;
- int (*flush)(fmt·State *);
int n;
+
va_list args;
rune verb;
ulong flag;
int width;
int prec;
+ char *thousands, *groups, *decimal;
+
+ void *file;
+ int (*flush)(fmt·State *);
+ struct {
+ void *heap;
+ mem·Reallocator mem;
+ };
};
#define iota(x) (1 << (x))
@@ -41,22 +49,24 @@ enum
#undef iota
/* normal printing interface */
-int fmt·print(char *fmt, ...);
-int fmt·fprint(int fd, char *fmt, ...);
-
-int fmt·sprint(char *buf, char *fmt, ...);
-int fmt·nsprint(int len, char *buf, char *fmt, ...);
-int fmt·esprint(char *buf, char *end, char *fmt, ...);
-
-int fmt·vprint(char *fmt, va_list args);
-int fmt·vfprint(int fd, char *fmt, va_list args);
-int fmt·vwrite(char *buf, char *fmt, va_list args);
-int fmt·vnwrite(int len, char *buf, char *fmt, va_list args);
-int fmt·vewrite(char *buf, char *end, char *fmt, va_list args);
-
-/* low-level interface: custom printing verbs */
-int fmt·do(fmt·State *, char *fmt);
-int fmt·put(fmt·State *, char *fmt, ...);
-int fmt·vput(fmt·State *, char *fmt, va_list args);
-int fmt·install(fmt·State *, int (*put)(fmt·State*));
-int fmt·flush(fmt·State *);
+int fmt·print(char *fmt, ...);
+int fmt·fprint(int fd, char *fmt, ...);
+
+int fmt·sprint(char *buf, char *fmt, ...);
+int fmt·nsprint(int len, char *buf, char *fmt, ...);
+char *fmt·esprint(char *buf, char *end, char *fmt, ...);
+
+int fmt·vprint(char *fmt, va_list args);
+int fmt·vfprint(int fd, char *fmt, va_list args);
+int fmt·vnsprint(int len, char *buf, char *fmt, va_list args);
+char *fmt·vesprint(char *buf, char *end, char *fmt, va_list args);
+
+/* low-level interface: used for custom printing verbs */
+int fmt·open(int fd, int len, char *buf, fmt·State *); // creates a buffer on a file
+int fmt·make(mem·Reallocator mem, void *heap, fmt·State *); // creates an in-memory buffer
+void fmt·free(fmt·State *); // releases an in-memory buffer
+
+int fmt·do(fmt·State *, char *fmt);
+int fmt·write(fmt·State *, char *fmt, ...);
+int fmt·vwrite(fmt·State *, char *fmt, va_list args);
+int fmt·install(int c, int (*format)(fmt·State *));
diff --git a/include/libutf.h b/include/libutf.h
index d6618eb..25d6dee 100644
--- a/include/libutf.h
+++ b/include/libutf.h
@@ -27,7 +27,7 @@ char *utf8·findlast(char* s, rune); // find last rune in char stream
int utf8·canfit(char *, int); // XXX: odd function...
-int utf8·isletter(rune r);
+int utf8·isalpha(rune r);
int utf8·isdigit(rune r);
int utf8·isspace(rune r);
int utf8·istitle(rune r);