shithub: sl

Download patch

ref: 98dfeb8e6bdc2d672c00df97709a115c0cd14755
parent: a2492259ee1e1cea92c307db8b6633e74dd95c86
author: Sigrid Solveig Haflínudóttir <sigrid@ftrv.se>
date: Wed Apr 2 20:02:55 EDT 2025

unboxed numbers: shorter names

--- a/src/builtins.c
+++ b/src/builtins.c
@@ -226,7 +226,7 @@
 {
 	argcount(nargs, 1);
 	sl_v v = args[0];
-	if(isfixnum(v) || isunboxednum(v) || ismp(v))
+	if(isfixnum(v) || isubnum(v) || ismp(v))
 		return sl_t;
 	if(iscprim(v)){
 		sl_numtype nt = cp_numtype(ptr(v));
@@ -256,7 +256,7 @@
 {
 	argcount(nargs, 1);
 	sl_v v = args[0];
-	return (isfixnum(v) || isunboxednum(v) || ismp(v) ||
+	return (isfixnum(v) || isubnum(v) || ismp(v) ||
 			(iscprim(v) && cp_numtype(ptr(v)) < T_FLOAT)) ?
 		sl_t : sl_nil;
 }
@@ -274,8 +274,8 @@
 	sl_v v = args[0];
 	if(isfixnum(v))
 		return v;
-	if(isunboxednum(v))
-		return isunboxedunum(v) ? fixnum(unboxednumuval(v)) : fixnum(unboxednumsval(v));
+	if(isubnum(v))
+		return isubnumu(v) ? fixnum(ubnumuval(v)) : fixnum(ubnumsval(v));
 	if(iscprim(v)){
 		void *p = ptr(v);
 		return fixnum(conv_to_s64(cp_data(p), cp_numtype(p)));
@@ -293,7 +293,7 @@
 {
 	argcount(nargs, 1);
 	sl_v v = args[0];
-	if(isfixnum(v) || isunboxednum(v) || ismp(v))
+	if(isfixnum(v) || isubnum(v) || ismp(v))
 		return v;
 	if(iscprim(v)){
 		sl_cprim *cp = ptr(v);
@@ -354,8 +354,8 @@
 {
 	if(isfixnum(a))
 		return (double)numval(a);
-	if(isunboxednum(a))
-		return isunboxedunum(a) ? (double)unboxednumuval(a) : (double)unboxednumsval(a);
+	if(isubnum(a))
+		return isubnumu(a) ? (double)ubnumuval(a) : (double)ubnumsval(a);
 	if(iscprim(a)){
 		sl_cprim *cp = ptr(a);
 		sl_numtype nt = cp_numtype(cp);
--- a/src/cvalues.c
+++ b/src/cvalues.c
@@ -208,12 +208,12 @@
 		USED(type); \
 		if(isfixnum(a)){ \
 			n = (ctype)numval(a); \
-		}else if(isunboxedunum(a)){ \
-			uintptr v = unboxednumuval(a); \
-			n = (ctype)conv_to_##cnvt(&v, unboxednumtype(a)); \
-		}else if(isunboxedsnum(a)){ \
-			intptr v = unboxednumsval(a); \
-			n = (ctype)conv_to_##cnvt(&v, unboxednumtype(a)); \
+		}else if(isubnumu(a)){ \
+			uintptr v = ubnumuval(a); \
+			n = (ctype)conv_to_##cnvt(&v, ubnumtype(a)); \
+		}else if(isubnums(a)){ \
+			intptr v = ubnumsval(a); \
+			n = (ctype)conv_to_##cnvt(&v, ubnumtype(a)); \
 		}else if(iscprim(a)){ \
 			sl_cprim *cp = ptr(a); \
 			n = (ctype)conv_to_##cnvt(cp_data(cp), cp_numtype(cp)); \
@@ -325,14 +325,14 @@
 	USED(type);
 	if(isfixnum(a))
 		n = vtomp(numval(a), nil);
-	else if(isunboxednum(a)){
+	else if(isubnum(a)){
 		uintptr v;
 		void *p = &v;
-		if(isunboxedunum(a))
-			v = unboxednumuval(a);
+		if(isubnumu(a))
+			v = ubnumuval(a);
 		else
-			v = unboxednumsval(a);
-		n = conv_to_mp(p, unboxednumtype(a));
+			v = ubnumsval(a);
+		n = conv_to_mp(p, ubnumtype(a));
 	}else if(iscvalue(a)){
 		sl_cv *cv = ptr(a);
 		void *p = cv_data(cv);
@@ -390,8 +390,8 @@
 {
 	if(isfixnum(n))
 		return (usize)numval(n);
-	if(isunboxednum(n))
-		return (usize)unboxednumuval(n);
+	if(isubnum(n))
+		return (usize)ubnumuval(n);
 	if(iscprim(n)){
 		sl_cprim *cp = ptr(n);
 		if(sizeof(usize) == 8)
@@ -406,10 +406,10 @@
 {
 	if(isfixnum(n))
 		return numval(n);
-	if(isunboxedunum(n))
-		return unboxednumuval(n);
-	if(isunboxedsnum(n))
-		return unboxednumsval(n);
+	if(isubnumu(n))
+		return ubnumuval(n);
+	if(isubnums(n))
+		return ubnumsval(n);
 	if(iscprim(n)){
 		sl_cprim *cp = ptr(n);
 		return conv_to_s64(cp_data(cp), cp_numtype(cp));
@@ -590,16 +590,16 @@
 void
 to_sized_ptr(sl_v v, u8int **pdata, usize *psz, uintptr *u)
 {
-	if(isunboxedunum(v)){
-		*u = unboxednumuval(v);
+	if(isubnumu(v)){
+		*u = ubnumuval(v);
 		*pdata = (u8int*)u;
-		*psz = unboxedtypes[unboxednumtype(v)]->size;
+		*psz = unboxedtypes[ubnumtype(v)]->size;
 		return;
 	}
-	if(isunboxedsnum(v)){
-		*u = unboxednumsval(v);
+	if(isubnums(v)){
+		*u = ubnumsval(v);
 		*pdata = (u8int*)u;
-		*psz = unboxedtypes[unboxednumtype(v)]->size;
+		*psz = unboxedtypes[ubnumtype(v)]->size;
 		return;
 	}
 	if(iscvalue(v)){
@@ -644,7 +644,7 @@
 	switch(tag(args[0])){
 	case TAG_CONS: return sl_conssym;
 	case TAG_FIXNUM: return sl_fixnumsym;
-	case TAG_UNBOXED: return unboxedtypesyms[unboxednumtype(args[0])];
+	case TAG_UNBOXED: return unboxedtypesyms[ubnumtype(args[0])];
 	case TAG_SYM: return sl_symsym;
 	case TAG_VEC:return sl_vecsym;
 	case TAG_FN:
@@ -727,7 +727,7 @@
 BUILTIN("plain-old-data?", plain_old_datap)
 {
 	argcount(nargs, 1);
-	return (isunboxednum(args[0]) ||
+	return (isubnum(args[0]) ||
 	        iscprim(args[0]) ||
 			(iscvalue(args[0]) && cv_isPOD(ptr(args[0])))) ?
 		sl_t : sl_nil;
@@ -1008,13 +1008,13 @@
 		*pp = pi;
 		*pt = T_FIXNUM;
 		return true;
-	}else if(isunboxednum(a)){
-		if(isunboxedunum(a))
-			*pi = unboxednumuval(a);
+	}else if(isubnum(a)){
+		if(isubnumu(a))
+			*pi = ubnumuval(a);
 		else
-			*pi = unboxednumsval(a);
+			*pi = ubnumsval(a);
 		*pp = pi;
-		*pt = unboxednumtype(a);
+		*pt = ubnumtype(a);
 		return true;
 	}else if(iscprim(a)){
 		cp = ptr(a);
@@ -1304,10 +1304,10 @@
 
 	if(isfixnum(a))
 		return fixnum(~numval(a));
-	if(isunboxedunum(a))
-		return (~unboxednumuval(a) & ~0xff) | (a & 0xff);
-	if(isunboxedsnum(a))
-		return (~unboxednumsval(a) & ~0xff) | (a & 0xff);
+	if(isubnumu(a))
+		return (~ubnumuval(a) & ~0xff) | (a & 0xff);
+	if(isubnums(a))
+		return (~ubnumsval(a) & ~0xff) | (a & 0xff);
 	if(iscprim(a)){
 		cp = ptr(a);
 		ta = cp_numtype(cp);
@@ -1349,8 +1349,8 @@
 	if(n == 0)
 		return a;
 	mp = nil;
-	if(isfixnum(a) || isunboxedsnum(a)){
-		accum = isfixnum(a) ? numval(a) : unboxednumsval(a);
+	if(isfixnum(a) || isubnums(a)){
+		accum = isfixnum(a) ? numval(a) : ubnumsval(a);
 		if(n > -64 && n < 0)
 			return fixnum(accum>>(-n));
 		if(n < 0 || n >= 64 || sash_overflow_64(accum, n, &accum)){
@@ -1359,8 +1359,8 @@
 		}else
 			return fits_fixnum(accum) ? fixnum(accum) : return_from_s64(accum);
 	}
-	if(isunboxedunum(a)){
-		u = unboxednumuval(a);
+	if(isubnumu(a)){
+		u = ubnumuval(a);
 		if(n > 0)
 			u = n < 64 ? u<<n : 0;
 		else
--- a/src/equal.c
+++ b/src/equal.c
@@ -80,7 +80,7 @@
 	case TAG_FIXNUM:
 		if(isfixnum(b))
 			return (sl_fx)a < (sl_fx)b ? fixnum(-1) : fixnum(1);
-		if(isunboxednum(b))
+		if(isubnum(b))
 			return fixnum(numeric_compare(a, b, eq, true, false));
 		if(iscprim(b)){
 			if(cp_class(ptr(b)) == sl_runetype)
@@ -94,7 +94,7 @@
 		}
 		return fixnum(-1);
 	case TAG_UNBOXED:
-		if(isfixnum(b) || isunboxednum(b))
+		if(isfixnum(b) || isubnum(b))
 			return fixnum(numeric_compare(a, b, eq, true, false));
 		if(iscprim(b)){
 			if(cp_class(ptr(b)) == sl_runetype)
@@ -348,10 +348,10 @@
 		u.d = (double)numval(a);
 		return doublehash(u.i64);
 	case TAG_UNBOXED:
-		if(isunboxedunum(a))
-			u.d = unboxednumuval(a);
-		else if(isunboxedsnum(a))
-			u.d = unboxednumsval(a);
+		if(isubnumu(a))
+			u.d = ubnumuval(a);
+		else if(isubnums(a))
+			u.d = ubnumsval(a);
 		else // FIXME(sigrid): unboxed
 			u.d = 0;
 		return doublehash(u.i64);
--- a/src/print.c
+++ b/src/print.c
@@ -854,13 +854,13 @@
 {
 	uintptr u;
 
-	if(isunboxedunum(v))
-		u = unboxednumuval(v);
-	else if(isunboxedsnum(v))
-		u = unboxednumsval(v);
+	if(isubnumu(v))
+		u = ubnumuval(v);
+	else if(isubnums(v))
+		u = ubnumsval(v);
 	else // FIXME(sigrid): unboxed
 		u = 0;
-	int numtype = unboxednumtype(v);
+	int numtype = ubnumtype(v);
 	sl_v typesym = unboxedtypesyms[numtype];
 	sl_type *type = unboxedtypes[numtype];
 	cvalue_printdata(f, &u, type->size, typesym, 0);
@@ -898,10 +898,10 @@
 	sl_v v = sym_value(sl_printwidthsym);
 	if(isfixnum(v))
 		sl.scr_width = numval(v);
-	else if(isunboxedunum(v))
-		sl.scr_width = unboxednumuval(v);
-	else if(isunboxedsnum(v))
-		sl.scr_width = unboxednumsval(v);
+	else if(isubnumu(v))
+		sl.scr_width = ubnumuval(v);
+	else if(isubnums(v))
+		sl.scr_width = ubnumsval(v);
 }
 
 void
--- a/src/sl.c
+++ b/src/sl.c
@@ -694,7 +694,7 @@
 {
 	if(isfixnum(v))
 		return true;
-	if(isunboxednum(v))
+	if(isubnum(v))
 		return true;
 	if(iscprim(v)){
 		sl_cprim *c = ptr(v);
--- a/src/sl.h
+++ b/src/sl.h
@@ -107,8 +107,8 @@
 #define tagptr(p, t) ((sl_v)(p) | (t))
 #define fixnum(x) ((sl_v)(x)<<TAG_BITS)
 #define numval(x) ((sl_fx)(x)>>TAG_BITS)
-#define unboxednumsval(x) ((intptr)(x)>>(TAG_BITS+1+4))
-#define unboxednumuval(x) ((uintptr)(x)>>(TAG_BITS+1+4))
+#define ubnumsval(x) ((intptr)(x)>>(TAG_BITS+1+4))
+#define ubnumuval(x) ((uintptr)(x)>>(TAG_BITS+1+4))
 #define uintval(x) (((unsigned int)(x))>>TAG_BITS)
 #define builtin(n) tagptr(((sl_v)n<<TAG_BITS), TAG_FN)
 #define iscons(x) (tag(x) == TAG_CONS)
@@ -123,14 +123,14 @@
 #define leafp(a) (((a)&TAG_NONLEAF_MASK) != TAG_NONLEAF_MASK)
 
 /* UNBOXED
- * integers/runes: ...|xxxxxxxx|xxxxxxxx|xxxxxxxx|tttt0100|
- * strings:        ...|xxxxxxxx|xxxxxxxx|xxxxxxxx|sss01100|
- * special:        ...|xxxxxxxx|xxxxxxxx|xxxxxxxx|00011100|
+ * integers: ...|xxxxxxxx|xxxxxxxx|xxxxxxxx|tttt0100|
+ * strings:  ...|xxxxxxxx|xxxxxxxx|xxxxxxxx|sss01100|
+ * runes:    ...|xxxxxxxx|xxxxxxxx|xxxxxxxx|00011100|
  */
-#define isunboxednum(x)  ((tagext(x) & ((1<<(TAG_BITS+1))-1)) == (0<<TAG_BITS | TAG_UNBOXED))
-#define isunboxedsnum(x) ((tagext(x) & ((2<<(TAG_BITS+1))-1)) == (0<<TAG_BITS | TAG_UNBOXED))
-#define isunboxedunum(x) ((tagext(x) & ((2<<(TAG_BITS+1))-1)) == (2<<TAG_BITS | TAG_UNBOXED))
-#define unboxednumtype(x) ((tagext(x)>>(TAG_BITS+1))&(0xff>>(TAG_BITS+1)))
+#define isubnum(x)  ((tagext(x) & ((1<<(TAG_BITS+1))-1)) == (0<<TAG_BITS | TAG_UNBOXED))
+#define isubnums(x) ((tagext(x) & ((2<<(TAG_BITS+1))-1)) == (0<<TAG_BITS | TAG_UNBOXED))
+#define isubnumu(x) ((tagext(x) & ((2<<(TAG_BITS+1))-1)) == (2<<TAG_BITS | TAG_UNBOXED))
+#define ubnumtype(x) ((tagext(x)>>(TAG_BITS+1))&(0xff>>(TAG_BITS+1)))
 extern sl_type *unboxedtypes[T_UNBOXED_NUM];
 extern sl_v unboxedtypesyms[T_UNBOXED_NUM];
 
--- a/src/sl_arith_any.h
+++ b/src/sl_arith_any.h
@@ -20,14 +20,14 @@
 		if(isfixnum(arg))
 			x = numval(arg);
 		else{
-			if(isunboxedunum(arg)){
-				u64 = unboxednumuval(arg);
+			if(isubnumu(arg)){
+				u64 = ubnumuval(arg);
 				a = &u64;
-				pt = unboxednumtype(arg);
-			}else if(isunboxedsnum(arg)){
-				u64 = unboxednumsval(arg);
+				pt = ubnumtype(arg);
+			}else if(isubnums(arg)){
+				u64 = ubnumsval(arg);
 				a = &u64;
-				pt = unboxednumtype(arg);
+				pt = ubnumtype(arg);
 			}else if(iscprim(arg)){
 				cp = ptr(arg);
 				a = cp_data(cp);
--- a/src/str.c
+++ b/src/str.c
@@ -358,10 +358,10 @@
 		radix = get_radix_arg(args[1]);
 	if(isfixnum(n))
 		num = numval(n);
-	else if(isunboxedunum(n))
-		num = unboxednumuval(n);
-	else if(isunboxedsnum(n))
-		num = unboxednumsval(n);
+	else if(isubnumu(n))
+		num = ubnumuval(n);
+	else if(isubnums(n))
+		num = ubnumsval(n);
 	else if(iscprim(n)){
 		void *data = ptr(n);
 		if(cp_numtype(data) < T_FLOAT)
--