aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorNicholas <nbnoll@eml.cc>2021-11-20 11:55:55 -0800
committerNicholas <nbnoll@eml.cc>2021-11-20 12:34:01 -0800
commite97c8c469db0aa27985dab2879dc1f14905c7387 (patch)
treef10f7ed68f1ad5212eebb0985ef040c5e96235ba /src
parenta9bfe650038afea8b751175cac16f6027345e45f (diff)
chore: simplify makefiles
Diffstat (limited to 'src')
-rw-r--r--src/base/bufio/dump.c66
-rw-r--r--src/base/bufio/get.c17
-rw-r--r--src/base/bufio/internal.h2
-rw-r--r--src/base/bufio/read.c36
-rw-r--r--src/base/bufio/reader.c28
-rw-r--r--src/base/bufio/refill.h28
-rw-r--r--src/base/bufio/rules.mk10
-rw-r--r--src/base/bufio/unget.c18
-rw-r--r--src/base/fmt/do.c6
-rw-r--r--src/base/fmt/float.c12
-rw-r--r--src/base/fmt/open.c5
-rw-r--r--src/base/fmt/rules.mk3
-rw-r--r--src/base/fmt/test.c2
-rw-r--r--src/base/rules.mk9
-rw-r--r--src/base/test.c112
-rw-r--r--src/base/utf/rules.mk9
-rw-r--r--src/cmd/rules.mk3
-rw-r--r--src/rules.mk8
18 files changed, 32 insertions, 342 deletions
diff --git a/src/base/bufio/dump.c b/src/base/bufio/dump.c
deleted file mode 100644
index 0b527e2..0000000
--- a/src/base/bufio/dump.c
+++ /dev/null
@@ -1,66 +0,0 @@
-// -----------------------------------------------------------------------
-// reader
-
-#if 0
-rune
-bufio·getrune(io·Buffer *buf)
-{
- ubyte b;
- int i;
- byte str[UTFmax+1];
- rune r;
-
- // NOTE: I'm worried about the sign here...
- b = bufio·getbyte(buf);
- if (b < RuneSelf) {
- buf->runesize = 1;
- return b;
- }
-
- i = 0;
- str[i++] = b;
-
-nextbyte:
- b = bufio·getbyte(buf);
- if (b < 0) return b;
- if (i >= arrlen(str)) return RuneErr;
- str[i++] = b;
- if (!utf8·fullrune(str, i))
- goto nextbyte;
-
- buf->runesize = utf8·bytetorune(&r, str);
- if (r == RuneErr && b == 1) {
- errorf("illegal UTF-8 sequence");
- for (; i >= 0; i--)
- errorf("%s%.2x", i > 0 ? " " : "", *(ubyte*)(str+i));
- errorf("\n");
-
- buf->runesize = 0;
- } else
- for (; i > buf->runesize; i--)
- bufio·ungetbyte(buf, str[i]);
-
- return r;
-}
-
-// TODO: Check that we are given the correct rune!
-error
-bufio·ungetrune(io·Buffer *buf, rune r)
-{
- if (buf->state & bufio·rdr) {
- errorf("attempted to unget on non-active reader");
- return bufio·err;
- }
-
- if (buf->pos == buf->buf) {
- errorf("attempted to unget past end of buffer");
- return bufio·err;
- }
-
- buf->pos -= buf->runesize;
- return 0;
-}
-#endif
-
-// -----------------------------------------------------------------------
-// writer
diff --git a/src/base/bufio/get.c b/src/base/bufio/get.c
deleted file mode 100644
index 9f10c88..0000000
--- a/src/base/bufio/get.c
+++ /dev/null
@@ -1,17 +0,0 @@
-#include "internal.h"
-#include "refill.h"
-
-int
-bufio·getbyte(io·Buffer *buf)
-{
-getbyte:
- if(buf->pos < buf->end)
- return *buf->pos++;
-
- memmove(buf->buf, buf->end - bufio·ungets, bufio·ungets);
-
- if(refill(buf) <= 0)
- return bufio·eof;
-
- goto getbyte;
-}
diff --git a/src/base/bufio/internal.h b/src/base/bufio/internal.h
index 302c035..a1a006a 100644
--- a/src/base/bufio/internal.h
+++ b/src/base/bufio/internal.h
@@ -1,4 +1,2 @@
-#pragma once
-
#include <u.h>
#include <base.h>
diff --git a/src/base/bufio/read.c b/src/base/bufio/read.c
deleted file mode 100644
index 09a9f83..0000000
--- a/src/base/bufio/read.c
+++ /dev/null
@@ -1,36 +0,0 @@
-#include "internal.h"
-#include "refill.h"
-
-int
-bufio·read(io·Buffer *buf, int sz, int n, void *out)
-{
- byte *wtr;
- int nr, rem, diff;
-
- if(n == 0 || buf->state & bufio·end)
- return bufio·err;
-
- assert(buf->state & bufio·rdr);
-
- wtr = out;
- rem = n*sz;
-
- while(rem > 0){
- diff = buf->end - buf->pos;
- nr = MIN(diff, rem);
- if(!nr){
- if(buf->state & bufio·end)
- break;
- if(refill(buf) <= 0)
- break;
-
- continue;
- }
- memmove(wtr, buf->pos, nr);
- wtr += nr;
- buf->pos += nr;
- rem -= nr;
- }
-
- return n - rem/sz;
-}
diff --git a/src/base/bufio/reader.c b/src/base/bufio/reader.c
deleted file mode 100644
index 39ea63e..0000000
--- a/src/base/bufio/reader.c
+++ /dev/null
@@ -1,28 +0,0 @@
-#include "internal.h"
-
-int
-bufio·initreader(io·Buffer *buf, io·Reader rdr, void *h)
-{
- if (buf->state) {
- errorf("attemped to initialize an active buffer, state is '%d'", buf->state);
- return bufio·err;
- }
- buf->state = bufio·rdr;
- buf->runesize = 0;
- buf->h = h;
- buf->rdr = rdr;
- buf->beg = buf->buf + bufio·ungets;
- buf->pos = buf->beg;
- buf->end = buf->pos;
- buf->size = bufio·size - bufio·ungets;
-
- return 0;
-}
-
-void
-bufio·finireader(io·Buffer *buf)
-{
- buf->state = bufio·nil;
- buf->runesize = 0;
- buf->rdr = (io·Reader){ .read = nil };
-}
diff --git a/src/base/bufio/refill.h b/src/base/bufio/refill.h
deleted file mode 100644
index 41e357e..0000000
--- a/src/base/bufio/refill.h
+++ /dev/null
@@ -1,28 +0,0 @@
-int
-refill(io·Buffer *buf)
-{
- int n;
-
- if(buf->state & bufio·end)
- return bufio·err;
-
- memcpy(buf->buf, buf->pos - bufio·ungets, bufio·ungets);
-
- n = buf->rdr.read(buf->h, 1, buf->size, buf->beg);
- if(n < 0)
- return bufio·err;
- if(n == 0){
- buf->state |= bufio·end;
- return 0;
- }
-
- buf->pos = buf->beg;
- buf->end = buf->pos + n;
-
- // TEST: put a physical EOF byte at the end
- // this would allow for an unget operation
- if(n < buf->size)
- *buf->end++ = EOF;
-
- return n;
-}
diff --git a/src/base/bufio/rules.mk b/src/base/bufio/rules.mk
index 84f283f..8089e77 100644
--- a/src/base/bufio/rules.mk
+++ b/src/base/bufio/rules.mk
@@ -1,5 +1,5 @@
-SRCS_$(d)+=\
- $(d)/bufio/get.c\
- $(d)/bufio/read.c\
- $(d)/bufio/reader.c\
- $(d)/bufio/unget.c\
+# SRCS_$(d)+=\
+# $(d)/bufio/get.c\
+# $(d)/bufio/read.c\
+# $(d)/bufio/reader.c\
+# $(d)/bufio/unget.c\
diff --git a/src/base/bufio/unget.c b/src/base/bufio/unget.c
deleted file mode 100644
index 1951384..0000000
--- a/src/base/bufio/unget.c
+++ /dev/null
@@ -1,18 +0,0 @@
-#include "internal.h"
-
-int
-bufio·ungetbyte(io·Buffer *buf, byte c)
-{
- if(!(buf->state & bufio·rdr)) {
- errorf("attempted to unget on non-active reader");
- return bufio·err;
- }
-
- if(buf->pos == buf->buf) {
- errorf("attempted to unget past end of buffer");
- return bufio·err;
- }
-
- buf->pos--;
- return 0;
-}
diff --git a/src/base/fmt/do.c b/src/base/fmt/do.c
index bd2e65c..71b005e 100644
--- a/src/base/fmt/do.c
+++ b/src/base/fmt/do.c
@@ -363,9 +363,9 @@ fmtstring(fmt·State *io)
static int
fmterror(fmt·State *io)
{
- char *s;
- s = strerror(errno);
- return copystring(io, s);
+ int c;
+ c = va_arg(io->args, int);
+ return copystring(io, sys·errormsg(c));
}
static int
diff --git a/src/base/fmt/float.c b/src/base/fmt/float.c
index 63ea80f..8a42dfc 100644
--- a/src/base/fmt/float.c
+++ b/src/base/fmt/float.c
@@ -529,7 +529,7 @@ fmtstrtod(char *as, char **aas)
ex = -ex;
dp += ex;
if(dp < -Maxe){
- errno = ERANGE;
+ /* errno = ERANGE; */
goto ret0; /* underflow by exp */
} else
if(dp > +Maxe)
@@ -617,7 +617,7 @@ retnan:
retinf:
/* Unix strtod requires these. Plan 9 would return Inf(0) or Inf(-1). */
- errno = ERANGE;
+ /* errno = ERANGE; */
if(flag & Fsign)
return -HUGE_VAL;
return HUGE_VAL;
@@ -630,7 +630,7 @@ out:
d = -d;
d = ldexp(d, bp - Prec*Nbits);
if(d == 0) /* underflow */
- errno = ERANGE;
+ /* errno = ERANGE; */
return d;
}
@@ -694,12 +694,10 @@ fmtexp(char *p, int e, int ucase)
static void
dtoa(double f, char *s, int *exp, int *neg, int *len)
{
- int c, d, e2, e, ee, i, ndigit, oerrno;
+ int c, d, e2, e, ee, i, ndigit;
char buf[NSIGNIF+10];
double g;
- oerrno = errno;
-
*neg = 0;
if(f < 0){
f = -f;
@@ -785,7 +783,7 @@ dtoa(double f, char *s, int *exp, int *neg, int *len)
*exp = e;
*len = ndigit;
- errno = oerrno;
+ /* errno = oerrno; */
}
diff --git a/src/base/fmt/open.c b/src/base/fmt/open.c
index 8aadef5..b6829bb 100644
--- a/src/base/fmt/open.c
+++ b/src/base/fmt/open.c
@@ -3,11 +3,12 @@
static int
flush(fmt·State *io)
{
- int n, fd;
+ int fd;
+ intptr n;
fd = (uintptr)io->file;
n = io->buffer.cur - io->buffer.beg;
- if(n && write(fd, io->buffer.beg, n) != n)
+ if(n && sys·write(fd, n, io->buffer.beg, &n))
return -1;
io->buffer.cur = io->buffer.beg;
diff --git a/src/base/fmt/rules.mk b/src/base/fmt/rules.mk
index fdfdac0..8effa9e 100644
--- a/src/base/fmt/rules.mk
+++ b/src/base/fmt/rules.mk
@@ -17,5 +17,4 @@ SRCS_$(d)+=\
$(d)/fmt/panic.c\
$(d)/fmt/write.c
-CHECK_$(d)+=\
- $(d)/fmt/test.c
+TEST += $(TST_DIR)/base/fmt/test
diff --git a/src/base/fmt/test.c b/src/base/fmt/test.c
index d81a62e..73f5e7c 100644
--- a/src/base/fmt/test.c
+++ b/src/base/fmt/test.c
@@ -1,7 +1,5 @@
#include <u.h>
#include <base.h>
-#include <libutf.h>
-#include <libfmt.h>
typedef struct Complex
{
diff --git a/src/base/rules.mk b/src/base/rules.mk
index 0a262c7..64f0797 100644
--- a/src/base/rules.mk
+++ b/src/base/rules.mk
@@ -6,9 +6,6 @@ include share/push.mk
SRCS_$(d):=\
$(d)/arg.c
-CHECK_$(d):=\
- $(d)/test.c
-
include $(d)/bufio/rules.mk
include $(d)/coro/rules.mk
include $(d)/error/rules.mk
@@ -28,13 +25,11 @@ include $(d)/utf/rules.mk
# outputs
LIBS_$(d) := $(d)/base.a
+TEST += $(TST_DIR)/base/test
+
include share/paths.mk
$(LIBS_$(d)): $(OBJS_$(d))
$(ARCHIVE)
-$(TEST_$(d)): TLIBS = $(LIBS_$(d))
-$(TEST_$(d)): $(UNIT_$(d)) $(LIBS_$(d))
- $(LINK)
-
include share/pop.mk
diff --git a/src/base/test.c b/src/base/test.c
index a29be1d..de53125 100644
--- a/src/base/test.c
+++ b/src/base/test.c
@@ -4,111 +4,6 @@
#include <time.h>
-uintptr
-printtest(Coro *c, uintptr d)
-{
- printf("--> Recieved %lu\n", d);
- d = coro·yield(c, d+10);
- printf("--> Now %lu\n", d);
-
- return d;
-}
-
-uintptr
-sequence(Coro *c, uintptr start)
-{
- int d = start;
- for (;;) {
- coro·yield(c, d++);
- }
-
- return d;
-}
-
-struct PrimeMsg
-{
- Coro *seq;
- int p;
-};
-
-uintptr
-filter(Coro *c, uintptr data)
-{
- int x, p;
- Coro *seq;
- struct PrimeMsg *msg;
-
- // Need to copy relevant variables onto the local stack
- // Data is volatile.
- msg = (struct PrimeMsg*)data;
- seq = msg->seq;
- p = msg->p;
-
- for (;;) {
- x = coro·yield(seq, x);
- if (x % p != 0) {
- x = coro·yield(c, x);
- }
- }
-
- return 0;
-}
-
-error
-test·coro()
-{
- int i;
- Coro *c[4];
- uintptr d;
-
- printf("Starting singleton test\n");
-
- for (i = 0; i < arrlen(c); i++) {
- c[i] = coro·make(0, &printtest);
- }
-
- /* Singleton test */
- d = 0;
- for (i = 0; i < 10; i++) {
- d = coro·yield(c[0], d);
- }
-
- printf("Starting triplet test\n");
-
- /* Triplet test */
- for (i = 0; i < 10; i++) {
- d = coro·yield(c[1], d);
- d = coro·yield(c[2], d+100);
- d = coro·yield(c[3], d+200);
- }
-
- for (i = 0; i < arrlen(c); i++) {
- coro·free(c[i]);
- }
-
- /* Prime sieve */
- printf("Starting prime test\n");
- uintptr num;
- Coro *cur, *seq[50];
-
- num = 2;
- seq[0] = coro·make(4096, &sequence);
- cur = *seq;
-
- num = coro·yield(cur, num);
- for (i = 1; i < arrlen(seq); i++) {
- seq[i] = coro·make(4096, &filter);
- struct PrimeMsg msg = {
- .seq = cur,
- .p = num,
- };
- cur = seq[i];
- num = coro·yield(cur, (uintptr)&msg);
- printf("--> prime number %lu\n", num);
- }
- return 0;
-}
-
int
less(void* a, void* b)
{
@@ -119,7 +14,7 @@ less(void* a, void* b)
return ai - bi;
}
-error
+int
test·sort()
{
clock_t t;
@@ -155,10 +50,10 @@ test·sort()
return 0;
}
-error
+int
main()
{
- error err;
+ int err;
#if 0
if (err = test·coro(), err) {
errorf("test fail: coroutine");
@@ -167,4 +62,5 @@ main()
if (err = test·sort(), err) {
errorf("test fail: coroutine");
}
+ return 0;
}
diff --git a/src/base/utf/rules.mk b/src/base/utf/rules.mk
index 446c113..dfe2da1 100644
--- a/src/base/utf/rules.mk
+++ b/src/base/utf/rules.mk
@@ -22,7 +22,8 @@ NEED_OBJS=\
$(OBJ_DIR)/base/error/panicf.o\
$(OBJ_DIR)/base/io/readln.o\
$(OBJ_DIR)/base/io/open.o\
- $(OBJ_DIR)/base/io/close.o
+ $(OBJ_DIR)/base/io/close.o\
+ $(d)/utf/vendor/common.o
$(d)/utf/vendor/common.o: $(d)/utf/vendor/common.c
$(COMPILE)
@@ -32,7 +33,7 @@ $(d)/utf/vendor/UnicodeData-$(UNICODE).txt:
@echo "GET UnicodeData.txt";\
curl https://www.unicode.org/Public/$(UNICODE)/ucd/UnicodeData.txt > $@
-$(d)/utf/vendor/mkrunetype: $(d)/utf/vendor/mkrunetype.c $(d)/utf/vendor/common.o $(NEED_OBJS)
+$(d)/utf/vendor/mkrunetype: $(d)/utf/vendor/mkrunetype.c $(NEED_OBJS) | $(RUNTIME) $(SYS)
$(COMPLINK)
GENS += $(d)/utf/vendor/mkrunetype
@@ -49,7 +50,7 @@ $(d)/utf/vendor/EmojiData-$(UNICODE).txt:
@echo "GET EmojiData.txt";\
curl https://www.unicode.org/Public/$(UNICODE)/ucd/emoji/emoji-data.txt > $@
-$(d)/utf/vendor/mkrunewidth: $(d)/utf/vendor/mkrunewidth.c $(d)/utf/vendor/common.o $(NEED_OBJS)
+$(d)/utf/vendor/mkrunewidth: $(d)/utf/vendor/mkrunewidth.c $(NEED_OBJS) | $(RUNTIME) $(SYS)
$(COMPLINK)
GENS += $(d)/utf/vendor/mkrunewidth
@@ -62,7 +63,7 @@ $(d)/utf/vendor/GraphemeBreakProperty-$(UNICODE).txt:
@echo "GET GraphemeBreakProperty.txt";\
curl https://www.unicode.org/Public/$(UNICODE)/ucd/auxiliary/GraphemeBreakProperty.txt > $@
-$(d)/utf/vendor/mkgraphemedata: $(d)/utf/vendor/mkgraphemedata.c $(d)/utf/vendor/common.o $(NEED_OBJS)
+$(d)/utf/vendor/mkgraphemedata: $(d)/utf/vendor/mkgraphemedata.c $(NEED_OBJS) | $(RUNTIME) $(SYS)
$(COMPLINK)
$(d)/utf/graphemedata-$(UNICODE).c: $(d)/utf/vendor/mkgraphemedata $(d)/utf/vendor/GraphemeBreakProperty-$(UNICODE).txt
diff --git a/src/cmd/rules.mk b/src/cmd/rules.mk
index 8a9cfab..ea53737 100644
--- a/src/cmd/rules.mk
+++ b/src/cmd/rules.mk
@@ -29,7 +29,4 @@ include $(DIR)/rules.mk
DIR := $(d)/term
include $(DIR)/rules.mk
-# DIR := $(d)/wm
-# include $(DIR)/rules.mk
-
include share/pop.mk
diff --git a/src/rules.mk b/src/rules.mk
index 368479c..8e8594c 100644
--- a/src/rules.mk
+++ b/src/rules.mk
@@ -8,10 +8,10 @@ include $(DIR)/rules.mk
DIR := $(d)/base
include $(DIR)/rules.mk
-DIR := $(d)/libmath
-include $(DIR)/rules.mk
+# DIR := $(d)/libmath
+# include $(DIR)/rules.mk
-DIR := $(d)/libbio
-include $(DIR)/rules.mk
+# DIR := $(d)/libbio
+# include $(DIR)/rules.mk
include share/pop.mk