Rearranging some files

This commit is contained in:
Bruce Hill 2024-03-10 00:03:21 -05:00
parent b639f01294
commit a33f730617
29 changed files with 113 additions and 61 deletions

View File

@ -25,13 +25,13 @@ O=-Og
CFLAGS=$(CCONFIG) $(EXTRA) $(CWARN) $(G) $(O) $(OSFLAGS) CFLAGS=$(CCONFIG) $(EXTRA) $(CWARN) $(G) $(O) $(OSFLAGS)
LDLIBS=-lgc -lcord -lm -lunistring 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 \ 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 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 $@ $(CC) $^ $(CFLAGS) $(EXTRA) $(CWARN) $(G) $(O) $(OSFLAGS) $(LDLIBS) -Wl,-soname,libtomo.so -shared -o $@
SipHash/halfsiphash.c: SipHash/halfsiphash.c:
@ -50,13 +50,13 @@ clean:
pandoc --lua-filter=.pandoc/bold-code.lua -s $< -t man -o $@ pandoc --lua-filter=.pandoc/bold-code.lua -s $< -t man -o $@
install: tomo libtomo.so install: tomo libtomo.so
mkdir -p -m 755 "$(PREFIX)/man/man1" "$(PREFIX)/bin" "$(PREFIX)/lib" "$(PREFIX)/share/tomo/modules" mkdir -p -m 755 "$(PREFIX)/man/man1" "$(PREFIX)/bin" "$(PREFIX)/include/tomo" "$(PREFIX)/lib" "$(PREFIX)/share/tomo/modules"
cp -v tomo.h "$(PREFIX)/include/" cp -v builtins/*.h "$(PREFIX)/include/tomo/"
cp -v libtomo.so "$(PREFIX)/lib/" cp -v libtomo.so "$(PREFIX)/lib/"
rm -f "$(PREFIX)/bin/tomo" rm -f "$(PREFIX)/bin/tomo"
cp -v tomo "$(PREFIX)/bin/" cp -v tomo "$(PREFIX)/bin/"
uninstall: 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 .PHONY: all clean install uninstall test tags

4
ast.h
View File

@ -4,8 +4,8 @@
#include <stdlib.h> #include <stdlib.h>
#include <printf.h> #include <printf.h>
#include "files.h" #include "builtins/files.h"
#include "util.h" #include "builtins/util.h"
#define NewAST(_file, _start, _end, ast_tag, ...) (new(ast_t, .file=_file, .start=_start, .end=_end,\ #define NewAST(_file, _start, _end, ast_tag, ...) (new(ast_t, .file=_file, .start=_start, .end=_end,\
.tag=ast_tag, .__data.ast_tag={__VA_ARGS__})) .tag=ast_tag, .__data.ast_tag={__VA_ARGS__}))

View File

@ -11,8 +11,8 @@
#include "array.h" #include "array.h"
#include "types.h" #include "types.h"
#include "functions.h" #include "functions.h"
#include "../SipHash/halfsiphash.h" #include "halfsiphash.h"
#include "../util.h" #include "util.h"
static inline size_t get_item_size(const TypeInfo *info) static inline size_t get_item_size(const TypeInfo *info)
{ {

View File

@ -2,7 +2,7 @@
#include <stdbool.h> #include <stdbool.h>
#include <gc/cord.h> #include <gc/cord.h>
#include "../util.h" #include "util.h"
#include "datatypes.h" #include "datatypes.h"
#include "functions.h" #include "functions.h"
#include "types.h" #include "types.h"

View File

@ -8,9 +8,9 @@
#include <sys/param.h> #include <sys/param.h>
#include <err.h> #include <err.h>
#include "../SipHash/halfsiphash.h" #include "util.h"
#include "../util.h"
#include "bool.h" #include "bool.h"
#include "halfsiphash.h"
#include "types.h" #include "types.h"
public CORD Bool__as_text(const bool *b, bool colorize, const TypeInfo *type) public CORD Bool__as_text(const bool *b, bool colorize, const TypeInfo *type)

View File

@ -4,7 +4,7 @@
#include <string.h> #include <string.h>
#include <unistd.h> #include <unistd.h>
#include "../util.h" #include "util.h"
#include "color.h" #include "color.h"
public bool USE_COLOR = true; public bool USE_COLOR = true;

View File

@ -7,15 +7,15 @@
#include <sys/param.h> #include <sys/param.h>
#include <uninorm.h> #include <uninorm.h>
#include "../SipHash/halfsiphash.h" #include "files.h"
#include "../files.h" #include "util.h"
#include "../util.h"
#include "functions.h"
#include "array.h" #include "array.h"
#include "table.h" #include "functions.h"
#include "text.h" #include "halfsiphash.h"
#include "pointer.h" #include "pointer.h"
#include "string.h" #include "string.h"
#include "table.h"
#include "text.h"
#include "types.h" #include "types.h"
extern bool USE_COLOR; extern bool USE_COLOR;

22
builtins/halfsiphash.h Normal file
View File

@ -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);

View File

@ -4,9 +4,9 @@
#include <stdint.h> #include <stdint.h>
#include <stdlib.h> #include <stdlib.h>
#include "../SipHash/halfsiphash.h"
#include "array.h" #include "array.h"
#include "datatypes.h" #include "datatypes.h"
#include "halfsiphash.h"
#include "integers.h" #include "integers.h"
#include "string.h" #include "string.h"
#include "types.h" #include "types.h"

31
builtins/macros.h Normal file
View File

@ -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)))

View File

@ -8,8 +8,8 @@
#include <sys/param.h> #include <sys/param.h>
#include <err.h> #include <err.h>
#include "../util.h" #include "util.h"
#include "../SipHash/halfsiphash.h" #include "halfsiphash.h"
#include "memory.h" #include "memory.h"
#include "types.h" #include "types.h"

View File

@ -1,13 +1,13 @@
#include <float.h>
#include <gc.h> #include <gc.h>
#include <gc/cord.h> #include <gc/cord.h>
#include <float.h>
#include <math.h> #include <math.h>
#include <stdbool.h> #include <stdbool.h>
#include <stdint.h> #include <stdint.h>
#include <stdlib.h> #include <stdlib.h>
#include "../SipHash/halfsiphash.h"
#include "array.h" #include "array.h"
#include "halfsiphash.h"
#include "nums.h" #include "nums.h"
#include "string.h" #include "string.h"
#include "types.h" #include "types.h"

View File

@ -1,16 +1,16 @@
#include <ctype.h>
#include <err.h>
#include <gc.h> #include <gc.h>
#include <gc/cord.h> #include <gc/cord.h>
#include <stdbool.h> #include <stdbool.h>
#include <stdint.h> #include <stdint.h>
#include <stdlib.h> #include <stdlib.h>
#include <ctype.h>
#include <sys/param.h> #include <sys/param.h>
#include <err.h>
#include "../util.h" #include "util.h"
#include "../SipHash/halfsiphash.h"
#include "functions.h" #include "functions.h"
#include "halfsiphash.h"
#include "types.h" #include "types.h"
typedef struct recursion_s { typedef struct recursion_s {

View File

@ -17,13 +17,13 @@
#include <string.h> #include <string.h>
#include <sys/param.h> #include <sys/param.h>
#include "../SipHash/halfsiphash.h" #include "util.h"
#include "../util.h"
#include "array.h" #include "array.h"
#include "datatypes.h" #include "datatypes.h"
#include "halfsiphash.h"
#include "memory.h" #include "memory.h"
#include "text.h"
#include "table.h" #include "table.h"
#include "text.h"
#include "types.h" #include "types.h"
// #define DEBUG_TABLES // #define DEBUG_TABLES

View File

@ -14,9 +14,9 @@
#include <uninorm.h> #include <uninorm.h>
#include <unistr.h> #include <unistr.h>
#include "../SipHash/halfsiphash.h"
#include "array.h" #include "array.h"
#include "functions.h" #include "functions.h"
#include "halfsiphash.h"
#include "text.h" #include "text.h"
#include "types.h" #include "types.h"

View File

@ -12,19 +12,20 @@
#include <string.h> #include <string.h>
#include <unistd.h> #include <unistd.h>
#include "SipHash/halfsiphash.h" #include "array.h"
#include "builtins/array.h" #include "bool.h"
#include "builtins/bool.h" #include "color.h"
#include "builtins/color.h" #include "datatypes.h"
#include "builtins/datatypes.h" #include "functions.h"
#include "builtins/functions.h" #include "halfsiphash.h"
#include "builtins/integers.h" #include "integers.h"
#include "builtins/memory.h" #include "macros.h"
#include "builtins/nums.h" #include "memory.h"
#include "builtins/pointer.h" #include "nums.h"
#include "builtins/table.h" #include "pointer.h"
#include "builtins/text.h" #include "table.h"
#include "builtins/types.h" #include "text.h"
#include "types.h"
#define $heap(x) (__typeof(x)*)memcpy(GC_MALLOC(sizeof(x)), (__typeof(x)[1]){x}, sizeof(x)) #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 $stack(x) (__typeof(x)*)((__typeof(x)[1]){x})
@ -45,7 +46,5 @@
#define mod1(x, n) (((x) % (n)) + (__typeof(x))1) #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), \ #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))) 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 // vim: ts=4 sw=0 et cino=L2,l1,(0,W4,m1,\:0

View File

@ -1,16 +1,16 @@
// Generic type constructor // Generic type constructor
#include <err.h> #include <err.h>
#include <gc.h> #include <gc.h>
#include <string.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h>
#include <sys/param.h> #include <sys/param.h>
#include "util.h"
#include "array.h" #include "array.h"
#include "table.h" #include "halfsiphash.h"
#include "pointer.h" #include "pointer.h"
#include "table.h"
#include "types.h" #include "types.h"
#include "../util.h"
#include "../SipHash/halfsiphash.h"
public CORD Type__as_text(const void *typeinfo, bool colorize, const TypeInfo *type) public CORD Type__as_text(const void *typeinfo, bool colorize, const TypeInfo *type)
{ {

View File

@ -12,7 +12,7 @@
#include "structs.h" #include "structs.h"
#include "environment.h" #include "environment.h"
#include "typecheck.h" #include "typecheck.h"
#include "util.h" #include "builtins/util.h"
CORD compile_type_ast(type_ast_t *t) 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) module_code_t compile_file(ast_t *ast)
{ {
env_t *env = new_compilation_unit(); 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) { for (ast_list_t *stmt = Match(ast, Block)->statements; stmt; stmt = stmt->next) {
bind_statement(env, stmt->ast); bind_statement(env, stmt->ast);

View File

@ -4,7 +4,7 @@
#include <gc.h> #include <gc.h>
#include <stdio.h> #include <stdio.h>
#include "util.h" #include "builtins/util.h"
#include "environment.h" #include "environment.h"
typedef struct { typedef struct {

View File

@ -10,7 +10,7 @@
#include "structs.h" #include "structs.h"
#include "environment.h" #include "environment.h"
#include "typecheck.h" #include "typecheck.h"
#include "util.h" #include "builtins/util.h"
static CORD compile_str_method(env_t *env, ast_t *ast) static CORD compile_str_method(env_t *env, ast_t *ast)
{ {

View File

@ -6,7 +6,7 @@
#include "builtins/table.h" #include "builtins/table.h"
#include "builtins/text.h" #include "builtins/text.h"
#include "typecheck.h" #include "typecheck.h"
#include "util.h" #include "builtins/util.h"
typedef struct { typedef struct {
const char *name; const char *name;

View File

@ -12,7 +12,7 @@
#include <signal.h> #include <signal.h>
#include "ast.h" #include "ast.h"
#include "util.h" #include "builtins/util.h"
static const char closing[128] = {['(']=')', ['[']=']', ['<']='>', ['{']='}'}; static const char closing[128] = {['(']=')', ['[']=']', ['<']='>', ['{']='}'};

View File

@ -9,7 +9,7 @@
#include "compile.h" #include "compile.h"
#include "environment.h" #include "environment.h"
#include "typecheck.h" #include "typecheck.h"
#include "util.h" #include "builtins/util.h"
static bool is_plain_data(env_t *env, type_t *t) static bool is_plain_data(env_t *env, type_t *t)
{ {

View File

@ -12,7 +12,7 @@
#include "parse.h" #include "parse.h"
#include "typecheck.h" #include "typecheck.h"
#include "types.h" #include "types.h"
#include "util.h" #include "builtins/util.h"
type_t *parse_type_ast(env_t *env, type_ast_t *ast) type_t *parse_type_ast(env_t *env, type_ast_t *ast)
{ {

View File

@ -7,7 +7,7 @@
#include "builtins/table.h" #include "builtins/table.h"
#include "types.h" #include "types.h"
#include "util.h" #include "builtins/util.h"
CORD type_to_cord(type_t *t) { CORD type_to_cord(type_t *t) {
switch (t->tag) { switch (t->tag) {