ref: f09637f62c7e948abb5c0e5df7d1b770de9625e6
parent: 7e0665beb50190f4b2c09a9a91fcfbf93ce12668
author: Sigrid Solveig Haflínudóttir <[email protected]>
date: Sun Mar 26 19:42:00 EDT 2023
use _Noreturn where needed
--- a/builtins.c
+++ b/builtins.c
@@ -96,7 +96,6 @@
return fixnum(llength(a));
}
type_error("length", "sequence", a);
- return -1;
}
static value_t fl_f_raise(value_t *args, uint32_t nargs)
@@ -103,7 +102,6 @@
{
argcount("raise", nargs, 1);
fl_raise(args[0]);
- return -1;
}
static value_t fl_exit(value_t *args, uint32_t nargs)
@@ -235,7 +233,6 @@
return fixnum(conv_to_long(cp_data(cp), cp_numtype(cp)));
}
type_error("fixnum", "number", args[0]);
- return -1;
}
double trunc(double x);
@@ -267,7 +264,6 @@
return return_from_int64((int64_t)d);
}
type_error("truncate", "number", args[0]);
- return -1;
}
static value_t fl_vector_alloc(value_t *args, uint32_t nargs)
@@ -307,7 +303,6 @@
return conv_to_double(cp_data(cp), nt);
}
type_error(fname, "number", a);
- return -1;
}
static value_t fl_time_string(value_t *args, uint32_t nargs)
--- a/cvalues.c
+++ b/cvalues.c
@@ -330,12 +330,11 @@
return conv_to_ulong(cp_data(cp), cp_numtype(cp));
}
type_error(fname, "number", n);
- return NIL;
}
static int cvalue_enum_init(fltype_t *ft, value_t arg, void *dest)
{
- int n=0;
+ int n;
value_t syms;
value_t type = ft->type;
@@ -565,7 +564,6 @@
}
lerrorf(ArgError, "sizeof: invalid c type");
- return 0;
}
extern fltype_t *iostreamtype;
@@ -821,10 +819,9 @@
{
argcount("builtin", nargs, 1);
symbol_t *name = tosymbol(args[0], "builtin");
- cvalue_t *cv = NULL;
- if (ismanaged(args[0]) || (cv=name->dlcache) == NULL) {
+ cvalue_t *cv;
+ if (ismanaged(args[0]) || (cv=name->dlcache) == NULL)
lerrorf(ArgError, "builtin: function %s not found", name->name);
- }
return tagptr(cv, TAG_CVALUE);
}
@@ -1104,7 +1101,6 @@
}
}
type_error("-", "number", n);
- return NIL;
}
static value_t fl_mul_any(value_t *args, uint32_t nargs, int64_t Saccum)
@@ -1224,8 +1220,7 @@
return 1;
}
-static void DivideByZeroError(void) __attribute__ ((__noreturn__));
-static void DivideByZeroError(void)
+static _Noreturn void DivideByZeroError(void)
{
lerrorf(DivideError, "/: division by zero");
}
@@ -1297,7 +1292,6 @@
return return_from_int64(conv_to_int64(aptr, ta) / b64);
div_error:
DivideByZeroError();
- return -1;
}
static value_t fl_bitwise_op(value_t a, value_t b, int opcode, char *fname)
@@ -1439,7 +1433,6 @@
}
}
type_error("lognot", "integer", a);
- return NIL;
}
static value_t fl_ash(value_t *args, uint32_t nargs)
@@ -1489,5 +1482,4 @@
}
}
type_error("ash", "integer", a);
- return NIL;
}
--- a/flisp.c
+++ b/flisp.c
@@ -114,7 +114,7 @@
curr_frame = _ctx->frame;
}
-void fl_raise(value_t e)
+_Noreturn void fl_raise(value_t e)
{
fl_lasterror = e;
// unwind read state
@@ -138,7 +138,7 @@
return string_from_cstr(msgbuf);
}
-void lerrorf(value_t e, char *format, ...)
+_Noreturn void lerrorf(value_t e, char *format, ...)
{
va_list args;
PUSH(e);
@@ -150,12 +150,12 @@
fl_raise(fl_list2(e, msg));
}
-void type_error(char *fname, char *expected, value_t got)
+_Noreturn void type_error(char *fname, char *expected, value_t got)
{
fl_raise(fl_listn(4, TypeError, symbol(fname), symbol(expected), got));
}
-void bounds_error(char *fname, value_t arr, value_t ind)
+_Noreturn void bounds_error(char *fname, value_t arr, value_t ind)
{
fl_raise(fl_listn(4, BoundsError, symbol(fname), arr, ind));
}
@@ -169,7 +169,6 @@
if (is##type(v)) \
return (ctype)cnvt(v); \
type_error(fname, #type, v); \
- return 0; \
}
SAFECAST_OP(cons, cons_t*, ptr)
SAFECAST_OP(symbol,symbol_t*,ptr)
@@ -566,7 +565,7 @@
{
value_t f = Stack[SP-n-1];
uint32_t saveSP = SP;
- value_t v = NIL;
+ value_t v;
if (iscbuiltin(f)) {
v = ((builtin_t*)ptr(f))[3](&Stack[SP-n], n);
}
@@ -910,7 +909,6 @@
SP++;//PUSH(0); //ip
PUSH(0); //captured?
curr_frame = SP;
- tail = 0;
op = *ip++;
while(1){
@@ -993,7 +991,6 @@
for(s=SP-n-1; s < (int)SP-1; s++)
Stack[s] = Stack[s+1];
SP--;
- op = i;
switch (i) {
case OP_LIST: goto apply_list;
case OP_VECTOR: goto apply_vector;
@@ -1003,7 +1000,7 @@
case OP_MUL: goto apply_mul;
case OP_DIV: goto apply_div;
default:
- op = (uint8_t)i;
+ op = i;
continue;
}
}
--- a/flisp.h
+++ b/flisp.h
@@ -212,12 +212,12 @@
else \
for(l__ca=1; l__ca; l__ca=0, fl_restorestate(&_ctx))
-void lerrorf(value_t e, char *format, ...) __attribute__ ((__noreturn__));
+_Noreturn void lerrorf(value_t e, char *format, ...);
void fl_savestate(fl_exception_context_t *_ctx);
void fl_restorestate(fl_exception_context_t *_ctx);
-void fl_raise(value_t e) __attribute__ ((__noreturn__));
-void type_error(char *fname, char *expected, value_t got) __attribute__ ((__noreturn__));
-void bounds_error(char *fname, value_t arr, value_t ind) __attribute__ ((__noreturn__));
+_Noreturn void fl_raise(value_t e);
+_Noreturn void type_error(char *fname, char *expected, value_t got);
+_Noreturn void bounds_error(char *fname, value_t arr, value_t ind);
extern value_t ArgError, IOError, KeyError, MemoryError, EnumerationError;
extern value_t UnboundError;
static inline void argcount(char *fname, uint32_t nargs, uint32_t c)
--- a/string.c
+++ b/string.c
@@ -79,7 +79,6 @@
}
}
type_error("string.encode", "wchar array", args[0]);
- return -1;
}
value_t fl_string_decode(value_t *args, uint32_t nargs)
@@ -261,7 +260,7 @@
size_t len = cv_len((cvalue_t*)ptr(args[0]));
if (start > len)
bounds_error("string.find", args[0], args[2]);
- char *needle = ""; size_t needlesz = 0;
+ char *needle; size_t needlesz;
value_t v = args[1];
cprim_t *cp = (cprim_t*)ptr(v);
@@ -352,7 +351,7 @@
argcount("number->string", nargs, 2);
value_t n = args[0];
int neg = 0;
- uint64_t num = 0;
+ uint64_t num;
if (isfixnum(n)) num = numval(n);
else if (!iscprim(n)) type_error("number->string", "integer", n);
else num = conv_to_uint64(cp_data((cprim_t*)ptr(n)),