ref: 37eb1a1a4ea6e80131ec861421478acaaed249c9
parent: c0e57a711517201e3b3bcd621b47c367a3fcd39f
author: Sigrid Solveig Haflínudóttir <sigrid@ftrv.se>
date: Sat Apr 19 14:15:14 EDT 2025
builtin fns go only *up to* N_BUILTINS (exclusive)
--- a/src/equal.c
+++ b/src/equal.c
@@ -117,7 +117,7 @@
break;
case TAG_FN:
if(tagb == TAG_FN){
- if(uintval(a) > N_BUILTINS && uintval(b) > N_BUILTINS){
+ if(!isfnbuiltin(a) && !isfnbuiltin(b)){
sl_fn *fa = ptr(a);
sl_fn *fb = ptr(b);
d = bounded_compare(fa->bcode, fb->bcode, bound-1, eq);
@@ -330,7 +330,7 @@
abort();
return doublehash(u.i64);
case TAG_FN:
- if(uintval(a) > N_BUILTINS)
+ if(!isfnbuiltin(a))
return bounded_hash(((sl_fn*)ptr(a))->bcode, bound, oob);
return inthash(a);
case TAG_SPECIAL:
--- a/src/sl.h
+++ b/src/sl.h
@@ -190,7 +190,8 @@
#define ismanaged(v) ((((u8int*)ptr(v)) >= slg.fromspace) && (((u8int*)ptr(v)) < slg.fromspace+slg.heapsize))
#define isgensym(v) (issym(v) && ismanaged(v))
#define iscbuiltin(v) (iscvalue(v) && cv_class(ptr(v)) == sl_builtintype)
-#define isfn(v) ((tag(v) == TAG_FN && ((v) > (N_BUILTINS<<TAG_BITS) || isbuiltin(v))) || iscbuiltin(v))
+#define isfnbuiltin(v) ((v) < (N_BUILTINS<<TAG_BITS))
+#define isfn(v) (tag(v) == TAG_FN || iscbuiltin(v))
// utility for iterating over all arguments in a builtin
// i=index, i0=start index, arg = var for each arg, args = arg array
// assumes "nargs" is the argument count
--- a/src/vm.h
+++ b/src/vm.h
@@ -32,7 +32,7 @@
SYNC;
sl_v v = sp[-n-1];
if(tag(v) == TAG_FN){
- if(v > (N_BUILTINS<<TAG_BITS)){
+ if(!isfnbuiltin(v)){
nargs = n;
if(tail){
sl.curr_frame = (sl_v*)sl.curr_frame[-3];