diff options
| author | Bruce Hill <bruce@bruce-hill.com> | 2025-12-28 17:27:05 -0500 |
|---|---|---|
| committer | Bruce Hill <bruce@bruce-hill.com> | 2025-12-28 17:27:05 -0500 |
| commit | cfce376f585e0cd0231e95843617f75bd65b6c07 (patch) | |
| tree | 9457de8bb9b8d0643c83cd5c08182af6a86804b7 | |
| parent | b80e21ce3d673d981e44a725c62b62563a77db9b (diff) | |
Change autoformatter to no longer allow single-line functions
| -rw-r--r-- | .clang-format | 2 | ||||
| -rw-r--r-- | src/ast.c | 8 | ||||
| -rw-r--r-- | src/compile/blocks.c | 4 | ||||
| -rw-r--r-- | src/compile/promotions.c | 4 | ||||
| -rw-r--r-- | src/compile/text.h | 8 | ||||
| -rw-r--r-- | src/environment.c | 4 | ||||
| -rw-r--r-- | src/parse/expressions.c | 4 | ||||
| -rw-r--r-- | src/parse/utils.c | 8 | ||||
| -rw-r--r-- | src/stdlib/bigint.c | 4 | ||||
| -rw-r--r-- | src/stdlib/bigint.h | 24 | ||||
| -rw-r--r-- | src/stdlib/bools.h | 24 | ||||
| -rw-r--r-- | src/stdlib/bytes.c | 8 | ||||
| -rw-r--r-- | src/stdlib/bytes.h | 8 | ||||
| -rw-r--r-- | src/stdlib/intX.c.h | 8 | ||||
| -rw-r--r-- | src/stdlib/intX.h | 44 | ||||
| -rw-r--r-- | src/stdlib/lists.c | 12 | ||||
| -rw-r--r-- | src/stdlib/numX.c.h | 20 | ||||
| -rw-r--r-- | src/stdlib/numX.h | 24 | ||||
| -rw-r--r-- | src/stdlib/paths.c | 16 | ||||
| -rw-r--r-- | src/stdlib/print.h | 16 | ||||
| -rw-r--r-- | src/stdlib/stdlib.c | 12 | ||||
| -rw-r--r-- | src/stdlib/tables.c | 32 | ||||
| -rw-r--r-- | src/stdlib/tables.h | 2 | ||||
| -rw-r--r-- | src/stdlib/text.c | 12 | ||||
| -rw-r--r-- | src/stdlib/text.h | 4 | ||||
| -rw-r--r-- | src/types.c | 8 |
26 files changed, 237 insertions, 83 deletions
diff --git a/.clang-format b/.clang-format index 82e3ce3b..1fabd157 100644 --- a/.clang-format +++ b/.clang-format @@ -71,7 +71,7 @@ AllowShortCaseExpressionOnASingleLine: true AllowShortCaseLabelsOnASingleLine: true AllowShortCompoundRequirementOnASingleLine: true AllowShortEnumsOnASingleLine: true -AllowShortFunctionsOnASingleLine: All +AllowShortFunctionsOnASingleLine: false AllowShortIfStatementsOnASingleLine: AllIfsAndElse AllowShortLambdasOnASingleLine: All AllowShortLoopsOnASingleLine: false @@ -85,7 +85,9 @@ static Text_t tags_to_sexp(tag_ast_t *tags); static Text_t optional_sexp(const char *tag, ast_t *ast); static Text_t optional_type_sexp(const char *tag, type_ast_t *ast); -static Text_t quoted_text(const char *text) { return Text$quoted(Text$from_str(text), false, Text("\"")); } +static Text_t quoted_text(const char *text) { + return Text$quoted(Text$from_str(text), false, Text("\"")); +} Text_t ast_list_to_sexp(ast_list_t *asts) { Text_t c = EMPTY_TEXT; @@ -281,7 +283,9 @@ Text_t ast_to_sexp(ast_t *ast) { } } -const char *ast_to_sexp_str(ast_t *ast) { return Text$as_c_string(ast_to_sexp(ast)); } +const char *ast_to_sexp_str(ast_t *ast) { + return Text$as_c_string(ast_to_sexp(ast)); +} OptionalText_t ast_source(ast_t *ast) { if (ast == NULL || ast->start == NULL || ast->end == NULL) return NONE_TEXT; diff --git a/src/compile/blocks.c b/src/compile/blocks.c index 1059fd34..66869ecc 100644 --- a/src/compile/blocks.c +++ b/src/compile/blocks.c @@ -9,7 +9,9 @@ #include "compilation.h" public -Text_t compile_block(env_t *env, ast_t *ast) { return Texts("{\n", compile_inline_block(env, ast), "}\n"); } +Text_t compile_block(env_t *env, ast_t *ast) { + return Texts("{\n", compile_inline_block(env, ast), "}\n"); +} Text_t compile_block_expression(env_t *env, ast_t *ast) { ast_list_t *stmts = Match(ast, Block)->statements; diff --git a/src/compile/promotions.c b/src/compile/promotions.c index 482e5ed0..7a169821 100644 --- a/src/compile/promotions.c +++ b/src/compile/promotions.c @@ -8,7 +8,9 @@ #include "../types.h" #include "compilation.h" -static Text_t quoted_str(const char *str) { return Text$quoted(Text$from_str(str), false, Text("\"")); } +static Text_t quoted_str(const char *str) { + return Text$quoted(Text$from_str(str), false, Text("\"")); +} public bool promote(env_t *env, ast_t *ast, Text_t *code, type_t *actual, type_t *needed) { diff --git a/src/compile/text.h b/src/compile/text.h index c160c7a9..ae3cc5c3 100644 --- a/src/compile/text.h +++ b/src/compile/text.h @@ -14,5 +14,9 @@ Text_t compile_text(env_t *env, ast_t *ast, Text_t color); Text_t compile_text_literal(Text_t literal); Text_t expr_as_text(Text_t expr, type_t *t, Text_t color); -MACROLIKE Text_t quoted_str(const char *str) { return Text$quoted(Text$from_str(str), false, Text("\"")); } -MACROLIKE Text_t quoted_text(Text_t text) { return Text$quoted(text, false, Text("\"")); } +MACROLIKE Text_t quoted_str(const char *str) { + return Text$quoted(Text$from_str(str), false, Text("\"")); +} +MACROLIKE Text_t quoted_text(Text_t text) { + return Text$quoted(text, false, Text("\"")); +} diff --git a/src/environment.c b/src/environment.c index a82274e7..b3009a5e 100644 --- a/src/environment.c +++ b/src/environment.c @@ -715,7 +715,9 @@ env_t *namespace_env(env_t *env, const char *namespace_name) { return ns_env; } -PUREFUNC binding_t *get_binding(env_t *env, const char *name) { return Table$str_get(*env->locals, name); } +PUREFUNC binding_t *get_binding(env_t *env, const char *name) { + return Table$str_get(*env->locals, name); +} binding_t *get_namespace_binding(env_t *env, ast_t *self, const char *name) { type_t *self_type = get_type(env, self); diff --git a/src/parse/expressions.c b/src/parse/expressions.c index d031c49f..27e44129 100644 --- a/src/parse/expressions.c +++ b/src/parse/expressions.c @@ -195,7 +195,9 @@ ast_t *parse_term(parse_ctx_t *ctx, const char *pos) { return term; } -ast_t *parse_expr(parse_ctx_t *ctx, const char *pos) { return parse_infix_expr(ctx, pos, 0); } +ast_t *parse_expr(parse_ctx_t *ctx, const char *pos) { + return parse_infix_expr(ctx, pos, 0); +} ast_t *parse_extended_expr(parse_ctx_t *ctx, const char *pos) { ast_t *expr = NULL; diff --git a/src/parse/utils.c b/src/parse/utils.c index f1b518ca..03e0ebcd 100644 --- a/src/parse/utils.c +++ b/src/parse/utils.c @@ -41,7 +41,9 @@ size_t some_not(const char **pos, const char *forbid) { return len; } -size_t spaces(const char **pos) { return some_of(pos, " \t"); } +size_t spaces(const char **pos) { + return some_of(pos, " \t"); +} void whitespace(parse_ctx_t *ctx, const char **pos) { while (some_of(pos, " \t\r\n") || comment(ctx, pos)) @@ -93,7 +95,9 @@ const char *get_id(const char **inout) { return word; } -PUREFUNC const char *eol(const char *str) { return str + strcspn(str, "\r\n"); } +PUREFUNC const char *eol(const char *str) { + return str + strcspn(str, "\r\n"); +} bool comment(parse_ctx_t *ctx, const char **pos) { if ((*pos)[0] == '#') { diff --git a/src/stdlib/bigint.c b/src/stdlib/bigint.c index 2d145bd5..c9bfb68e 100644 --- a/src/stdlib/bigint.c +++ b/src/stdlib/bigint.c @@ -393,7 +393,9 @@ PUREFUNC Closure_t Int$onward(Int_t first, Int_t step) { } public -Int_t Int$from_str(const char *str) { return Int$parse(Text$from_str(str), NONE_INT, NULL); } +Int_t Int$from_str(const char *str) { + return Int$parse(Text$from_str(str), NONE_INT, NULL); +} public OptionalInt_t Int$parse(Text_t text, OptionalInt_t base, Text_t *remainder) { diff --git a/src/stdlib/bigint.h b/src/stdlib/bigint.h index 9ce4c800..8c3502bf 100644 --- a/src/stdlib/bigint.h +++ b/src/stdlib/bigint.h @@ -195,18 +195,30 @@ MACROLIKE PUREFUNC Int_t Int$from_num64(double n, bool truncate) { if (!truncate && unlikely(mpz_get_d(result) != n)) fail("Could not convert to an integer without truncation: ", n); return Int$from_mpz(result); } -MACROLIKE PUREFUNC Int_t Int$from_num32(float n, bool truncate) { return Int$from_num64((double)n, truncate); } +MACROLIKE PUREFUNC Int_t Int$from_num32(float n, bool truncate) { + return Int$from_num64((double)n, truncate); +} MACROLIKE Int_t Int$from_int64(int64_t i) { if likely (i >= SMALLEST_SMALL_INT && i <= BIGGEST_SMALL_INT) return (Int_t){.small = (i << 2L) | 1L}; mpz_t result; mpz_init_set_si(result, i); return Int$from_mpz(result); } -MACROLIKE CONSTFUNC Int_t Int$from_int32(Int32_t i) { return Int$from_int64((Int32_t)i); } -MACROLIKE CONSTFUNC Int_t Int$from_int16(Int16_t i) { return I_small(i); } -MACROLIKE CONSTFUNC Int_t Int$from_int8(Int8_t i) { return I_small(i); } -MACROLIKE CONSTFUNC Int_t Int$from_byte(Byte_t b) { return I_small(b); } -MACROLIKE CONSTFUNC Int_t Int$from_bool(Bool_t b) { return I_small(b); } +MACROLIKE CONSTFUNC Int_t Int$from_int32(Int32_t i) { + return Int$from_int64((Int32_t)i); +} +MACROLIKE CONSTFUNC Int_t Int$from_int16(Int16_t i) { + return I_small(i); +} +MACROLIKE CONSTFUNC Int_t Int$from_int8(Int8_t i) { + return I_small(i); +} +MACROLIKE CONSTFUNC Int_t Int$from_byte(Byte_t b) { + return I_small(b); +} +MACROLIKE CONSTFUNC Int_t Int$from_bool(Bool_t b) { + return I_small(b); +} #ifdef __GNUC__ #pragma GCC diagnostic pop diff --git a/src/stdlib/bools.h b/src/stdlib/bools.h index 52bd45a8..17ff3681 100644 --- a/src/stdlib/bools.h +++ b/src/stdlib/bools.h @@ -13,11 +13,23 @@ PUREFUNC Text_t Bool$as_text(const void *b, bool colorize, const TypeInfo_t *type); OptionalBool_t Bool$parse(Text_t text, Text_t *remainder); -MACROLIKE Bool_t Bool$from_int(Int_t i) { return (i.small != 0); } -MACROLIKE Bool_t Bool$from_int64(Int64_t i) { return (i != 0); } -MACROLIKE Bool_t Bool$from_int32(Int32_t i) { return (i != 0); } -MACROLIKE Bool_t Bool$from_int16(Int16_t i) { return (i != 0); } -MACROLIKE Bool_t Bool$from_int8(Int8_t i) { return (i != 0); } -MACROLIKE Bool_t Bool$from_byte(uint8_t b) { return (b != 0); } +MACROLIKE Bool_t Bool$from_int(Int_t i) { + return (i.small != 0); +} +MACROLIKE Bool_t Bool$from_int64(Int64_t i) { + return (i != 0); +} +MACROLIKE Bool_t Bool$from_int32(Int32_t i) { + return (i != 0); +} +MACROLIKE Bool_t Bool$from_int16(Int16_t i) { + return (i != 0); +} +MACROLIKE Bool_t Bool$from_int8(Int8_t i) { + return (i != 0); +} +MACROLIKE Bool_t Bool$from_byte(uint8_t b) { + return (b != 0); +} extern const TypeInfo_t Bool$info; diff --git a/src/stdlib/bytes.c b/src/stdlib/bytes.c index a1e953a0..2b8dab4d 100644 --- a/src/stdlib/bytes.c +++ b/src/stdlib/bytes.c @@ -30,7 +30,9 @@ PUREFUNC public Text_t Byte$as_text(const void *b, bool colorize, const TypeInfo } public -CONSTFUNC bool Byte$is_between(const Byte_t x, const Byte_t low, const Byte_t high) { return low <= x && x <= high; } +CONSTFUNC bool Byte$is_between(const Byte_t x, const Byte_t low, const Byte_t high) { + return low <= x && x <= high; +} public OptionalByte_t Byte$parse(Text_t text, OptionalInt_t base, Text_t *remainder) { @@ -67,7 +69,9 @@ public bool Byte$get_bit(Byte_t x, Int_t bit_index) { if (Int$compare_value(bit_index, I(1)) < 0) fail("Invalid bit index (expected 1 or higher): ", bit_index); if (Int$compare_value(bit_index, I(8)) > 0) - fail("Bit index is too large! There are only 8 bits in a byte, but index is: ", bit_index); + fail("Bit index is too large! There are only 8 bits in a byte, but index " + "is: ", + bit_index); return ((x & (Byte_t)(1L << (Int64$from_int(bit_index, true) - 1L))) != 0); } diff --git a/src/stdlib/bytes.h b/src/stdlib/bytes.h index 6581f300..b0a1c213 100644 --- a/src/stdlib/bytes.h +++ b/src/stdlib/bytes.h @@ -21,8 +21,12 @@ Byte_t Byte$from_int16(int16_t i, bool truncate); OptionalByte_t Byte$parse(Text_t text, OptionalInt_t base, Text_t *remainder); Closure_t Byte$to(Byte_t first, Byte_t last, OptionalInt8_t step); -MACROLIKE Byte_t Byte$from_int8(int8_t i) { return (Byte_t)i; } -MACROLIKE Byte_t Byte$from_bool(bool b) { return (Byte_t)b; } +MACROLIKE Byte_t Byte$from_int8(int8_t i) { + return (Byte_t)i; +} +MACROLIKE Byte_t Byte$from_bool(bool b) { + return (Byte_t)b; +} CONSTFUNC bool Byte$is_between(const Byte_t x, const Byte_t low, const Byte_t high); extern const Byte_t Byte$min; diff --git a/src/stdlib/intX.c.h b/src/stdlib/intX.c.h index 03322e5b..3e6648f7 100644 --- a/src/stdlib/intX.c.h +++ b/src/stdlib/intX.c.h @@ -101,7 +101,9 @@ Text_t NAMESPACED(as_text)(const void *i, bool colorize, const TypeInfo_t *info) return colorize ? Text$concat(Text("\033[35m"), text, Text("\033[m")) : text; } public -Text_t NAMESPACED(value_as_text)(INT_T i) { return _int64_to_text((int64_t)i); } +Text_t NAMESPACED(value_as_text)(INT_T i) { + return _int64_to_text((int64_t)i); +} public PUREFUNC int32_t NAMESPACED(compare)(const void *x, const void *y, const TypeInfo_t *info) { (void)info; @@ -117,7 +119,9 @@ CONSTFUNC bool NAMESPACED(is_between)(const INT_T x, const INT_T low, const INT_ return low <= x && x <= high; } public -CONSTFUNC INT_T NAMESPACED(clamped)(INT_T x, INT_T min, INT_T max) { return x < min ? min : (x > max ? max : x); } +CONSTFUNC INT_T NAMESPACED(clamped)(INT_T x, INT_T min, INT_T max) { + return x < min ? min : (x > max ? max : x); +} public Text_t NAMESPACED(hex)(INT_T i, Int_t digits_int, bool uppercase, bool prefix) { Int_t as_int = Int$from_int64((int64_t)i); diff --git a/src/stdlib/intX.h b/src/stdlib/intX.h index 1c8b4a05..3c4fa976 100644 --- a/src/stdlib/intX.h +++ b/src/stdlib/intX.h @@ -49,8 +49,12 @@ Closure_t NAMESPACED(onward)(INTX_T first, INTX_T step); PUREFUNC OPT_T NAMESPACED(parse)(Text_t text, OptionalInt_t base, Text_t *remainder); CONSTFUNC bool NAMESPACED(is_between)(const INTX_T x, const INTX_T low, const INTX_T high); CONSTFUNC INTX_T NAMESPACED(clamped)(INTX_T x, INTX_T min, INTX_T max); -MACROLIKE CONSTFUNC INTX_T NAMESPACED(from_byte)(Byte_t b) { return (INTX_T)b; } -MACROLIKE CONSTFUNC INTX_T NAMESPACED(from_bool)(Bool_t b) { return (INTX_T)b; } +MACROLIKE CONSTFUNC INTX_T NAMESPACED(from_byte)(Byte_t b) { + return (INTX_T)b; +} +MACROLIKE CONSTFUNC INTX_T NAMESPACED(from_bool)(Bool_t b) { + return (INTX_T)b; +} CONSTFUNC INTX_T NAMESPACED(gcd)(INTX_T x, INTX_T y); extern const INTX_T NAMESPACED(min), NAMESPACED(max); extern const TypeInfo_t NAMESPACED(info); @@ -75,15 +79,25 @@ MACROLIKE INTX_T NAMESPACED(modulo)(INTX_T D, INTX_T d) { return r; } -MACROLIKE INTX_T NAMESPACED(modulo1)(INTX_T D, INTX_T d) { return NAMESPACED(modulo)(D - 1, d) + 1; } +MACROLIKE INTX_T NAMESPACED(modulo1)(INTX_T D, INTX_T d) { + return NAMESPACED(modulo)(D - 1, d) + 1; +} -MACROLIKE PUREFUNC INTX_T NAMESPACED(wrapping_plus)(INTX_T x, INTX_T y) { return (INTX_T)((UINTX_T)x + (UINTX_T)y); } +MACROLIKE PUREFUNC INTX_T NAMESPACED(wrapping_plus)(INTX_T x, INTX_T y) { + return (INTX_T)((UINTX_T)x + (UINTX_T)y); +} -MACROLIKE PUREFUNC INTX_T NAMESPACED(wrapping_minus)(INTX_T x, INTX_T y) { return (INTX_T)((UINTX_T)x + (UINTX_T)y); } +MACROLIKE PUREFUNC INTX_T NAMESPACED(wrapping_minus)(INTX_T x, INTX_T y) { + return (INTX_T)((UINTX_T)x + (UINTX_T)y); +} -MACROLIKE PUREFUNC INTX_T NAMESPACED(unsigned_left_shifted)(INTX_T x, INTX_T y) { return (INTX_T)((UINTX_T)x << y); } +MACROLIKE PUREFUNC INTX_T NAMESPACED(unsigned_left_shifted)(INTX_T x, INTX_T y) { + return (INTX_T)((UINTX_T)x << y); +} -MACROLIKE PUREFUNC INTX_T NAMESPACED(unsigned_right_shifted)(INTX_T x, INTX_T y) { return (INTX_T)((UINTX_T)x >> y); } +MACROLIKE PUREFUNC INTX_T NAMESPACED(unsigned_right_shifted)(INTX_T x, INTX_T y) { + return (INTX_T)((UINTX_T)x >> y); +} void NAMESPACED(serialize)(const void *obj, FILE *out, Table_t *, const TypeInfo_t *); void NAMESPACED(deserialize)(FILE *in, void *outval, List_t *, const TypeInfo_t *); @@ -121,7 +135,9 @@ MACROLIKE PUREFUNC INTX_T NAMESPACED(from_int64)(Int64_t i64, bool truncate) { return i; } #elif INTX_H__INT_BITS > 64 -MACROLIKE CONSTFUNC INTX_T NAMESPACED(from_int64)(Int64_t i) { return (INTX_T)i; } +MACROLIKE CONSTFUNC INTX_T NAMESPACED(from_int64)(Int64_t i) { + return (INTX_T)i; +} #endif #if INTX_H__INT_BITS < 32 @@ -131,7 +147,9 @@ MACROLIKE PUREFUNC INTX_T NAMESPACED(from_int32)(Int32_t i32, bool truncate) { return i; } #elif INTX_H__INT_BITS > 32 -MACROLIKE CONSTFUNC INTX_T NAMESPACED(from_int32)(Int32_t i) { return (INTX_T)i; } +MACROLIKE CONSTFUNC INTX_T NAMESPACED(from_int32)(Int32_t i) { + return (INTX_T)i; +} #endif #if INTX_H__INT_BITS < 16 @@ -141,11 +159,15 @@ MACROLIKE PUREFUNC INTX_T NAMESPACED(from_int16)(Int16_t i16, bool truncate) { return i; } #elif INTX_H__INT_BITS > 16 -MACROLIKE CONSTFUNC INTX_T NAMESPACED(from_int16)(Int16_t i) { return (INTX_T)i; } +MACROLIKE CONSTFUNC INTX_T NAMESPACED(from_int16)(Int16_t i) { + return (INTX_T)i; +} #endif #if INTX_H__INT_BITS > 8 -MACROLIKE CONSTFUNC INTX_T NAMESPACED(from_int8)(Int8_t i) { return (INTX_T)i; } +MACROLIKE CONSTFUNC INTX_T NAMESPACED(from_int8)(Int8_t i) { + return (INTX_T)i; +} #endif #undef PASTE3_ diff --git a/src/stdlib/lists.c b/src/stdlib/lists.c index db514671..9753cd86 100644 --- a/src/stdlib/lists.c +++ b/src/stdlib/lists.c @@ -440,10 +440,14 @@ List_t List$sample(List_t list, Int_t int_n, List_t weights, OptionalClosure_t r } public -List_t List$from(List_t list, Int_t first) { return List$slice(list, first, I_small(-1)); } +List_t List$from(List_t list, Int_t first) { + return List$slice(list, first, I_small(-1)); +} public -List_t List$to(List_t list, Int_t last) { return List$slice(list, I_small(1), last); } +List_t List$to(List_t list, Int_t last) { + return List$slice(list, I_small(1), last); +} public List_t List$by(List_t list, Int_t int_stride, int64_t padded_item_size) { @@ -554,7 +558,9 @@ bool List$has(List_t list, void *item, const TypeInfo_t *type) { } public -void List$clear(List_t *list) { *list = list->atomic ? EMPTY_ATOMIC_LIST : EMPTY_LIST; } +void List$clear(List_t *list) { + *list = list->atomic ? EMPTY_ATOMIC_LIST : EMPTY_LIST; +} public int32_t List$compare(const void *vx, const void *vy, const TypeInfo_t *type) { diff --git a/src/stdlib/numX.c.h b/src/stdlib/numX.c.h index 2fde8c45..ed91fbf5 100644 --- a/src/stdlib/numX.c.h +++ b/src/stdlib/numX.c.h @@ -66,7 +66,9 @@ PUREFUNC int32_t NAMESPACED(compare)(const void *x, const void *y, const TypeInf } #elif NUMX_C_H__BITS == 32 public -PUREFUNC Text_t NAMESPACED(value_as_text)(NUM_T x) { return Num$value_as_text((double)x); } +PUREFUNC Text_t NAMESPACED(value_as_text)(NUM_T x) { + return Num$value_as_text((double)x); +} public PUREFUNC Text_t NAMESPACED(as_text)(const void *x, bool colorize, const TypeInfo_t *info) { (void)info; @@ -147,7 +149,9 @@ CONSTFUNC NUM_T NAMESPACED(mod1)(NUM_T num, NUM_T modulus) { } public -CONSTFUNC NUM_T NAMESPACED(mix)(NUM_T amount, NUM_T x, NUM_T y) { return (SUFFIXED(1.0) - amount) * x + amount * y; } +CONSTFUNC NUM_T NAMESPACED(mix)(NUM_T amount, NUM_T x, NUM_T y) { + return (SUFFIXED(1.0) - amount) * x + amount * y; +} public CONSTFUNC bool NAMESPACED(is_between)(const NUM_T x, const NUM_T low, const NUM_T high) { @@ -184,11 +188,17 @@ CONSTFUNC bool NAMESPACED(is_none)(const void *n, const TypeInfo_t *info) { } public -CONSTFUNC bool NAMESPACED(isinf)(NUM_T n) { return (fpclassify(n) == FP_INFINITE); } +CONSTFUNC bool NAMESPACED(isinf)(NUM_T n) { + return (fpclassify(n) == FP_INFINITE); +} public -CONSTFUNC bool NAMESPACED(finite)(NUM_T n) { return (fpclassify(n) != FP_INFINITE); } +CONSTFUNC bool NAMESPACED(finite)(NUM_T n) { + return (fpclassify(n) != FP_INFINITE); +} public -CONSTFUNC bool NAMESPACED(isnan)(NUM_T n) { return (fpclassify(n) == FP_NAN); } +CONSTFUNC bool NAMESPACED(isnan)(NUM_T n) { + return (fpclassify(n) == FP_NAN); +} public const TypeInfo_t NAMESPACED(info) = { diff --git a/src/stdlib/numX.h b/src/stdlib/numX.h index 3d65cb59..87794762 100644 --- a/src/stdlib/numX.h +++ b/src/stdlib/numX.h @@ -53,9 +53,13 @@ CONSTFUNC bool NAMESPACED(is_between)(const NUM_T x, const NUM_T low, const NUM_ CONSTFUNC NUM_T NAMESPACED(clamped)(NUM_T x, NUM_T low, NUM_T high); #if NUMX_H__BITS == 64 -MACROLIKE CONSTFUNC NUM_T NAMESPACED(from_num32)(float n) { return (NUM_T)n; } +MACROLIKE CONSTFUNC NUM_T NAMESPACED(from_num32)(float n) { + return (NUM_T)n; +} #elif NUMX_H__BITS == 32 -MACROLIKE CONSTFUNC NUM_T NAMESPACED(from_num64)(double n) { return (NUM_T)n; } +MACROLIKE CONSTFUNC NUM_T NAMESPACED(from_num64)(double n) { + return (NUM_T)n; +} #endif #ifdef __GNUC__ @@ -88,10 +92,18 @@ MACROLIKE CONSTFUNC NUM_T NAMESPACED(from_int64)(Int64_t i, bool truncate) { fail("Could not convert integer to " TYPE_STR " without losing precision: ", i); return n; } -MACROLIKE CONSTFUNC NUM_T NAMESPACED(from_int32)(Int32_t i) { return (NUM_T)i; } -MACROLIKE CONSTFUNC NUM_T NAMESPACED(from_int16)(Int16_t i) { return (NUM_T)i; } -MACROLIKE CONSTFUNC NUM_T NAMESPACED(from_int8)(Int8_t i) { return (NUM_T)i; } -MACROLIKE CONSTFUNC NUM_T NAMESPACED(from_byte)(Byte_t i) { return (NUM_T)i; } +MACROLIKE CONSTFUNC NUM_T NAMESPACED(from_int32)(Int32_t i) { + return (NUM_T)i; +} +MACROLIKE CONSTFUNC NUM_T NAMESPACED(from_int16)(Int16_t i) { + return (NUM_T)i; +} +MACROLIKE CONSTFUNC NUM_T NAMESPACED(from_int8)(Int8_t i) { + return (NUM_T)i; +} +MACROLIKE CONSTFUNC NUM_T NAMESPACED(from_byte)(Byte_t i) { + return (NUM_T)i; +} extern const TypeInfo_t NAMESPACED(info); diff --git a/src/stdlib/paths.c b/src/stdlib/paths.c index e3028cce..cbe52f5f 100644 --- a/src/stdlib/paths.c +++ b/src/stdlib/paths.c @@ -98,7 +98,9 @@ Path_t Path$from_str(const char *str) { } public -Path_t Path$from_text(Text_t text) { return Path$from_str(Text$as_c_string(text)); } +Path_t Path$from_text(Text_t text) { + return Path$from_str(Text$as_c_string(text)); +} public Path_t Path$expand_home(Path_t path) { @@ -645,7 +647,9 @@ OptionalPath_t Path$write_unique_bytes(Path_t path, List_t bytes) { } public -OptionalPath_t Path$write_unique(Path_t path, Text_t text) { return Path$write_unique_bytes(path, Text$utf8(text)); } +OptionalPath_t Path$write_unique(Path_t path, Text_t text) { + return Path$write_unique_bytes(path, Text$utf8(text)); +} public OptionalPath_t Path$parent(Path_t path) { @@ -709,7 +713,9 @@ Path_t Path$child(Path_t path, Text_t name) { } public -Path_t Path$sibling(Path_t path, Text_t name) { return Path$child(Path$parent(path), name); } +Path_t Path$sibling(Path_t path, Text_t name) { + return Path$child(Path$parent(path), name); +} public OptionalPath_t Path$with_extension(Path_t path, Text_t extension, bool replace) { @@ -865,7 +871,9 @@ int Path$print(FILE *f, Path_t path) { } public -const char *Path$as_c_string(Path_t path) { return String(path); } +const char *Path$as_c_string(Path_t path) { + return String(path); +} public Text_t Path$as_text(const void *obj, bool color, const TypeInfo_t *type) { diff --git a/src/stdlib/print.h b/src/stdlib/print.h index 7106d561..943a084a 100644 --- a/src/stdlib/print.h +++ b/src/stdlib/print.h @@ -80,10 +80,18 @@ int _print_double(FILE *f, double x); int _print_hex(FILE *f, hex_format_t hex); int _print_hex_double(FILE *f, hex_double_t hex); int _print_oct(FILE *f, oct_format_t oct); -PRINT_FN _print_float(FILE *f, float x) { return _print_double(f, (double)x); } -PRINT_FN _print_pointer(FILE *f, void *p) { return _print_hex(f, hex((uint64_t)p)); } -PRINT_FN _print_bool(FILE *f, bool b) { return fputs(b ? "yes" : "no", f); } -PRINT_FN _print_str(FILE *f, const char *s) { return fputs(s ? s : "(null)", f); } +PRINT_FN _print_float(FILE *f, float x) { + return _print_double(f, (double)x); +} +PRINT_FN _print_pointer(FILE *f, void *p) { + return _print_hex(f, hex((uint64_t)p)); +} +PRINT_FN _print_bool(FILE *f, bool b) { + return fputs(b ? "yes" : "no", f); +} +PRINT_FN _print_str(FILE *f, const char *s) { + return fputs(s ? s : "(null)", f); +} int _print_char(FILE *f, char c); int _print_quoted(FILE *f, quoted_t quoted); PRINT_FN _print_string_slice(FILE *f, string_slice_t slice) { diff --git a/src/stdlib/stdlib.c b/src/stdlib/stdlib.c index 7b038dac..a05b8753 100644 --- a/src/stdlib/stdlib.c +++ b/src/stdlib/stdlib.c @@ -159,10 +159,14 @@ void tomo_init(void) { } public -_Noreturn void fail_text(Text_t message) { fail(message); } +_Noreturn void fail_text(Text_t message) { + fail(message); +} public -Text_t builtin_last_err() { return Text$from_str(strerror(errno)); } +Text_t builtin_last_err() { + return Text$from_str(strerror(errno)); +} static int _inspect_depth = 0; static file_t *file = NULL; @@ -328,7 +332,9 @@ typedef struct cleanup_s { static cleanup_t *cleanups = NULL; public -void tomo_at_cleanup(Closure_t fn) { cleanups = new (cleanup_t, .cleanup_fn = fn, .next = cleanups); } +void tomo_at_cleanup(Closure_t fn) { + cleanups = new (cleanup_t, .cleanup_fn = fn, .next = cleanups); +} public void tomo_cleanup(void) { diff --git a/src/stdlib/tables.c b/src/stdlib/tables.c index adbdd6bd..753059c8 100644 --- a/src/stdlib/tables.c +++ b/src/stdlib/tables.c @@ -137,7 +137,8 @@ static void Table$set_bucket(Table_t *t, const void *entry, int32_t index, const bucket->occupied = 1; bucket->index = index; bucket->next_bucket = END_OF_CHAIN; - } else { // Collided with the start of a chain, put the new entry in chain position #2 + } else { // Collided with the start of a chain, put the new entry in chain + // position #2 buckets[t->bucket_info->last_free] = (bucket_t){.occupied = 1, .index = index, .next_bucket = bucket->next_bucket}; bucket->next_bucket = t->bucket_info->last_free; @@ -146,7 +147,8 @@ static void Table$set_bucket(Table_t *t, const void *entry, int32_t index, const static void hashmap_resize_buckets(Table_t *t, uint32_t new_capacity, const TypeInfo_t *type) { if (unlikely(new_capacity > TABLE_MAX_BUCKETS)) - fail("Table has exceeded the maximum table size (2^31) and cannot grow further!"); + fail("Table has exceeded the maximum table size (2^31) and cannot grow " + "further!"); size_t alloc_size = sizeof(bucket_info_t) + sizeof(bucket_t[new_capacity]); t->bucket_info = GC_MALLOC_ATOMIC(alloc_size); memset(t->bucket_info->buckets, 0, sizeof(bucket_t[new_capacity])); @@ -316,7 +318,9 @@ CONSTFUNC public void *Table$entry(Table_t t, int64_t n) { } public -void Table$clear(Table_t *t) { *t = EMPTY_TABLE; } +void Table$clear(Table_t *t) { + *t = EMPTY_TABLE; +} public Table_t Table$sorted(Table_t t, const TypeInfo_t *type) { @@ -535,7 +539,8 @@ Table_t Table$from_entries(List_t entries, const TypeInfo_t *type) { // "set intersection" in formal terms public Table_t Table$intersection(Table_t a, Table_t b, const TypeInfo_t *type) { - // Return a table such that t[k]==a[k] for all k such that a.has(k), b.has(k), and a[k]==b[k] + // Return a table such that t[k]==a[k] for all k such that a.has(k), b.has(k), + // and a[k]==b[k] Table_t result = EMPTY_TABLE; const size_t offset = value_offset(type); for (Table_t *t = &a; t; t = t->fallback) { @@ -553,8 +558,8 @@ Table_t Table$intersection(Table_t a, Table_t b, const TypeInfo_t *type) { // "set union" in formal terms public Table_t Table$with(Table_t a, Table_t b, const TypeInfo_t *type) { - // return a table such that t[k]==b[k] for all k such that b.has(k), and t[k]==a[k] for all k such that a.has(k) and - // not b.has(k) + // return a table such that t[k]==b[k] for all k such that b.has(k), and + // t[k]==a[k] for all k such that a.has(k) and not b.has(k) Table_t result = EMPTY_TABLE; const size_t offset = value_offset(type); for (Table_t *t = &a; t; t = t->fallback) { @@ -596,7 +601,8 @@ Table_t Table$difference(Table_t a, Table_t b, const TypeInfo_t *type) { // "without" is "set difference" in formal terms public Table_t Table$without(Table_t a, Table_t b, const TypeInfo_t *type) { - // Return a table such that t[k]==a[k] for all k such that not b.has(k) or b[k] != a[k] + // Return a table such that t[k]==a[k] for all k such that not b.has(k) or + // b[k] != a[k] Table_t result = EMPTY_TABLE; const size_t offset = value_offset(type); for (Table_t *t = &a; t; t = t->fallback) { @@ -655,12 +661,18 @@ void *Table$str_reserve(Table_t *t, const char *key, const void *value) { } public -void Table$str_set(Table_t *t, const char *key, const void *value) { Table$set(t, &key, &value, &CStrToVoidStarTable); } +void Table$str_set(Table_t *t, const char *key, const void *value) { + Table$set(t, &key, &value, &CStrToVoidStarTable); +} public -void Table$str_remove(Table_t *t, const char *key) { return Table$remove(t, &key, &CStrToVoidStarTable); } +void Table$str_remove(Table_t *t, const char *key) { + return Table$remove(t, &key, &CStrToVoidStarTable); +} -CONSTFUNC public void *Table$str_entry(Table_t t, int64_t n) { return Table$entry(t, n); } +CONSTFUNC public void *Table$str_entry(Table_t t, int64_t n) { + return Table$entry(t, n); +} PUREFUNC public bool Table$is_none(const void *obj, const TypeInfo_t *info) { (void)info; diff --git a/src/stdlib/tables.h b/src/stdlib/tables.h index 93da465e..f3f9d2c7 100644 --- a/src/stdlib/tables.h +++ b/src/stdlib/tables.h @@ -4,7 +4,7 @@ #include <stdbool.h> #include <stdint.h> -#include <string.h> +#include <string.h> // IWYU pragma: export #include "datatypes.h" #include "lists.h" diff --git a/src/stdlib/text.c b/src/stdlib/text.c index 411f3546..4bf6d999 100644 --- a/src/stdlib/text.c +++ b/src/stdlib/text.c @@ -669,10 +669,14 @@ Text_t Text$slice(Text_t text, Int_t first_int, Int_t last_int) { } public -Text_t Text$from(Text_t text, Int_t first) { return Text$slice(text, first, I_small(-1)); } +Text_t Text$from(Text_t text, Int_t first) { + return Text$slice(text, first, I_small(-1)); +} public -Text_t Text$to(Text_t text, Int_t last) { return Text$slice(text, I_small(1), last); } +Text_t Text$to(Text_t text, Int_t last) { + return Text$slice(text, I_small(1), last); +} public Text_t Text$reversed(Text_t text) { @@ -814,7 +818,9 @@ OptionalText_t Text$from_strn(const char *str, size_t len) { } public -OptionalText_t Text$from_str(const char *str) { return str ? Text$from_strn(str, strlen(str)) : Text(""); } +OptionalText_t Text$from_str(const char *str) { + return str ? Text$from_strn(str, strlen(str)) : Text(""); +} static void u8_buf_append(Text_t text, Byte_t **buf, int64_t *capacity, int64_t *i) { switch (text.tag) { diff --git a/src/stdlib/text.h b/src/stdlib/text.h index 08423cfe..856b173a 100644 --- a/src/stdlib/text.h +++ b/src/stdlib/text.h @@ -33,7 +33,9 @@ static inline Text_t Text_from_str_literal(const char *str) { return (Text_t){.length = strlen(str), .tag = TEXT_ASCII, .ascii = str}; } -static inline Text_t Text_from_text(Text_t t) { return t; } +static inline Text_t Text_from_text(Text_t t) { + return t; +} #define convert_to_text(x) \ _Generic(x, \ diff --git a/src/types.c b/src/types.c index 1ccb7952..24453150 100644 --- a/src/types.c +++ b/src/types.c @@ -136,7 +136,9 @@ bool type_is_a(type_t *t, type_t *req) { return false; } -type_t *non_optional(type_t *t) { return t->tag == OptionalType ? Match(t, OptionalType)->type : t; } +type_t *non_optional(type_t *t) { + return t->tag == OptionalType ? Match(t, OptionalType)->type : t; +} PUREFUNC type_t *value_type(type_t *t) { while (t->tag == PointerType) @@ -457,7 +459,9 @@ PUREFUNC bool can_promote(type_t *actual, type_t *needed) { return false; } -PUREFUNC bool is_int_type(type_t *t) { return t->tag == IntType || t->tag == BigIntType || t->tag == ByteType; } +PUREFUNC bool is_int_type(type_t *t) { + return t->tag == IntType || t->tag == BigIntType || t->tag == ByteType; +} PUREFUNC bool is_numeric_type(type_t *t) { return t->tag == IntType || t->tag == BigIntType || t->tag == NumType || t->tag == ByteType; |
