diff options
| -rw-r--r-- | .gitignore | 3 | ||||
| -rw-r--r-- | Makefile | 4 | ||||
| -rw-r--r-- | ir.c | 37 | ||||
| -rw-r--r-- | ir.h | 2 | ||||
| -rw-r--r-- | test.lang | 4 | ||||
| -rwxr-xr-x | watch.sh | 14 |
6 files changed, 46 insertions, 18 deletions
@@ -1,2 +1,3 @@ -a.out +lang *.o +out.pdf @@ -1,4 +1,4 @@ -EXE = a.out +EXE = lang RUNARGS = test.lang CFLAGS = -std=c23 -Wall -Wextra -Wpedantic ${CFLAGS_${DEBUG}} @@ -27,7 +27,7 @@ debug: ${EXE} ${GDB} -ex start --args ./${EXE} ${RUNARGS} clean: - rm -fv ${EXE} ${OBJ} + rm -fv ${EXE} ${OBJ} out.pdf ${EXE}: ${OBJ} ${CC} ${LDFLAGS} ${OBJ} -o ${EXE} ${LDLIBS} @@ -1,4 +1,5 @@ #include <stdarg.h> +#include <stdbit.h> #include <assert.h> #include "ir.h" @@ -10,20 +11,16 @@ void nodelist_fit(NodeList *l, u32 sz, Arena *a) { if (l->cap) { if (sz > l->cap) { - u32 c = l->cap; - while (sz > c) c <<= 1; - l->data = resize(a, l->data, l->cap, c); - l->cap = c; - } - } else { - if (sz > 1) { - u32 cap = 2; - while (cap < sz) cap <<= 1; - Node **data = new_arr(a, Node *, cap); - data[0] = l->sbo; - l->data = data; + u32 cap = stdc_bit_ceil(sz); + l->data = resize(a, l->data, l->cap, cap); l->cap = cap; } + } else if (sz > 1) { + u32 cap = stdc_bit_ceil(sz); + Node **data = new_arr(a, Node *, cap); + data[0] = l->sbo; + l->data = data; + l->cap = cap; } } @@ -176,14 +173,26 @@ Node *node_new_empty(Graph *p, NodeType t) { Node *node_newv(Graph *p, NodeType t, Node *ctrl, ...) { Node *node = node_new_empty(p, t); va_list ap; + /* do inputs all at once to decrease chance of arena_realloc() fragmenting */ + va_start(ap, ctrl); - node_add(p, ctrl, node); + node_add_in(p, node, ctrl); for (;;) { Node *n = va_arg(ap, Node *); if (!n) break; - node_add(p, n, node); + node_add_in(p, node, n); } va_end(ap); + + va_start(ap, ctrl); + if (ctrl) node_add_out(p, ctrl, node); + for (;;) { + Node *n = va_arg(ap, Node *); + if (!n) break; + node_add_out(p, n, node); + } + va_end(ap); + return node; } @@ -102,7 +102,7 @@ typedef enum { const char *node_type_name(NodeType t); typedef struct { - unsigned len, cap; + u32 len, cap; union { struct Node *sbo; struct Node **data; @@ -1,3 +1,7 @@ +func square(x i64) i64 { + return x * x +} + func main(a, b i64) i64 { if a < b { let t = a diff --git a/watch.sh b/watch.sh new file mode 100755 index 0000000..896473d --- /dev/null +++ b/watch.sh @@ -0,0 +1,14 @@ +#!/bin/sh + +gen() { + tcc ir.c lex.c impl.c peephole.c proc.c -run main.c test.lang\ + | dot -Tpdf -o out.pdf +} + +gen +mupdf out.pdf & +while true; do + inotifywait -e modify -r . + gen + killall -SIGHUP mupdf +done |
