ref: 70059e264c1f27b0ec9e3129a6e6796969d058e0
parent: 775cc94dbb55ddd1ab137527068dbc8bd0103602
author: Sigrid Solveig Haflínudóttir <sigrid@ftrv.se>
date: Sun Feb 9 19:52:55 EST 2025
(l)argc: update ip only on error; add explicit arity_error func
--- a/src/flisp.c
+++ b/src/flisp.c
@@ -163,6 +163,12 @@
fl_raise(fl_listn(2, FL_UnboundError, sym));
}
+_Noreturn void
+arity_error(uint32_t nargs, uint32_t c)
+{
+ lerrorf(FL_ArgError, "arity mismatch: wanted %"PRIu32", got %"PRIu32, c, nargs);
+}
+
// safe cast operators --------------------------------------------------------
#define isstring fl_isstring
--- a/src/flisp.h
+++ b/src/flisp.h
@@ -266,11 +266,12 @@
_Noreturn void type_error(const char *expected, value_t got);
_Noreturn void bounds_error(value_t arr, value_t ind);
_Noreturn void unbound_error(value_t sym);
+_Noreturn void arity_error(uint32_t nargs, uint32_t c);
#define argcount(nargs, c) \
do{ \
if(fl_unlikely(nargs != c)) \
- lerrorf(FL_ArgError, "arity mismatch: wanted %"PRIu32", got %"PRIu32, (uint32_t)c, nargs); \
+ arity_error(nargs, c); \
}while(0)
typedef struct {
--- a/src/vm.inc
+++ b/src/vm.inc
@@ -668,8 +668,10 @@
n = GET_INT32(ip);
ip += 4;
}
- FL(stack)[ipd] = (uintptr_t)ip;
- argcount(nargs, n);
+ if(fl_unlikely(nargs != n)){
+ FL(stack)[ipd] = (uintptr_t)ip;
+ arity_error(nargs, n);
+ }
NEXT_OP;
OP(OP_VECTOR)