aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Makefile12
-rw-r--r--ast.h4
-rw-r--r--builtins/array.c4
-rw-r--r--builtins/array.h2
-rw-r--r--builtins/bool.c4
-rw-r--r--builtins/color.c2
-rw-r--r--builtins/files.c (renamed from files.c)0
-rw-r--r--builtins/files.h (renamed from files.h)0
-rw-r--r--builtins/functions.c12
-rw-r--r--builtins/halfsiphash.h22
-rw-r--r--builtins/integers.c2
-rw-r--r--builtins/macros.h31
-rw-r--r--builtins/memory.c4
-rw-r--r--builtins/nums.c4
-rw-r--r--builtins/pointer.c8
-rw-r--r--builtins/table.c6
-rw-r--r--builtins/text.c2
-rw-r--r--builtins/tomo.h (renamed from tomo.h)29
-rw-r--r--builtins/types.c8
-rw-r--r--builtins/util.c (renamed from util.c)0
-rw-r--r--builtins/util.h (renamed from util.h)0
-rw-r--r--compile.c4
-rw-r--r--compile.h2
-rw-r--r--enums.c2
-rw-r--r--environment.c2
-rw-r--r--parse.c2
-rw-r--r--structs.c2
-rw-r--r--typecheck.c2
-rw-r--r--types.c2
29 files changed, 113 insertions, 61 deletions
diff --git a/Makefile b/Makefile
index 671e17b3..a5b7d11f 100644
--- a/Makefile
+++ b/Makefile
@@ -25,13 +25,13 @@ O=-Og
CFLAGS=$(CCONFIG) $(EXTRA) $(CWARN) $(G) $(O) $(OSFLAGS)
LDLIBS=-lgc -lcord -lm -lunistring
BUILTIN_OBJS=builtins/array.o builtins/bool.o builtins/color.o builtins/nums.o builtins/functions.o builtins/integers.o \
- builtins/pointer.o builtins/memory.o builtins/text.o builtins/table.o builtins/types.o
+ builtins/pointer.o builtins/memory.o builtins/text.o builtins/table.o builtins/types.o builtins/util.o builtins/files.o
all: libtomo.so tomo
-tomo: tomo.c SipHash/halfsiphash.o util.o files.o ast.o parse.o environment.o types.o typecheck.o structs.o enums.o compile.o $(BUILTIN_OBJS)
+tomo: tomo.c SipHash/halfsiphash.o ast.o parse.o environment.o types.o typecheck.o structs.o enums.o compile.o $(BUILTIN_OBJS)
-libtomo.so: util.o files.o $(BUILTIN_OBJS) SipHash/halfsiphash.o
+libtomo.so: $(BUILTIN_OBJS) SipHash/halfsiphash.o
$(CC) $^ $(CFLAGS) $(EXTRA) $(CWARN) $(G) $(O) $(OSFLAGS) $(LDLIBS) -Wl,-soname,libtomo.so -shared -o $@
SipHash/halfsiphash.c:
@@ -50,13 +50,13 @@ clean:
pandoc --lua-filter=.pandoc/bold-code.lua -s $< -t man -o $@
install: tomo libtomo.so
- mkdir -p -m 755 "$(PREFIX)/man/man1" "$(PREFIX)/bin" "$(PREFIX)/lib" "$(PREFIX)/share/tomo/modules"
- cp -v tomo.h "$(PREFIX)/include/"
+ mkdir -p -m 755 "$(PREFIX)/man/man1" "$(PREFIX)/bin" "$(PREFIX)/include/tomo" "$(PREFIX)/lib" "$(PREFIX)/share/tomo/modules"
+ cp -v builtins/*.h "$(PREFIX)/include/tomo/"
cp -v libtomo.so "$(PREFIX)/lib/"
rm -f "$(PREFIX)/bin/tomo"
cp -v tomo "$(PREFIX)/bin/"
uninstall:
- rm -rvf "$(PREFIX)/bin/tomo" "$(PREFIX)/lib/libtomo.so" "$(PREFIX)/share/tomo"; \
+ rm -rvf "$(PREFIX)/bin/tomo" "$(PREFIX)/include/tomo" "$(PREFIX)/lib/libtomo.so" "$(PREFIX)/share/tomo"; \
.PHONY: all clean install uninstall test tags
diff --git a/ast.h b/ast.h
index 847f2224..3ee7f61d 100644
--- a/ast.h
+++ b/ast.h
@@ -4,8 +4,8 @@
#include <stdlib.h>
#include <printf.h>
-#include "files.h"
-#include "util.h"
+#include "builtins/files.h"
+#include "builtins/util.h"
#define NewAST(_file, _start, _end, ast_tag, ...) (new(ast_t, .file=_file, .start=_start, .end=_end,\
.tag=ast_tag, .__data.ast_tag={__VA_ARGS__}))
diff --git a/builtins/array.c b/builtins/array.c
index 07814f66..2fd66f58 100644
--- a/builtins/array.c
+++ b/builtins/array.c
@@ -11,8 +11,8 @@
#include "array.h"
#include "types.h"
#include "functions.h"
-#include "../SipHash/halfsiphash.h"
-#include "../util.h"
+#include "halfsiphash.h"
+#include "util.h"
static inline size_t get_item_size(const TypeInfo *info)
{
diff --git a/builtins/array.h b/builtins/array.h
index 52fd65e3..d36db573 100644
--- a/builtins/array.h
+++ b/builtins/array.h
@@ -2,7 +2,7 @@
#include <stdbool.h>
#include <gc/cord.h>
-#include "../util.h"
+#include "util.h"
#include "datatypes.h"
#include "functions.h"
#include "types.h"
diff --git a/builtins/bool.c b/builtins/bool.c
index 327a101d..35eaafec 100644
--- a/builtins/bool.c
+++ b/builtins/bool.c
@@ -8,9 +8,9 @@
#include <sys/param.h>
#include <err.h>
-#include "../SipHash/halfsiphash.h"
-#include "../util.h"
+#include "util.h"
#include "bool.h"
+#include "halfsiphash.h"
#include "types.h"
public CORD Bool__as_text(const bool *b, bool colorize, const TypeInfo *type)
diff --git a/builtins/color.c b/builtins/color.c
index b84d8a71..4732382a 100644
--- a/builtins/color.c
+++ b/builtins/color.c
@@ -4,7 +4,7 @@
#include <string.h>
#include <unistd.h>
-#include "../util.h"
+#include "util.h"
#include "color.h"
public bool USE_COLOR = true;
diff --git a/files.c b/builtins/files.c
index 9fe9b916..9fe9b916 100644
--- a/files.c
+++ b/builtins/files.c
diff --git a/files.h b/builtins/files.h
index 79dd48cd..79dd48cd 100644
--- a/files.h
+++ b/builtins/files.h
diff --git a/builtins/functions.c b/builtins/functions.c
index 448b7758..ae67fcb9 100644
--- a/builtins/functions.c
+++ b/builtins/functions.c
@@ -7,15 +7,15 @@
#include <sys/param.h>
#include <uninorm.h>
-#include "../SipHash/halfsiphash.h"
-#include "../files.h"
-#include "../util.h"
-#include "functions.h"
+#include "files.h"
+#include "util.h"
#include "array.h"
-#include "table.h"
-#include "text.h"
+#include "functions.h"
+#include "halfsiphash.h"
#include "pointer.h"
#include "string.h"
+#include "table.h"
+#include "text.h"
#include "types.h"
extern bool USE_COLOR;
diff --git a/builtins/halfsiphash.h b/builtins/halfsiphash.h
new file mode 100644
index 00000000..a1af8cd2
--- /dev/null
+++ b/builtins/halfsiphash.h
@@ -0,0 +1,22 @@
+/*
+ SipHash reference C implementation
+
+ Copyright (c) 2012-2021 Jean-Philippe Aumasson
+ <jeanphilippe.aumasson@gmail.com>
+ Copyright (c) 2012-2014 Daniel J. Bernstein <djb@cr.yp.to>
+
+ To the extent possible under law, the author(s) have dedicated all copyright
+ and related and neighboring rights to this software to the public domain
+ worldwide. This software is distributed without any warranty.
+
+ You should have received a copy of the CC0 Public Domain Dedication along
+ with
+ this software. If not, see
+ <http://creativecommons.org/publicdomain/zero/1.0/>.
+ */
+
+#include <inttypes.h>
+#include <string.h>
+
+int halfsiphash(const void *in, const size_t inlen, const void *k, uint8_t *out,
+ const size_t outlen);
diff --git a/builtins/integers.c b/builtins/integers.c
index 6de85c3e..4116879e 100644
--- a/builtins/integers.c
+++ b/builtins/integers.c
@@ -4,9 +4,9 @@
#include <stdint.h>
#include <stdlib.h>
-#include "../SipHash/halfsiphash.h"
#include "array.h"
#include "datatypes.h"
+#include "halfsiphash.h"
#include "integers.h"
#include "string.h"
#include "types.h"
diff --git a/builtins/macros.h b/builtins/macros.h
new file mode 100644
index 00000000..c6f474ec
--- /dev/null
+++ b/builtins/macros.h
@@ -0,0 +1,31 @@
+#pragma once
+
+#include <gc.h>
+#include <gc/cord.h>
+#include <signal.h>
+#include <stdbool.h>
+#include <stdint.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+
+#define $heap(x) (__typeof(x)*)memcpy(GC_MALLOC(sizeof(x)), (__typeof(x)[1]){x}, sizeof(x))
+#define $stack(x) (__typeof(x)*)((__typeof(x)[1]){x})
+#define $tagged(obj_expr, type_name, tag_name) ({ __typeof(obj_expr) $obj = obj_expr; \
+ $obj.$tag == $tag$##type_name##$##tag_name ? &$obj.tag_name : NULL; })
+
+
+#define not(x) _Generic(x, bool: (bool)!(x), int64_t: ~(x), int32_t: ~(x), int16_t: ~(x), int8_t: ~(x), \
+ array_t: ((x).length == 0), table_t: ((x).entries.length == 0), CORD: ((x) == CORD_EMPTY), \
+ default: _Static_assert(0, "Not supported"))
+#define Bool(x) _Generic(x, bool: (bool)(x), int64_t: (x != 0), int32_t: (x != 0), int16_t: (x != 0), int8_t: (x != 0), CORD: ((x) == CORD_EMPTY), \
+ array_t: ((x).length > 0), table_t: ((x).entries.length > 0), CORD: ((x) != CORD_EMPTY), \
+ default: _Static_assert(0, "Not supported"))
+#define and(x, y) _Generic(x, bool: (bool)((x) && (y)), default: ((x) & (y)))
+#define or(x, y) _Generic(x, bool: (bool)((x) || (y)), default: ((x) | (y)))
+#define xor(x, y) _Generic(x, bool: (bool)((x) ^ (y)), default: ((x) ^ (y)))
+#define mod(x, n) ((x) % (n))
+#define mod1(x, n) (((x) % (n)) + (__typeof(x))1)
+#define $cmp(x, y, info) (_Generic(x, int8_t: (x>0)-(y>0), int16_t: (x>0)-(y>0), int32_t: (x>0)-(y>0), int64_t: (x>0)-(y>0), bool: (x>0)-(y>0), \
+ CORD: CORD_cmp((CORD)x, (CORD)y), char*: strcmp((char*)x, (char*)y), default: generic_compare($stack(x), $stack(y), info)))
diff --git a/builtins/memory.c b/builtins/memory.c
index d4af4cc2..f33196be 100644
--- a/builtins/memory.c
+++ b/builtins/memory.c
@@ -8,8 +8,8 @@
#include <sys/param.h>
#include <err.h>
-#include "../util.h"
-#include "../SipHash/halfsiphash.h"
+#include "util.h"
+#include "halfsiphash.h"
#include "memory.h"
#include "types.h"
diff --git a/builtins/nums.c b/builtins/nums.c
index 32ec89fb..b05c6fab 100644
--- a/builtins/nums.c
+++ b/builtins/nums.c
@@ -1,13 +1,13 @@
+#include <float.h>
#include <gc.h>
#include <gc/cord.h>
-#include <float.h>
#include <math.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdlib.h>
-#include "../SipHash/halfsiphash.h"
#include "array.h"
+#include "halfsiphash.h"
#include "nums.h"
#include "string.h"
#include "types.h"
diff --git a/builtins/pointer.c b/builtins/pointer.c
index 54bab4b3..d490485f 100644
--- a/builtins/pointer.c
+++ b/builtins/pointer.c
@@ -1,16 +1,16 @@
+#include <ctype.h>
+#include <err.h>
#include <gc.h>
#include <gc/cord.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdlib.h>
-#include <ctype.h>
#include <sys/param.h>
-#include <err.h>
-#include "../util.h"
-#include "../SipHash/halfsiphash.h"
+#include "util.h"
#include "functions.h"
+#include "halfsiphash.h"
#include "types.h"
typedef struct recursion_s {
diff --git a/builtins/table.c b/builtins/table.c
index 5631a7fb..be4444ac 100644
--- a/builtins/table.c
+++ b/builtins/table.c
@@ -17,13 +17,13 @@
#include <string.h>
#include <sys/param.h>
-#include "../SipHash/halfsiphash.h"
-#include "../util.h"
+#include "util.h"
#include "array.h"
#include "datatypes.h"
+#include "halfsiphash.h"
#include "memory.h"
-#include "text.h"
#include "table.h"
+#include "text.h"
#include "types.h"
// #define DEBUG_TABLES
diff --git a/builtins/text.c b/builtins/text.c
index 4641bc1d..e443da33 100644
--- a/builtins/text.c
+++ b/builtins/text.c
@@ -14,9 +14,9 @@
#include <uninorm.h>
#include <unistr.h>
-#include "../SipHash/halfsiphash.h"
#include "array.h"
#include "functions.h"
+#include "halfsiphash.h"
#include "text.h"
#include "types.h"
diff --git a/tomo.h b/builtins/tomo.h
index 7f4a6254..dd00c628 100644
--- a/tomo.h
+++ b/builtins/tomo.h
@@ -12,19 +12,20 @@
#include <string.h>
#include <unistd.h>
-#include "SipHash/halfsiphash.h"
-#include "builtins/array.h"
-#include "builtins/bool.h"
-#include "builtins/color.h"
-#include "builtins/datatypes.h"
-#include "builtins/functions.h"
-#include "builtins/integers.h"
-#include "builtins/memory.h"
-#include "builtins/nums.h"
-#include "builtins/pointer.h"
-#include "builtins/table.h"
-#include "builtins/text.h"
-#include "builtins/types.h"
+#include "array.h"
+#include "bool.h"
+#include "color.h"
+#include "datatypes.h"
+#include "functions.h"
+#include "halfsiphash.h"
+#include "integers.h"
+#include "macros.h"
+#include "memory.h"
+#include "nums.h"
+#include "pointer.h"
+#include "table.h"
+#include "text.h"
+#include "types.h"
#define $heap(x) (__typeof(x)*)memcpy(GC_MALLOC(sizeof(x)), (__typeof(x)[1]){x}, sizeof(x))
#define $stack(x) (__typeof(x)*)((__typeof(x)[1]){x})
@@ -45,7 +46,5 @@
#define mod1(x, n) (((x) % (n)) + (__typeof(x))1)
#define $cmp(x, y, info) (_Generic(x, int8_t: (x>0)-(y>0), int16_t: (x>0)-(y>0), int32_t: (x>0)-(y>0), int64_t: (x>0)-(y>0), bool: (x>0)-(y>0), \
CORD: CORD_cmp((CORD)x, (CORD)y), char*: strcmp((char*)x, (char*)y), default: generic_compare($stack(x), $stack(y), info)))
-#define min(c_type, x, y, info) ({ c_type $lhs = x, $rhs = y; generic_compare(&$lhs, &$rhs, info) <= 0 ? $lhs : $rhs; })
-#define max(c_type, x, y, info) ({ c_type $lhs = x, $rhs = y; generic_compare(&$lhs, &$rhs, info) >= 0 ? $lhs : $rhs; })
// vim: ts=4 sw=0 et cino=L2,l1,(0,W4,m1,\:0
diff --git a/builtins/types.c b/builtins/types.c
index 59bf5c47..72be5afa 100644
--- a/builtins/types.c
+++ b/builtins/types.c
@@ -1,16 +1,16 @@
// Generic type constructor
#include <err.h>
#include <gc.h>
-#include <string.h>
#include <stdlib.h>
+#include <string.h>
#include <sys/param.h>
+#include "util.h"
#include "array.h"
-#include "table.h"
+#include "halfsiphash.h"
#include "pointer.h"
+#include "table.h"
#include "types.h"
-#include "../util.h"
-#include "../SipHash/halfsiphash.h"
public CORD Type__as_text(const void *typeinfo, bool colorize, const TypeInfo *type)
{
diff --git a/util.c b/builtins/util.c
index 16ef7aaf..16ef7aaf 100644
--- a/util.c
+++ b/builtins/util.c
diff --git a/util.h b/builtins/util.h
index c858f6ce..c858f6ce 100644
--- a/util.h
+++ b/builtins/util.h
diff --git a/compile.c b/compile.c
index a395a75c..9d1604cc 100644
--- a/compile.c
+++ b/compile.c
@@ -12,7 +12,7 @@
#include "structs.h"
#include "environment.h"
#include "typecheck.h"
-#include "util.h"
+#include "builtins/util.h"
CORD compile_type_ast(type_ast_t *t)
{
@@ -1518,7 +1518,7 @@ CORD compile_type_info(env_t *env, type_t *t)
module_code_t compile_file(ast_t *ast)
{
env_t *env = new_compilation_unit();
- CORD_appendf(&env->code->imports, "#include <tomo.h>\n");
+ CORD_appendf(&env->code->imports, "#include <tomo/tomo.h>\n");
for (ast_list_t *stmt = Match(ast, Block)->statements; stmt; stmt = stmt->next) {
bind_statement(env, stmt->ast);
diff --git a/compile.h b/compile.h
index c50e22aa..b8bdbc36 100644
--- a/compile.h
+++ b/compile.h
@@ -4,7 +4,7 @@
#include <gc.h>
#include <stdio.h>
-#include "util.h"
+#include "builtins/util.h"
#include "environment.h"
typedef struct {
diff --git a/enums.c b/enums.c
index 6aaa9ced..ff0c09fc 100644
--- a/enums.c
+++ b/enums.c
@@ -10,7 +10,7 @@
#include "structs.h"
#include "environment.h"
#include "typecheck.h"
-#include "util.h"
+#include "builtins/util.h"
static CORD compile_str_method(env_t *env, ast_t *ast)
{
diff --git a/environment.c b/environment.c
index d9573e2f..3ba7cdd2 100644
--- a/environment.c
+++ b/environment.c
@@ -6,7 +6,7 @@
#include "builtins/table.h"
#include "builtins/text.h"
#include "typecheck.h"
-#include "util.h"
+#include "builtins/util.h"
typedef struct {
const char *name;
diff --git a/parse.c b/parse.c
index bed73e0b..ef0a89ad 100644
--- a/parse.c
+++ b/parse.c
@@ -12,7 +12,7 @@
#include <signal.h>
#include "ast.h"
-#include "util.h"
+#include "builtins/util.h"
static const char closing[128] = {['(']=')', ['[']=']', ['<']='>', ['{']='}'};
diff --git a/structs.c b/structs.c
index a5f4b964..b5ea5638 100644
--- a/structs.c
+++ b/structs.c
@@ -9,7 +9,7 @@
#include "compile.h"
#include "environment.h"
#include "typecheck.h"
-#include "util.h"
+#include "builtins/util.h"
static bool is_plain_data(env_t *env, type_t *t)
{
diff --git a/typecheck.c b/typecheck.c
index 5cabf3f1..769d8680 100644
--- a/typecheck.c
+++ b/typecheck.c
@@ -12,7 +12,7 @@
#include "parse.h"
#include "typecheck.h"
#include "types.h"
-#include "util.h"
+#include "builtins/util.h"
type_t *parse_type_ast(env_t *env, type_ast_t *ast)
{
diff --git a/types.c b/types.c
index ba6c1b62..e37a3b90 100644
--- a/types.c
+++ b/types.c
@@ -7,7 +7,7 @@
#include "builtins/table.h"
#include "types.h"
-#include "util.h"
+#include "builtins/util.h"
CORD type_to_cord(type_t *t) {
switch (t->tag) {