shithub: femtolisp

Download patch

ref: 5a40f2d38ff53e1bdc3f3b56a2d3691179c14183
parent: 19887e156a7fe98c224793b4f95f42035e604645
author: Sigrid Solveig Haflínudóttir <sigrid@ftrv.se>
date: Mon Mar 27 17:03:47 EDT 2023

rewrite argcount as a macro

--- a/flisp.h
+++ b/flisp.h
@@ -220,13 +220,15 @@
 _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)
-{
-    if (__unlikely(nargs != c)){
-        assert(0);
-        lerrorf(ArgError,"%s: too %s arguments (want %d, got %d)", fname, nargs<c ? "few":"many", c, nargs);
-    }
-}
+#define argcount(fname, nargs, c)                         \
+    do {                                                  \
+        if (__unlikely(nargs != c)) {                     \
+            lerrorf(ArgError,                             \
+                "%s: too %s arguments (want %d, got %d)", \
+                fname,                                    \
+                nargs < c ? "few" : "many", c, nargs);    \
+        }                                                 \
+    } while(0)
 
 typedef struct {
     void (*print)(value_t self, ios_t *f);