diff options
| author | Bruce Hill <bruce@bruce-hill.com> | 2025-04-15 19:59:14 -0400 |
|---|---|---|
| committer | Bruce Hill <bruce@bruce-hill.com> | 2025-04-15 19:59:14 -0400 |
| commit | e5420471a7364a92521575e7abd3a29a9318001b (patch) | |
| tree | 6b7aaccff3d033fdc49cee41874071637fa8b68e /src | |
| parent | c3615dc92c667899af7a11b2b25201dad5502ee6 (diff) | |
Make some compatibility fixes to make sure the compiler can fully build
using TinyCC
Diffstat (limited to 'src')
| -rw-r--r-- | src/compile.c | 14 | ||||
| -rw-r--r-- | src/cordhelpers.h | 2 | ||||
| -rw-r--r-- | src/environment.c | 2 | ||||
| -rw-r--r-- | src/repl.c | 3 | ||||
| -rw-r--r-- | src/stdlib/bools.c | 6 | ||||
| -rw-r--r-- | src/stdlib/bytes.c | 7 | ||||
| -rw-r--r-- | src/stdlib/c_strings.c | 15 | ||||
| -rw-r--r-- | src/stdlib/enums.c | 3 | ||||
| -rw-r--r-- | src/stdlib/functiontype.c | 3 | ||||
| -rw-r--r-- | src/stdlib/integers.c | 46 | ||||
| -rw-r--r-- | src/stdlib/lists.c | 3 | ||||
| -rw-r--r-- | src/stdlib/memory.c | 3 | ||||
| -rw-r--r-- | src/stdlib/metamethods.c | 6 | ||||
| -rw-r--r-- | src/stdlib/nums.c | 24 | ||||
| -rw-r--r-- | src/stdlib/pointers.c | 9 | ||||
| -rw-r--r-- | src/stdlib/stdlib.c | 4 | ||||
| -rw-r--r-- | src/stdlib/tables.c | 3 | ||||
| -rw-r--r-- | src/stdlib/text.c | 28 | ||||
| -rw-r--r-- | src/typecheck.c | 3 | ||||
| -rw-r--r-- | src/types.c | 2 |
20 files changed, 136 insertions, 50 deletions
diff --git a/src/compile.c b/src/compile.c index 2c644747..0a847093 100644 --- a/src/compile.c +++ b/src/compile.c @@ -58,6 +58,7 @@ CORD promote_to_optional(type_t *t, CORD code) case TYPE_IBITS64: return CORD_all("((OptionalInt64_t){.value=", code, "})"); default: errx(1, "Unsupported in type: ", type_to_str(t)); } + return code; } else if (t->tag == ByteType) { return CORD_all("((OptionalByte_t){.value=", code, "})"); } else if (t->tag == StructType) { @@ -755,6 +756,7 @@ static CORD compile_binary_op(env_t *env, ast_t *ast) } default: errx(1, "Not a valid binary operation: ", ast_to_xml_str(ast)); } + return CORD_EMPTY; } PUREFUNC CORD compile_unsigned_type(type_t *t) @@ -768,6 +770,7 @@ PUREFUNC CORD compile_unsigned_type(type_t *t) case TYPE_IBITS64: return "uint64_t"; default: errx(1, "Invalid integer bit size"); } + return CORD_EMPTY; } CORD compile_type(type_t *t) @@ -844,6 +847,7 @@ CORD compile_type(type_t *t) case TypeInfoType: return "TypeInfo_t"; default: compiler_err(NULL, NULL, NULL, "Compiling type is not implemented for type with tag ", t->tag); } + return CORD_EMPTY; } CORD compile_lvalue(env_t *env, ast_t *ast) @@ -914,6 +918,7 @@ CORD compile_lvalue(env_t *env, ast_t *ast) } else { code_err(ast, "I don't know how to assign to this"); } + return CORD_EMPTY; } static CORD compile_assignment(env_t *env, ast_t *target, CORD value) @@ -987,6 +992,7 @@ CORD check_none(type_t *t, CORD value) else if (t->tag == EnumType) return CORD_all("({(", value, ").$tag == 0;})"); print_err("Optional check not implemented for: ", type_to_str(t)); + return CORD_EMPTY; } static CORD compile_condition(env_t *env, ast_t *ast) @@ -1007,6 +1013,7 @@ static CORD compile_condition(env_t *env, ast_t *ast) } else { code_err(ast, type_to_str(t), " values cannot be used for conditionals"); } + return CORD_EMPTY; } static CORD _compile_statement(env_t *env, ast_t *ast) @@ -1947,6 +1954,7 @@ CORD expr_as_text(CORD expr, type_t *t, CORD color) return CORD_asprintf("generic_as_text(stack(%r), %r, %r)", expr, color, compile_type_info(t)); default: compiler_err(NULL, NULL, NULL, "Stringifying is not supported for ", type_to_str(t)); } + return CORD_EMPTY; } CORD compile_string(env_t *env, ast_t *ast, CORD color) @@ -2250,6 +2258,7 @@ CORD compile_typed_allocation(env_t *env, ast_t *ast, type_t *pointer_type) } default: code_err(ast, "Not an allocation!"); } + return CORD_EMPTY; } CORD compile_int_to_type(env_t *env, ast_t *ast, type_t *target) @@ -2322,6 +2331,7 @@ CORD compile_int_to_type(env_t *env, ast_t *ast, type_t *target) } else { code_err(ast, "I don't know how to compile this to a ", type_to_str(target)); } + return CORD_EMPTY; } CORD compile_arguments(env_t *env, ast_t *call_ast, arg_t *spec_args, arg_ast_t *call_args) @@ -2504,6 +2514,7 @@ CORD compile_none(type_t *t) } default: compiler_err(NULL, NULL, NULL, "none isn't implemented for this type: ", type_to_str(t)); } + return CORD_EMPTY; } CORD compile_empty(type_t *t) @@ -2571,6 +2582,7 @@ CORD compile_empty(type_t *t) } default: return CORD_EMPTY; } + return CORD_EMPTY; } static CORD compile_declared_value(env_t *env, ast_t *declare_ast) @@ -3859,6 +3871,7 @@ CORD compile(env_t *env, ast_t *ast) code_err(ast, "This is not a valid expression"); default: case Unknown: code_err(ast, "Unknown AST: ", ast_to_xml_str(ast)); } + return CORD_EMPTY; } CORD compile_type_info(type_t *t) @@ -3921,6 +3934,7 @@ CORD compile_type_info(type_t *t) default: compiler_err(NULL, 0, 0, "I couldn't convert to a type info: ", type_to_str(t)); } + return CORD_EMPTY; } static CORD get_flag_options(type_t *t, CORD separator) diff --git a/src/cordhelpers.h b/src/cordhelpers.h index 9a72e93c..a1638869 100644 --- a/src/cordhelpers.h +++ b/src/cordhelpers.h @@ -3,7 +3,7 @@ #include <gc/cord.h> -#define CORD_appendf(cord, fmt, ...) CORD_sprintf(cord, "%r" fmt, *(cord) __VA_OPT__(,) __VA_ARGS__) +#define CORD_appendf(cord, fmt, ...) CORD_sprintf(cord, "%r" fmt, *(cord), __VA_ARGS__) #define CORD_all(...) CORD_catn(sizeof((CORD[]){__VA_ARGS__})/sizeof(CORD), __VA_ARGS__) __attribute__((format(printf, 1, 2))) diff --git a/src/environment.c b/src/environment.c index 70c29ce7..9605707a 100644 --- a/src/environment.c +++ b/src/environment.c @@ -38,6 +38,7 @@ static type_t *declare_type(env_t *env, const char *def_str) } default: errx(1, "Not a type definition: %s", def_str); } + return NULL; } static type_t *bind_type(env_t *env, const char *name, type_t *type) @@ -676,6 +677,7 @@ env_t *for_scope(env_t *env, ast_t *ast) } default: code_err(for_->iter, "Iteration is not implemented for type: ", type_to_str(iter_t)); } + return NULL; } env_t *get_namespace_by_type(env_t *env, type_t *t) @@ -148,6 +148,7 @@ const TypeInfo_t *type_to_type_info(type_t *t) } default: print_err("Unsupported type: ", type_to_str(t)); } + return NULL; } static PUREFUNC void *get_address(env_t *env, ast_t *ast) @@ -160,6 +161,7 @@ static PUREFUNC void *get_address(env_t *env, ast_t *ast) } default: print_err("Address not implemented for ", ast_to_xml_str(ast)); } + return NULL; } static Int_t ast_to_int(env_t *env, ast_t *ast) @@ -184,6 +186,7 @@ static Int_t ast_to_int(env_t *env, ast_t *ast) } default: print_err("Cannot convert to integer"); } + return I(0); } // static double ast_to_num(env_t *env, ast_t *ast) diff --git a/src/stdlib/bools.c b/src/stdlib/bools.c index 1b408eaa..6b65968d 100644 --- a/src/stdlib/bools.c +++ b/src/stdlib/bools.c @@ -12,8 +12,9 @@ #include "text.h" #include "util.h" -PUREFUNC public Text_t Bool$as_text(const void *b, bool colorize, const TypeInfo_t*) +PUREFUNC public Text_t Bool$as_text(const void *b, bool colorize, const TypeInfo_t *info) { + (void)info; if (!b) return Text("Bool"); if (colorize) return *(Bool_t*)b ? Text("\x1b[35myes\x1b[m") : Text("\x1b[35mno\x1b[m"); @@ -38,8 +39,9 @@ PUREFUNC public OptionalBool_t Bool$parse(Text_t text) } } -static bool Bool$is_none(const void *b, const TypeInfo_t*) +static bool Bool$is_none(const void *b, const TypeInfo_t *info) { + (void)info; return *(OptionalBool_t*)b == NONE_BOOL; } diff --git a/src/stdlib/bytes.c b/src/stdlib/bytes.c index b543c7c6..fffce06c 100644 --- a/src/stdlib/bytes.c +++ b/src/stdlib/bytes.c @@ -10,8 +10,9 @@ public const Byte_t Byte$min = 0; public const Byte_t Byte$max = UINT8_MAX; -PUREFUNC public Text_t Byte$as_text(const void *b, bool colorize, const TypeInfo_t*) +PUREFUNC public Text_t Byte$as_text(const void *b, bool colorize, const TypeInfo_t *info) { + (void)info; if (!b) return Text("Byte"); return Text$format(colorize ? "\x1b[35m0x%02X\x1b[m" : "0x%02X", *(Byte_t*)b); } @@ -34,6 +35,10 @@ public Text_t Byte$hex(Byte_t byte, bool uppercase, bool prefix) { return text; } +#ifdef __TINYC__ +#define __builtin_add_overflow(x, y, result) ({ *(result) = (x) + (y); false; }) +#endif + typedef struct { OptionalByte_t current, last; Int8_t step; diff --git a/src/stdlib/c_strings.c b/src/stdlib/c_strings.c index dc777a7c..e74ccb68 100644 --- a/src/stdlib/c_strings.c +++ b/src/stdlib/c_strings.c @@ -24,8 +24,9 @@ public Text_t CString$as_text_simple(const char *str) return Text$format("%s", str); } -PUREFUNC public int32_t CString$compare(const void *x, const void *y, const TypeInfo_t*) +PUREFUNC public int32_t CString$compare(const void *x, const void *y, const TypeInfo_t *info) { + (void)info; if (x == y) return 0; @@ -40,27 +41,31 @@ PUREFUNC public bool CString$equal(const void *x, const void *y, const TypeInfo_ return CString$compare(x, y, type) == 0; } -PUREFUNC public uint64_t CString$hash(const void *c_str, const TypeInfo_t*) +PUREFUNC public uint64_t CString$hash(const void *c_str, const TypeInfo_t *info) { + (void)info; if (!*(const char**)c_str) return 0; return siphash24(*(void**)c_str, strlen(*(const char**)c_str)); } -PUREFUNC public bool CString$is_none(const void *c_str, const TypeInfo_t*) +PUREFUNC public bool CString$is_none(const void *c_str, const TypeInfo_t *info) { + (void)info; return *(const char**)c_str == NULL; } -static void CString$serialize(const void *obj, FILE *out, Table_t *pointers, const TypeInfo_t*) +static void CString$serialize(const void *obj, FILE *out, Table_t *pointers, const TypeInfo_t *info) { + (void)info; const char *str = *(const char **)obj; int64_t len = (int64_t)strlen(str); Int64$serialize(&len, out, pointers, &Int64$info); fwrite(str, sizeof(char), (size_t)len, out); } -static void CString$deserialize(FILE *in, void *out, List_t *pointers, const TypeInfo_t *) +static void CString$deserialize(FILE *in, void *out, List_t *pointers, const TypeInfo_t *info) { + (void)info; int64_t len = -1; Int64$deserialize(in, &len, pointers, &Int64$info); char *str = GC_MALLOC_ATOMIC((size_t)len+1); diff --git a/src/stdlib/enums.c b/src/stdlib/enums.c index bcf47d8e..0c5cf196 100644 --- a/src/stdlib/enums.c +++ b/src/stdlib/enums.c @@ -83,8 +83,9 @@ public Text_t Enum$as_text(const void *obj, bool colorize, const TypeInfo_t *typ return generic_as_text(obj + byte_offset, colorize, value.type); } -PUREFUNC public bool Enum$is_none(const void *x, const TypeInfo_t*) +PUREFUNC public bool Enum$is_none(const void *x, const TypeInfo_t *info) { + (void)info; return *(int32_t*)x == 0; } diff --git a/src/stdlib/functiontype.c b/src/stdlib/functiontype.c index 8c864611..f169057a 100644 --- a/src/stdlib/functiontype.c +++ b/src/stdlib/functiontype.c @@ -89,8 +89,9 @@ public Text_t Func$as_text(const void *fn, bool colorize, const TypeInfo_t *type return text; } -public PUREFUNC bool Func$is_none(const void *obj, const TypeInfo_t*) +public PUREFUNC bool Func$is_none(const void *obj, const TypeInfo_t *info) { + (void)info; return *(void**)obj == NULL; } diff --git a/src/stdlib/integers.c b/src/stdlib/integers.c index 8fff9bd6..b4ca69d3 100644 --- a/src/stdlib/integers.c +++ b/src/stdlib/integers.c @@ -35,15 +35,17 @@ public Text_t Int$value_as_text(Int_t i) { } } -public Text_t Int$as_text(const void *i, bool colorize, const TypeInfo_t*) { +public Text_t Int$as_text(const void *i, bool colorize, const TypeInfo_t *info) { + (void)info; if (!i) return Text("Int"); Text_t text = Int$value_as_text(*(Int_t*)i); if (colorize) text = Text$concat(Text("\x1b[35m"), text, Text("\x1b[m")); return text; } -static bool Int$is_none(const void *i, const TypeInfo_t*) +static bool Int$is_none(const void *i, const TypeInfo_t *info) { + (void)info; return ((Int_t*)i)->small == 0L; } @@ -58,7 +60,8 @@ public PUREFUNC int32_t Int$compare_value(const Int_t x, const Int_t y) { return x.big == y.big ? 0 : mpz_cmp(*x.big, *y.big); } -public PUREFUNC int32_t Int$compare(const void *x, const void *y, const TypeInfo_t*) { +public PUREFUNC int32_t Int$compare(const void *x, const void *y, const TypeInfo_t *info) { + (void)info; return Int$compare_value(*(Int_t*)x, *(Int_t*)y); } @@ -69,7 +72,8 @@ public PUREFUNC bool Int$equal_value(const Int_t x, const Int_t y) { return x.big == y.big ? 0 : (mpz_cmp(*x.big, *y.big) == 0); } -public PUREFUNC bool Int$equal(const void *x, const void *y, const TypeInfo_t*) { +public PUREFUNC bool Int$equal(const void *x, const void *y, const TypeInfo_t *info) { + (void)info; return Int$equal_value(*(Int_t*)x, *(Int_t*)y); } @@ -81,7 +85,8 @@ public CONSTFUNC bool Int$is_between(const Int_t x, const Int_t low, const Int_t return Int$compare_value(low, x) <= 0 && Int$compare_value(x, high) <= 0; } -public PUREFUNC uint64_t Int$hash(const void *vx, const TypeInfo_t*) { +public PUREFUNC uint64_t Int$hash(const void *vx, const TypeInfo_t *info) { + (void)info; Int_t *x = (Int_t*)vx; if (likely(x->small & 1L)) { return siphash24((void*)x, sizeof(Int_t)); @@ -473,8 +478,9 @@ public Int_t Int$factorial(Int_t n) return Int$from_mpz(ret); } -static void Int$serialize(const void *obj, FILE *out, Table_t *pointers, const TypeInfo_t*) +static void Int$serialize(const void *obj, FILE *out, Table_t *pointers, const TypeInfo_t *info) { + (void)info; Int_t i = *(Int_t*)obj; if (likely(i.small & 1L)) { fputc(0, out); @@ -488,8 +494,9 @@ static void Int$serialize(const void *obj, FILE *out, Table_t *pointers, const T } } -static void Int$deserialize(FILE *in, void *obj, List_t *pointers, const TypeInfo_t*) +static void Int$deserialize(FILE *in, void *obj, List_t *pointers, const TypeInfo_t *info) { + (void)info; if (fgetc(in) == 0) { int64_t i = 0; Int64$deserialize(in, &i, pointers, &Int64$info); @@ -516,8 +523,9 @@ public const TypeInfo_t Int$info = { }, }; -public void Int64$serialize(const void *obj, FILE *out, Table_t*, const TypeInfo_t*) +public void Int64$serialize(const void *obj, FILE *out, Table_t *pointers, const TypeInfo_t *info) { + (void)info, (void)pointers; int64_t i = *(int64_t*)obj; uint64_t z = (uint64_t)((i << 1L) ^ (i >> 63L)); // Zigzag encode while (z >= 0x80L) { @@ -527,8 +535,9 @@ public void Int64$serialize(const void *obj, FILE *out, Table_t*, const TypeInfo fputc((uint8_t)z, out); } -public void Int64$deserialize(FILE *in, void *outval, List_t*, const TypeInfo_t*) +public void Int64$deserialize(FILE *in, void *outval, List_t *pointers, const TypeInfo_t *info) { + (void)info, (void)pointers; uint64_t z = 0; for(size_t shift = 0; ; shift += 7) { uint8_t byte = (uint8_t)fgetc(in); @@ -538,8 +547,9 @@ public void Int64$deserialize(FILE *in, void *outval, List_t*, const TypeInfo_t* *(int64_t*)outval = (int64_t)((z >> 1L) ^ -(z & 1L)); // Zigzag decode } -public void Int32$serialize(const void *obj, FILE *out, Table_t*, const TypeInfo_t*) +public void Int32$serialize(const void *obj, FILE *out, Table_t *pointers, const TypeInfo_t *info) { + (void)info, (void)pointers; int32_t i = *(int32_t*)obj; uint32_t z = (uint32_t)((i << 1) ^ (i >> 31)); // Zigzag encode while (z >= 0x80) { @@ -549,8 +559,9 @@ public void Int32$serialize(const void *obj, FILE *out, Table_t*, const TypeInfo fputc((uint8_t)z, out); } -public void Int32$deserialize(FILE *in, void *outval, List_t*, const TypeInfo_t*) +public void Int32$deserialize(FILE *in, void *outval, List_t *pointers, const TypeInfo_t *info) { + (void)info, (void)pointers; uint32_t z = 0; for(size_t shift = 0; ; shift += 7) { uint8_t byte = (uint8_t)fgetc(in); @@ -566,15 +577,22 @@ public void Int32$deserialize(FILE *in, void *outval, List_t*, const TypeInfo_t* #define Int8$serialize NULL #define Int8$deserialize NULL +#ifdef __TINYC__ +#define __builtin_add_overflow(x, y, result) ({ *(result) = (x) + (y); false; }) +#endif + #define DEFINE_INT_TYPE(c_type, KindOfInt, fmt, min_val, max_val, to_attr)\ - public Text_t KindOfInt ## $as_text(const void *i, bool colorize, const TypeInfo_t*) { \ + public Text_t KindOfInt ## $as_text(const void *i, bool colorize, const TypeInfo_t *info) { \ + (void)info; \ if (!i) return Text(#KindOfInt); \ return Text$format(colorize ? "\x1b[35m" fmt "\x1b[m" : fmt, *(c_type*)i); \ } \ - public PUREFUNC int32_t KindOfInt ## $compare(const void *x, const void *y, const TypeInfo_t*) { \ + public PUREFUNC int32_t KindOfInt ## $compare(const void *x, const void *y, const TypeInfo_t *info) { \ + (void)info; \ return (*(c_type*)x > *(c_type*)y) - (*(c_type*)x < *(c_type*)y); \ } \ - public PUREFUNC bool KindOfInt ## $equal(const void *x, const void *y, const TypeInfo_t*) { \ + public PUREFUNC bool KindOfInt ## $equal(const void *x, const void *y, const TypeInfo_t *info) { \ + (void)info; \ return *(c_type*)x == *(c_type*)y; \ } \ public CONSTFUNC bool KindOfInt ## $is_between(const c_type x, const c_type low, const c_type high) { \ diff --git a/src/stdlib/lists.c b/src/stdlib/lists.c index fb6c4fb9..af0d1e0a 100644 --- a/src/stdlib/lists.c +++ b/src/stdlib/lists.c @@ -763,8 +763,9 @@ public Int_t List$binary_search(List_t list, void *target, Closure_t comparison) return I(lo+1); // Return the index where the target would be inserted } -public PUREFUNC bool List$is_none(const void *obj, const TypeInfo_t*) +public PUREFUNC bool List$is_none(const void *obj, const TypeInfo_t *info) { + (void)info; return ((List_t*)obj)->length < 0; } diff --git a/src/stdlib/memory.c b/src/stdlib/memory.c index 1805fb6f..ed2ded40 100644 --- a/src/stdlib/memory.c +++ b/src/stdlib/memory.c @@ -13,7 +13,8 @@ #include "types.h" #include "util.h" -public Text_t Memory$as_text(const void *p, bool colorize, const TypeInfo_t *) { +public Text_t Memory$as_text(const void *p, bool colorize, const TypeInfo_t *info) { + (void)info; if (!p) return Text("Memory"); return Text$format(colorize ? "\x1b[0;34;1mMemory<%p>\x1b[m" : "Memory<%p>", p); } diff --git a/src/stdlib/metamethods.c b/src/stdlib/metamethods.c index 6ee52222..a7c9424b 100644 --- a/src/stdlib/metamethods.c +++ b/src/stdlib/metamethods.c @@ -108,15 +108,17 @@ public int generic_print(const void *obj, bool colorize, const TypeInfo_t *type) } __attribute__((noreturn)) -public void cannot_serialize(const void*, FILE*, Table_t*, const TypeInfo_t *type) +public void cannot_serialize(const void *obj, FILE *out, Table_t *pointers, const TypeInfo_t *type) { + (void)obj, (void)out, (void)pointers; Text_t typestr = generic_as_text(NULL, false, type); fail("Values of type ", typestr, " cannot be serialized or deserialized!"); } __attribute__((noreturn)) -public void cannot_deserialize(FILE*, void*, List_t*, const TypeInfo_t *type) +public void cannot_deserialize(FILE *in, void *obj, List_t *pointers, const TypeInfo_t *type) { + (void)obj, (void)in, (void)pointers; Text_t typestr = generic_as_text(NULL, false, type); fail("Values of type ", typestr, " cannot be serialized or deserialized!"); } diff --git a/src/stdlib/nums.c b/src/stdlib/nums.c index ed1c64be..c488b551 100644 --- a/src/stdlib/nums.c +++ b/src/stdlib/nums.c @@ -13,12 +13,14 @@ #include "text.h" #include "types.h" -public PUREFUNC Text_t Num$as_text(const void *f, bool colorize, const TypeInfo_t*) { +public PUREFUNC Text_t Num$as_text(const void *f, bool colorize, const TypeInfo_t *info) { + (void)info; if (!f) return Text("Num"); return Text$format(colorize ? "\x1b[35m%.16g\x1b[33;2m\x1b[m" : "%.16g", *(double*)f); } -public PUREFUNC int32_t Num$compare(const void *x, const void *y, const TypeInfo_t*) { +public PUREFUNC int32_t Num$compare(const void *x, const void *y, const TypeInfo_t *info) { + (void)info; int64_t rx = *(int64_t*)x, ry = *(int64_t*)y; @@ -30,7 +32,8 @@ public PUREFUNC int32_t Num$compare(const void *x, const void *y, const TypeInfo return (rx > ry) - (rx < ry); } -public PUREFUNC bool Num$equal(const void *x, const void *y, const TypeInfo_t*) { +public PUREFUNC bool Num$equal(const void *x, const void *y, const TypeInfo_t *info) { + (void)info; return *(double*)x == *(double*)y; } @@ -93,8 +96,9 @@ public OptionalNum_t Num$parse(Text_t text) { return nan("null"); } -static bool Num$is_none(const void *n, const TypeInfo_t*) +static bool Num$is_none(const void *n, const TypeInfo_t *info) { + (void)info; return isnan(*(Num_t*)n); } @@ -113,16 +117,19 @@ public const TypeInfo_t Num$info = { }, }; -public PUREFUNC Text_t Num32$as_text(const void *f, bool colorize, const TypeInfo_t*) { +public PUREFUNC Text_t Num32$as_text(const void *f, bool colorize, const TypeInfo_t *info) { + (void)info; if (!f) return Text("Num32"); return Text$format(colorize ? "\x1b[35m%.8g\x1b[33;2m\x1b[m" : "%.8g", (double)*(float*)f); } -public PUREFUNC int32_t Num32$compare(const void *x, const void *y, const TypeInfo_t*) { +public PUREFUNC int32_t Num32$compare(const void *x, const void *y, const TypeInfo_t *info) { + (void)info; return (*(float*)x > *(float*)y) - (*(float*)x < *(float*)y); } -public PUREFUNC bool Num32$equal(const void *x, const void *y, const TypeInfo_t*) { +public PUREFUNC bool Num32$equal(const void *x, const void *y, const TypeInfo_t *info) { + (void)info; return *(float*)x == *(float*)y; } @@ -186,8 +193,9 @@ public OptionalNum32_t Num32$parse(Text_t text) { return nan("null"); } -static bool Num32$is_none(const void *n, const TypeInfo_t*) +static bool Num32$is_none(const void *n, const TypeInfo_t *info) { + (void)info; return isnan(*(Num32_t*)n); } diff --git a/src/stdlib/pointers.c b/src/stdlib/pointers.c index daea2dbd..d766a9b3 100644 --- a/src/stdlib/pointers.c +++ b/src/stdlib/pointers.c @@ -66,18 +66,21 @@ public Text_t Pointer$as_text(const void *x, bool colorize, const TypeInfo_t *ty return text; } -PUREFUNC public int32_t Pointer$compare(const void *x, const void *y, const TypeInfo_t*) { +PUREFUNC public int32_t Pointer$compare(const void *x, const void *y, const TypeInfo_t *info) { + (void)info; const void *xp = *(const void**)x, *yp = *(const void**)y; return (xp > yp) - (xp < yp); } -PUREFUNC public bool Pointer$equal(const void *x, const void *y, const TypeInfo_t*) { +PUREFUNC public bool Pointer$equal(const void *x, const void *y, const TypeInfo_t *info) { + (void)info; const void *xp = *(const void**)x, *yp = *(const void**)y; return xp == yp; } -PUREFUNC public bool Pointer$is_none(const void *x, const TypeInfo_t*) +PUREFUNC public bool Pointer$is_none(const void *x, const TypeInfo_t *info) { + (void)info; return *(void**)x == NULL; } diff --git a/src/stdlib/stdlib.c b/src/stdlib/stdlib.c index 6332c69d..88553f54 100644 --- a/src/stdlib/stdlib.c +++ b/src/stdlib/stdlib.c @@ -43,8 +43,9 @@ static ssize_t getrandom(void *buf, size_t buflen, unsigned int flags) { public bool USE_COLOR; -static _Noreturn void signal_handler(int sig, siginfo_t *, void *) +static _Noreturn void signal_handler(int sig, siginfo_t *info, void *userdata) { + (void)info, (void)userdata; assert(sig == SIGILL); fflush(stdout); if (USE_COLOR) fputs("\x1b[31;7m ===== ILLEGAL INSTRUCTION ===== \n\n\x1b[m", stderr); @@ -167,6 +168,7 @@ static bool parse_single_arg(const TypeInfo_t *info, char *arg, void *dest) Text_t t = generic_as_text(NULL, false, info); print_err("Unsupported type for argument parsing: ", t); } + return false; } static List_t parse_list(const TypeInfo_t *item_info, int n, char *args[]) diff --git a/src/stdlib/tables.c b/src/stdlib/tables.c index 780aca83..c01ac25e 100644 --- a/src/stdlib/tables.c +++ b/src/stdlib/tables.c @@ -752,8 +752,9 @@ 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*) +PUREFUNC public bool Table$is_none(const void *obj, const TypeInfo_t *info) { + (void)info; return ((Table_t*)obj)->entries.length < 0; } diff --git a/src/stdlib/text.c b/src/stdlib/text.c index 21d1a3db..cc4158e5 100644 --- a/src/stdlib/text.c +++ b/src/stdlib/text.c @@ -111,7 +111,8 @@ public Text_t EMPTY_TEXT = { .ascii=0, }; -PUREFUNC static bool graphemes_equal(const void *va, const void *vb, const TypeInfo_t*) { +PUREFUNC static bool graphemes_equal(const void *va, const void *vb, const TypeInfo_t *info) { + (void)info; ucs4_t *a = *(ucs4_t**)va; ucs4_t *b = *(ucs4_t**)vb; if (a[0] != b[0]) return false; @@ -120,7 +121,8 @@ PUREFUNC static bool graphemes_equal(const void *va, const void *vb, const TypeI return true; } -PUREFUNC static uint64_t grapheme_hash(const void *g, const TypeInfo_t*) { +PUREFUNC static uint64_t grapheme_hash(const void *g, const TypeInfo_t *info) { + (void)info; ucs4_t *cluster = *(ucs4_t**)g; return siphash24((void*)&cluster[1], sizeof(ucs4_t[cluster[0]])); } @@ -639,6 +641,7 @@ public Text_t Text$slice(Text_t text, Int_t first_int, Int_t last_int) } default: errx(1, "Invalid tag"); } + return EMPTY_TEXT; } public Text_t Text$from(Text_t text, Int_t first) @@ -679,6 +682,7 @@ public Text_t Text$reversed(Text_t text) } default: errx(1, "Invalid tag"); } + return EMPTY_TEXT; } public PUREFUNC Text_t Text$cluster(Text_t text, Int_t index_int) @@ -719,6 +723,7 @@ public PUREFUNC Text_t Text$cluster(Text_t text, Int_t index_int) } default: errx(1, "Invalid tag"); } + return EMPTY_TEXT; } Text_t text_from_u32(ucs4_t *codepoints, int64_t num_codepoints, bool normalize) @@ -859,8 +864,9 @@ public char *Text$as_c_string(Text_t text) return buf; } -PUREFUNC public uint64_t Text$hash(const void *obj, const TypeInfo_t*) +PUREFUNC public uint64_t Text$hash(const void *obj, const TypeInfo_t *info) { + (void)info; Text_t text = *(Text_t*)obj; siphash sh; siphashinit(&sh, sizeof(int32_t[text.length])); @@ -903,6 +909,7 @@ PUREFUNC public uint64_t Text$hash(const void *obj, const TypeInfo_t*) } default: errx(1, "Invalid text"); } + return 0; } public int32_t Text$get_grapheme_fast(TextIter_t *state, int64_t index) @@ -961,8 +968,9 @@ public uint32_t Text$get_main_grapheme_fast(TextIter_t *state, int64_t index) return (g) >= 0 ? (ucs4_t)(g) : synthetic_graphemes[-(g)-1].main_codepoint; } -PUREFUNC public int32_t Text$compare(const void *va, const void *vb, const TypeInfo_t*) +PUREFUNC public int32_t Text$compare(const void *va, const void *vb, const TypeInfo_t *info) { + (void)info; if (va == vb) return 0; const Text_t a = *(const Text_t*)va; const Text_t b = *(const Text_t*)vb; @@ -1269,8 +1277,9 @@ PUREFUNC public bool Text$equal_values(Text_t a, Text_t b) return true; } -PUREFUNC public bool Text$equal(const void *a, const void *b, const TypeInfo_t*) +PUREFUNC public bool Text$equal(const void *a, const void *b, const TypeInfo_t *info) { + (void)info; if (a == b) return true; return Text$equal_values(*(Text_t*)a, *(Text_t*)b); } @@ -1633,21 +1642,24 @@ public Closure_t Text$by_line(Text_t text) }; } -PUREFUNC public bool Text$is_none(const void *t, const TypeInfo_t*) +PUREFUNC public bool Text$is_none(const void *t, const TypeInfo_t *info) { + (void)info; return ((Text_t*)t)->length < 0; } -public void Text$serialize(const void *obj, FILE *out, Table_t *pointers, const TypeInfo_t *) +public void Text$serialize(const void *obj, FILE *out, Table_t *pointers, const TypeInfo_t *info) { + (void)info; const char *str = Text$as_c_string(*(Text_t*)obj); int64_t len = (int64_t)strlen(str); Int64$serialize(&len, out, pointers, &Int64$info); fwrite(str, sizeof(char), (size_t)len, out); } -public void Text$deserialize(FILE *in, void *out, List_t *pointers, const TypeInfo_t *) +public void Text$deserialize(FILE *in, void *out, List_t *pointers, const TypeInfo_t *info) { + (void)info; int64_t len = -1; Int64$deserialize(in, &len, pointers, &Int64$info); char *buf = GC_MALLOC_ATOMIC((size_t)len+1); diff --git a/src/typecheck.c b/src/typecheck.c index 3695de76..42f37224 100644 --- a/src/typecheck.c +++ b/src/typecheck.c @@ -125,6 +125,7 @@ type_t *parse_type_ast(env_t *env, type_ast_t *ast) #pragma GCC diagnostic pop #endif errx(1, "Unreachable"); + return NULL; } // static PUREFUNC bool risks_zero_or_inf(ast_t *ast) @@ -157,6 +158,7 @@ PUREFUNC type_t *get_math_type(env_t *env, ast_t *ast, type_t *lhs_t, type_t *rh case NUM_PRECISION_LESS: return rhs_t; default: code_err(ast, "Math operations between ", type_to_str(lhs_t), " and ", type_to_str(rhs_t), " are not supported"); } + return NULL; } static env_t *load_module(env_t *env, ast_t *module_ast) @@ -1492,6 +1494,7 @@ type_t *get_type(env_t *env, ast_t *ast) #pragma GCC diagnostic pop #endif code_err(ast, "I can't figure out the type of: ", ast_to_xml_str(ast)); + return NULL; } PUREFUNC bool is_discardable(env_t *env, ast_t *ast) diff --git a/src/types.c b/src/types.c index 14f6bc8e..dd76258d 100644 --- a/src/types.c +++ b/src/types.c @@ -570,6 +570,7 @@ PUREFUNC size_t type_size(type_t *t) #pragma GCC diagnostic pop #endif errx(1, "This should not be reachable"); + return 0; } PUREFUNC size_t type_align(type_t *t) @@ -646,6 +647,7 @@ PUREFUNC size_t type_align(type_t *t) #pragma GCC diagnostic pop #endif errx(1, "This should not be reachable"); + return 0; } type_t *get_field_type(type_t *t, const char *field_name) |
