aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBruce Hill <bruce@bruce-hill.com>2025-08-23 18:20:43 -0400
committerBruce Hill <bruce@bruce-hill.com>2025-08-23 18:20:43 -0400
commita4b8ef38b1d7a26b4e6bfa966f021a237bf16ce1 (patch)
treea4137025b4096749341513f44c12d381ceb636bf
parentecf08ab61fe49101b6c769badf362d21d8699df4 (diff)
Lots of cleanups
-rw-r--r--.clangd3
-rw-r--r--examples/coroutines/aco.c4
-rw-r--r--lib/commands/commands.c2
-rw-r--r--lib/random/chacha.h2
-rw-r--r--lib/time/time.tm1
-rw-r--r--lib/time/time_defs.h3
-rw-r--r--src/compile.c9
-rw-r--r--src/compile.h1
-rw-r--r--src/enums.c1
-rw-r--r--src/environment.h3
-rw-r--r--src/naming.c2
-rw-r--r--src/stdlib/bools.c1
-rw-r--r--src/stdlib/bools.h1
-rw-r--r--src/stdlib/bytes.h1
-rw-r--r--src/stdlib/c_strings.c4
-rw-r--r--src/stdlib/datatypes.h1
-rw-r--r--src/stdlib/functiontype.h2
-rw-r--r--src/stdlib/integers.h2
-rw-r--r--src/stdlib/lists.c1
-rw-r--r--src/stdlib/memory.c1
-rw-r--r--src/stdlib/nums.c4
-rw-r--r--src/stdlib/nums.h4
-rw-r--r--src/stdlib/optionals.c3
-rw-r--r--src/stdlib/optionals.h1
-rw-r--r--src/stdlib/paths.h4
-rw-r--r--src/stdlib/print.c2
-rw-r--r--src/stdlib/print.h1
-rw-r--r--src/stdlib/random.h3
-rw-r--r--src/stdlib/simpleparse.h1
-rw-r--r--src/stdlib/stacktrace.c5
-rw-r--r--src/stdlib/stdlib.c2
-rw-r--r--src/stdlib/stdlib.h2
-rw-r--r--src/stdlib/text.c3
-rw-r--r--src/stdlib/text.h2
-rw-r--r--src/stdlib/tomo.h2
-rw-r--r--src/structs.c1
-rw-r--r--src/tomo.c2
-rw-r--r--src/typecheck.c1
-rw-r--r--src/typecheck.h2
-rw-r--r--test/extern.tm1
40 files changed, 54 insertions, 37 deletions
diff --git a/.clangd b/.clangd
new file mode 100644
index 00000000..6cf2eba8
--- /dev/null
+++ b/.clangd
@@ -0,0 +1,3 @@
+CompileFlags:
+ Add: [-xc]
+Checks: '-bugprone-suspicious-missing-comma'
diff --git a/examples/coroutines/aco.c b/examples/coroutines/aco.c
index 3226468b..6057466f 100644
--- a/examples/coroutines/aco.c
+++ b/examples/coroutines/aco.c
@@ -175,7 +175,7 @@ static inline void aco_fast_memcpy(void *dst, const void *src, size_t sz) {
}
#endif
-void aco_default_protector_last_word(void*) {
+void aco_default_protector_last_word(void*_) {
aco_t* co = aco_get_co();
// do some log about the offending `co`
fprintf(stderr,"error: aco_default_protector_last_word triggered\n");
@@ -487,6 +487,6 @@ public void aco_destroy(aco_t* co) {
}
}
-public void aco_exit_fn(void*) {
+public void aco_exit_fn(void*_) {
aco_exit();
}
diff --git a/lib/commands/commands.c b/lib/commands/commands.c
index 1e9afe8e..80710387 100644
--- a/lib/commands/commands.c
+++ b/lib/commands/commands.c
@@ -23,7 +23,7 @@ static void xpipe(int fd[2]) {
}
int run_command(Text_t exe, List_t arg_list, Table_t env_table,
- OptionalList_t input_bytes, List_t *output_bytes, List_t *error_bytes)
+ OptionalList_t input_bytes, List_t *output_bytes, List_t *error_bytes)
{
pthread_testcancel();
diff --git a/lib/random/chacha.h b/lib/random/chacha.h
index 4b1283ed..b803c24a 100644
--- a/lib/random/chacha.h
+++ b/lib/random/chacha.h
@@ -86,7 +86,7 @@ chacha_encrypt_bytes(chacha_ctx *chacha, const u8 *m, u8 *c, u32 bytes)
{
u32 x0, x1, x2, x3, x4, x5, x6, x7, x8, x9, x10, x11, x12, x13, x14, x15;
u32 j0, j1, j2, j3, j4, j5, j6, j7, j8, j9, j10, j11, j12, j13, j14, j15;
- u8 *ctarget = NULL;
+ u8 *ctarget = (u8*)0;
u8 tmp[64];
unsigned int i;
diff --git a/lib/time/time.tm b/lib/time/time.tm
index 456b5f08..d26d7218 100644
--- a/lib/time/time.tm
+++ b/lib/time/time.tm
@@ -1,4 +1,5 @@
# Time - a module for dealing with dates and times
+use <math.h>
use ./time_defs.h
enum Weekday(Sunday, Monday, Tuesday, Wednesday, Thursday, Friday, Saturday)
diff --git a/lib/time/time_defs.h b/lib/time/time_defs.h
index 30000983..2ae1d9e4 100644
--- a/lib/time/time_defs.h
+++ b/lib/time/time_defs.h
@@ -1,6 +1,7 @@
#pragma once
-#include <time.h>
+#include <stdlib.h>
#include <sys/time.h>
+#include <time.h>
typedef struct timeval Time;
diff --git a/src/compile.c b/src/compile.c
index cc9a7bd6..8d5fe9b6 100644
--- a/src/compile.c
+++ b/src/compile.c
@@ -7,15 +7,16 @@
#include <uninorm.h>
#include "ast.h"
+#include "config.h"
#include "compile.h"
#include "enums.h"
#include "environment.h"
#include "modules.h"
#include "naming.h"
-#include "parse.h"
#include "stdlib/integers.h"
#include "stdlib/nums.h"
#include "stdlib/paths.h"
+#include "stdlib/tables.h"
#include "stdlib/text.h"
#include "stdlib/util.h"
#include "structs.h"
@@ -64,7 +65,7 @@ Text_t promote_to_optional(type_t *t, Text_t code)
case TYPE_IBITS16: return Texts("((OptionalInt16_t){.value=", code, "})");
case TYPE_IBITS32: return Texts("((OptionalInt32_t){.value=", code, "})");
case TYPE_IBITS64: return Texts("((OptionalInt64_t){.value=", code, "})");
- default: errx(1, "Unsupported in type: ", type_to_str(t));
+ default: errx(1, "Unsupported in type: %s", type_to_str(t));
}
return code;
} else if (t->tag == ByteType) {
@@ -779,7 +780,7 @@ static Text_t compile_binary_op(env_t *env, ast_t *ast)
code_err(ast, "Concatenation isn't supported between ", type_to_str(lhs_t), " and ", type_to_str(rhs_t), " values");
}
}
- default: errx(1, "Not a valid binary operation: ", ast_to_sexp_str(ast));
+ default: errx(1, "Not a valid binary operation: %s", ast_to_sexp_str(ast));
}
return EMPTY_TEXT;
}
@@ -1003,7 +1004,7 @@ Text_t check_none(type_t *t, Text_t value)
else if (t->tag == ClosureType)
return Texts("({(", value, ").fn == NULL;})");
else if (t->tag == NumType)
- return Texts("isnan(", value, ")");
+ return Texts(Match(t, NumType)->bits == TYPE_NBITS64 ? "Num$isnan(" : "Num32$isnan(", value, ")");
else if (t->tag == ListType)
return Texts("({(", value, ").length < 0;})");
else if (t->tag == TableType || t->tag == SetType)
diff --git a/src/compile.h b/src/compile.h
index 2e866cc2..21176395 100644
--- a/src/compile.h
+++ b/src/compile.h
@@ -3,7 +3,6 @@
// Compilation functions
#include <gc.h>
-#include <stdio.h>
#include "environment.h"
#include "stdlib/datatypes.h"
diff --git a/src/enums.c b/src/enums.c
index ae15d71c..dba6d4cb 100644
--- a/src/enums.c
+++ b/src/enums.c
@@ -6,6 +6,7 @@
#include "compile.h"
#include "environment.h"
#include "naming.h"
+#include "stdlib/tables.h"
#include "stdlib/text.h"
#include "structs.h"
#include "typecheck.h"
diff --git a/src/environment.h b/src/environment.h
index eb5b55bc..0bff474d 100644
--- a/src/environment.h
+++ b/src/environment.h
@@ -4,9 +4,6 @@
#include "stdlib/datatypes.h"
#include "stdlib/print.h"
-#include "stdlib/stacktrace.h"
-#include "stdlib/stdlib.h"
-#include "stdlib/tables.h"
#include "types.h"
typedef struct {
diff --git a/src/naming.c b/src/naming.c
index 664fd970..3bf71597 100644
--- a/src/naming.c
+++ b/src/naming.c
@@ -63,7 +63,7 @@ public Text_t get_id_suffix(const char *filename)
}
Path_t id_file = Path$child(build_dir, Texts(Path$base_name(path), Text$from_str(".id")));
OptionalText_t id = Path$read(id_file);
- if (id.length < 0) err(1, "Could not read ID file: ", id_file);
+ if (id.length < 0) err(1, "Could not read ID file: %s", id_file);
return Texts(Text("$"), id);
}
diff --git a/src/stdlib/bools.c b/src/stdlib/bools.c
index 558d184e..76de49e0 100644
--- a/src/stdlib/bools.c
+++ b/src/stdlib/bools.c
@@ -6,6 +6,7 @@
#include <sys/param.h>
#include "bools.h"
+#include "integers.h"
#include "optionals.h"
#include "text.h"
#include "util.h"
diff --git a/src/stdlib/bools.h b/src/stdlib/bools.h
index ae6c5feb..bdf80879 100644
--- a/src/stdlib/bools.h
+++ b/src/stdlib/bools.h
@@ -6,7 +6,6 @@
#include <stdint.h>
#include "types.h"
-#include "optionals.h"
#include "util.h"
#define yes (Bool_t)true
diff --git a/src/stdlib/bytes.h b/src/stdlib/bytes.h
index ab88b5bc..b5e352d0 100644
--- a/src/stdlib/bytes.h
+++ b/src/stdlib/bytes.h
@@ -7,7 +7,6 @@
#include "datatypes.h"
#include "integers.h"
-#include "stdlib.h"
#include "types.h"
#include "util.h"
diff --git a/src/stdlib/c_strings.c b/src/stdlib/c_strings.c
index 4ad56d4e..c2b8efbe 100644
--- a/src/stdlib/c_strings.c
+++ b/src/stdlib/c_strings.c
@@ -6,8 +6,10 @@
#include <stdio.h>
#include <stdlib.h>
-#include "text.h"
+#include "integers.h"
#include "siphash.h"
+#include "stdlib.h"
+#include "text.h"
#include "util.h"
public Text_t CString$as_text(const void *c_string, bool colorize, const TypeInfo_t *info)
diff --git a/src/stdlib/datatypes.h b/src/stdlib/datatypes.h
index fce1ea74..e473956e 100644
--- a/src/stdlib/datatypes.h
+++ b/src/stdlib/datatypes.h
@@ -5,7 +5,6 @@
#include <gmp.h>
#include <stdbool.h>
#include <stdint.h>
-#include <time.h>
#define LIST_LENGTH_BITS 64
#define LIST_FREE_BITS 48
diff --git a/src/stdlib/functiontype.h b/src/stdlib/functiontype.h
index d308be96..095d630e 100644
--- a/src/stdlib/functiontype.h
+++ b/src/stdlib/functiontype.h
@@ -3,8 +3,6 @@
#include <stdbool.h>
#include <stdint.h>
-#include "metamethods.h"
-#include "optionals.h"
#include "types.h"
#include "util.h"
diff --git a/src/stdlib/integers.h b/src/stdlib/integers.h
index 50ca485f..744992dd 100644
--- a/src/stdlib/integers.h
+++ b/src/stdlib/integers.h
@@ -4,10 +4,8 @@
#include <stdbool.h>
#include <stdint.h>
-#include <stdlib.h>
#include <gmp.h>
-#include "print.h"
#include "datatypes.h"
#include "stdlib.h"
#include "types.h"
diff --git a/src/stdlib/lists.c b/src/stdlib/lists.c
index a1ffdf0c..ce27f822 100644
--- a/src/stdlib/lists.c
+++ b/src/stdlib/lists.c
@@ -1,6 +1,7 @@
// Functions that operate on lists
#include <gc.h>
+#include <math.h>
#include <stdbool.h>
#include <stdint.h>
#include <sys/param.h>
diff --git a/src/stdlib/memory.c b/src/stdlib/memory.c
index 83efc71f..a28b0069 100644
--- a/src/stdlib/memory.c
+++ b/src/stdlib/memory.c
@@ -7,6 +7,7 @@
#include "memory.h"
#include "metamethods.h"
+#include "print.h"
#include "text.h"
#include "types.h"
#include "util.h"
diff --git a/src/stdlib/nums.c b/src/stdlib/nums.c
index cbb0c9d7..83166659 100644
--- a/src/stdlib/nums.c
+++ b/src/stdlib/nums.c
@@ -113,7 +113,7 @@ public OptionalNum_t Num$parse(Text_t text, Text_t *remainder) {
}
}
-static bool Num$is_none(const void *n, const TypeInfo_t *info)
+public CONSTFUNC bool Num$is_none(const void *n, const TypeInfo_t *info)
{
(void)info;
return isnan(*(Num_t*)n);
@@ -223,7 +223,7 @@ public OptionalNum32_t Num32$parse(Text_t text, Text_t *remainder) {
}
}
-static bool Num32$is_none(const void *n, const TypeInfo_t *info)
+public CONSTFUNC bool Num32$is_none(const void *n, const TypeInfo_t *info)
{
(void)info;
return isnan(*(Num32_t*)n);
diff --git a/src/stdlib/nums.h b/src/stdlib/nums.h
index fe76d1c3..6e6e1431 100644
--- a/src/stdlib/nums.h
+++ b/src/stdlib/nums.h
@@ -2,12 +2,10 @@
// Type infos and methods for Nums (floating point)
-#include <math.h>
#include <stdbool.h>
#include <stdint.h>
#include "datatypes.h"
-#include "integers.h"
#include "stdlib.h"
#include "types.h"
#include "util.h"
@@ -28,6 +26,7 @@ double Num$mod1(double num, double modulus);
CONSTFUNC bool Num$isinf(double n);
CONSTFUNC bool Num$finite(double n);
CONSTFUNC bool Num$isnan(double n);
+bool Num$is_none(const void *n, const TypeInfo_t *info);
double Num$nan(Text_t tag);
CONSTFUNC double Num$mix(double amount, double x, double y);
OptionalNum_t Num$parse(Text_t text, Text_t *remainder);
@@ -82,6 +81,7 @@ float Num32$mod1(float num, float modulus);
CONSTFUNC bool Num32$isinf(float n);
CONSTFUNC bool Num32$finite(float n);
CONSTFUNC bool Num32$isnan(float n);
+CONSTFUNC bool Num32$is_none(const void *n, const TypeInfo_t *info);
CONSTFUNC float Num32$mix(float amount, float x, float y);
OptionalNum32_t Num32$parse(Text_t text, Text_t *remainder);
float Num32$nan(Text_t tag);
diff --git a/src/stdlib/optionals.c b/src/stdlib/optionals.c
index 7cf57f91..36683241 100644
--- a/src/stdlib/optionals.c
+++ b/src/stdlib/optionals.c
@@ -1,8 +1,11 @@
// Optional types
+#include <math.h>
+
#include "datatypes.h"
#include "metamethods.h"
#include "nums.h"
+#include "optionals.h"
#include "text.h"
#include "util.h"
diff --git a/src/stdlib/optionals.h b/src/stdlib/optionals.h
index 5be52e93..bd1f63b3 100644
--- a/src/stdlib/optionals.h
+++ b/src/stdlib/optionals.h
@@ -6,7 +6,6 @@
#include <stdint.h>
#include "datatypes.h"
-#include "integers.h"
#include "types.h"
#include "util.h"
diff --git a/src/stdlib/paths.h b/src/stdlib/paths.h
index 3a9cdef7..6284e55b 100644
--- a/src/stdlib/paths.h
+++ b/src/stdlib/paths.h
@@ -5,9 +5,9 @@
#include <stdbool.h>
#include <stdint.h>
-#include "types.h"
#include "datatypes.h"
-#include "optionals.h"
+#include "integers.h"
+#include "types.h"
Path_t Path$from_str(const char *str);
Path_t Path$from_text(Text_t text);
diff --git a/src/stdlib/print.c b/src/stdlib/print.c
index 476ddd7b..8e2dd862 100644
--- a/src/stdlib/print.c
+++ b/src/stdlib/print.c
@@ -1,4 +1,5 @@
// This file defines some of the helper functions used for printing values
+#include <ctype.h>
#include <stdio.h>
#include <string.h>
#include <unistd.h>
@@ -170,6 +171,7 @@ public int _print_char(FILE *f, char c)
if (name != NULL)
return fputs(name, f);
else if (isprint(c))
+
return fputc('\'', f) + fputc(c, f) + fputc('\'', f);
else
return (fputs("'\\x", f) + _print_hex(f, hex((uint64_t)c, .digits=2, .no_prefix=true, .uppercase=true))
diff --git a/src/stdlib/print.h b/src/stdlib/print.h
index ce20152b..56953866 100644
--- a/src/stdlib/print.h
+++ b/src/stdlib/print.h
@@ -10,7 +10,6 @@
//
#include <assert.h>
-#include <ctype.h>
#include <gc.h>
#include <stdbool.h>
#include <stdint.h>
diff --git a/src/stdlib/random.h b/src/stdlib/random.h
index 7311d695..8509dbd7 100644
--- a/src/stdlib/random.h
+++ b/src/stdlib/random.h
@@ -1,3 +1,6 @@
+#include <stdint.h>
+#include <assert.h>
+
#if defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__NetBSD__) || defined(__APPLE__)
#include <stdlib.h>
static ssize_t getrandom(void *buf, size_t buflen, unsigned int flags) {
diff --git a/src/stdlib/simpleparse.h b/src/stdlib/simpleparse.h
index 86a96ce8..da077e20 100644
--- a/src/stdlib/simpleparse.h
+++ b/src/stdlib/simpleparse.h
@@ -32,6 +32,7 @@ typedef struct { parse_type_e type; void *dest; } parse_element_t;
#define _parse_type(dest) _Generic((dest), \
some_char_t*: PARSE_SOME_OF, \
const char*: PARSE_LITERAL, \
+ char*: PARSE_LITERAL, \
const char**: PARSE_STRING, \
char**: PARSE_STRING, \
double*: PARSE_DOUBLE, \
diff --git a/src/stdlib/stacktrace.c b/src/stdlib/stacktrace.c
index 4c8b5af3..f408d753 100644
--- a/src/stdlib/stacktrace.c
+++ b/src/stdlib/stacktrace.c
@@ -1,3 +1,7 @@
+#ifndef _GNU_SOURCE
+#define _GNU_SOURCE
+#endif
+
#include <dlfcn.h>
#include <err.h>
#include <execinfo.h>
@@ -8,6 +12,7 @@
#include <string.h>
#include <unistd.h>
+#include "../config.h"
#include "print.h"
#include "simpleparse.h"
#include "util.h"
diff --git a/src/stdlib/stdlib.c b/src/stdlib/stdlib.c
index 767e7705..159acdb3 100644
--- a/src/stdlib/stdlib.c
+++ b/src/stdlib/stdlib.c
@@ -1,10 +1,12 @@
// Built-in functions
+#include <ctype.h>
#include <errno.h>
#include <execinfo.h>
#include <fcntl.h>
#include <gc.h>
#include <locale.h>
+#include <math.h>
#include <signal.h>
#include <stdbool.h>
#include <stdint.h>
diff --git a/src/stdlib/stdlib.h b/src/stdlib/stdlib.h
index 2dd3c5b7..8ac35f72 100644
--- a/src/stdlib/stdlib.h
+++ b/src/stdlib/stdlib.h
@@ -8,11 +8,9 @@
#include <stdio.h>
#include "datatypes.h"
-#include "files.h"
#include "print.h"
#include "stacktrace.h"
#include "types.h"
-#include "util.h"
extern bool USE_COLOR;
extern Text_t TOMO_VERSION_TEXT;
diff --git a/src/stdlib/text.c b/src/stdlib/text.c
index b246b6ce..d9793eb8 100644
--- a/src/stdlib/text.c
+++ b/src/stdlib/text.c
@@ -109,8 +109,9 @@
#include "bytes.h"
#include "datatypes.h"
-#include "lists.h"
#include "integers.h"
+#include "lists.h"
+#include "optionals.h"
#include "tables.h"
#include "text.h"
diff --git a/src/stdlib/text.h b/src/stdlib/text.h
index 637a3db7..cb3f1b90 100644
--- a/src/stdlib/text.h
+++ b/src/stdlib/text.h
@@ -7,9 +7,7 @@
#include <stdint.h>
#include "datatypes.h"
-#include "integers.h"
#include "mapmacro.h"
-#include "optionals.h"
#include "types.h"
#include "util.h"
diff --git a/src/stdlib/tomo.h b/src/stdlib/tomo.h
index 63abd2d6..d0463409 100644
--- a/src/stdlib/tomo.h
+++ b/src/stdlib/tomo.h
@@ -3,6 +3,7 @@
// All of the different builtin modules can be included by including this one
// import
+#include <math.h>
#include <stdbool.h>
#include <stdint.h>
#include <sys/param.h>
@@ -12,6 +13,7 @@
#include "c_strings.h"
#include "datatypes.h"
#include "enums.h"
+#include "files.h"
#include "functiontype.h"
#include "integers.h"
#include "lists.h"
diff --git a/src/structs.c b/src/structs.c
index 2d71fbac..0bcb8a08 100644
--- a/src/structs.c
+++ b/src/structs.c
@@ -6,6 +6,7 @@
#include "environment.h"
#include "naming.h"
#include "stdlib/text.h"
+#include "stdlib/tables.h"
#include "typecheck.h"
Text_t compile_struct_typeinfo(env_t *env, type_t *t, const char *name, arg_ast_t *fields, bool is_secret, bool is_opaque)
diff --git a/src/tomo.c b/src/tomo.c
index c9414393..1aa16581 100644
--- a/src/tomo.c
+++ b/src/tomo.c
@@ -13,6 +13,7 @@
#endif
#include "ast.h"
+#include "config.h"
#include "changes.md.h"
#include "compile.h"
#include "modules.h"
@@ -28,6 +29,7 @@
#include "stdlib/print.h"
#include "stdlib/random.h"
#include "stdlib/siphash.h"
+#include "stdlib/tables.h"
#include "stdlib/text.h"
#include "types.h"
diff --git a/src/typecheck.c b/src/typecheck.c
index 13a1c31e..19d6c09f 100644
--- a/src/typecheck.c
+++ b/src/typecheck.c
@@ -8,6 +8,7 @@
#include <sys/stat.h>
#include "ast.h"
+#include "config.h"
#include "environment.h"
#include "modules.h"
#include "naming.h"
diff --git a/src/typecheck.h b/src/typecheck.h
index 4342acc2..6f25fd1e 100644
--- a/src/typecheck.h
+++ b/src/typecheck.h
@@ -4,8 +4,6 @@
#include <gc.h>
#include <stdarg.h>
-#include <stdlib.h>
-#include <string.h>
#include "ast.h"
#include "environment.h"
diff --git a/test/extern.tm b/test/extern.tm
index 8e2b6c06..79239a39 100644
--- a/test/extern.tm
+++ b/test/extern.tm
@@ -1,3 +1,4 @@
+use <math.h>
extern sqrt : func(n:Num->Num)
func main()