shithub: femtolisp

Download patch

ref: 27361e559d2f21cf0ce729b7f58bb60b1fcb96a1
parent: bcb96ecf0f2b0d57559f806fccb12177db86db61
author: Sigrid Solveig Haflínudóttir <sigrid@ftrv.se>
date: Thu Jan 16 16:49:13 EST 2025

reduce parentheses

--- a/cvalues.c
+++ b/cvalues.c
@@ -202,7 +202,7 @@
 int
 fl_isstring(value_t v)
 {
-	return iscvalue(v) && cv_isstr((cvalue_t*)ptr(v));
+	return iscvalue(v) && cv_isstr(ptr(v));
 }
 
 // convert to malloc representation (fixed address)
@@ -262,7 +262,7 @@
 			args = &FL(stack)[FL(sp)-1]; \
 		} \
 		value_t cp = cprim(FL(typenam##type), sizeof(ctype)); \
-		if(cvalue_##ctype##_init(FL(typenam##type), args[0], cp_data((cprim_t*)ptr(cp)))) \
+		if(cvalue_##ctype##_init(FL(typenam##type), args[0], cp_data(ptr(cp)))) \
 			type_error("number", args[0]); \
 		return cp; \
 	}
@@ -271,7 +271,7 @@
 	value_t mk_##typenam(ctype n) \
 	{ \
 		value_t cp = cprim(FL(typenam##type), sizeof(ctype)); \
-		*(ctype*)cp_data((cprim_t*)ptr(cp)) = n; \
+		*(ctype*)cp_data(ptr(cp)) = n; \
 		return cp; \
 	}
 
@@ -304,7 +304,7 @@
 		void *p = cv_data(cv);
 		n = conv_to_mpint(p, cp_numtype(cv));
 	}else if(iscprim(arg)){
-		cprim_t *cp = (cprim_t*)ptr(arg);
+		cprim_t *cp = ptr(arg);
 		void *p = cp_data(cp);
 		n = conv_to_mpint(p, cp_numtype(cp));
 	}else{
@@ -360,7 +360,7 @@
 	if(isfixnum(n))
 		return (size_t)numval(n);
 	if(iscprim(n)){
-		cprim_t *cp = (cprim_t*)ptr(n);
+		cprim_t *cp = ptr(n);
 		if(sizeof(size_t) == 8)
 			return conv_to_uint64(cp_data(cp), cp_numtype(cp));
 		return conv_to_uint32(cp_data(cp), cp_numtype(cp));
@@ -374,7 +374,7 @@
 	if(isfixnum(n))
 		return numval(n);
 	if(iscprim(n)){
-		cprim_t *cp = (cprim_t*)ptr(n);
+		cprim_t *cp = ptr(n);
 		return conv_to_int64(cp_data(cp), cp_numtype(cp));
 	}
 	type_error("number", n);
@@ -402,7 +402,7 @@
 	if(isfixnum(arg))
 		n = (int)numval(arg);
 	else if(iscprim(arg)){
-		cprim_t *cp = (cprim_t*)ptr(arg);
+		cprim_t *cp = ptr(arg);
 		n = conv_to_int32(cp_data(cp), cp_numtype(cp));
 	}else
 		type_error("number", arg);
@@ -415,7 +415,7 @@
 int
 isarray(value_t v)
 {
-	return iscvalue(v) && cv_class((cvalue_t*)ptr(v))->eltype != nil;
+	return iscvalue(v) && cv_class(ptr(v))->eltype != nil;
 }
 
 static size_t
@@ -475,7 +475,7 @@
 		return 0;
 	}
 	if(iscvalue(arg)){
-		cvalue_t *cv = (cvalue_t*)ptr(arg);
+		cvalue_t *cv = ptr(arg);
 		if(isarray(arg)){
 			fltype_t *aet = cv_class(cv)->eltype;
 			if(aet == eltype){
@@ -600,7 +600,7 @@
 		}
 	}
 	if(iscprim(v)){
-		cprim_t *pcp = (cprim_t*)ptr(v);
+		cprim_t *pcp = ptr(v);
 		*pdata = cp_data(pcp);
 		*psz = cp_class(pcp)->size;
 		return;
@@ -711,7 +711,7 @@
 {
 	argcount(nargs, 1);
 	return (iscprim(args[0]) ||
-			(iscvalue(args[0]) && cv_isPOD((cvalue_t*)ptr(args[0])))) ?
+			(iscvalue(args[0]) && cv_isPOD(ptr(args[0])))) ?
 		FL_t : FL_f;
 }
 
--- a/equal.c
+++ b/equal.c
@@ -87,7 +87,7 @@
 		if(isfixnum(b))
 			return (fixnum_t)a < (fixnum_t)b ? fixnum(-1) : fixnum(1);
 		if(iscprim(b)){
-			if(cp_class((cprim_t*)ptr(b)) == FL(runetype))
+			if(cp_class(ptr(b)) == FL(runetype))
 				return fixnum(1);
 			return fixnum(numeric_compare(a, b, eq, true, false));
 		}
@@ -108,7 +108,7 @@
 			return bounded_vector_compare(a, b, bound, eq);
 		break;
 	case TAG_CPRIM:
-		if(cp_class((cprim_t*)ptr(a)) == FL(runetype)){
+		if(cp_class(ptr(a)) == FL(runetype)){
 			if(!iscprim(b) || cp_class(ptr(b)) != FL(runetype))
 				return fixnum(-1);
 		}else if(iscprim(b) && cp_class(ptr(b)) == FL(runetype))
@@ -366,7 +366,7 @@
 		u.d = conv_to_double(data, nt);
 		return doublehash(u.i64);
 	case TAG_CVALUE:
-		cv = (cvalue_t*)ptr(a);
+		cv = ptr(a);
 		data = cv_data(cv);
 		if(cv->type == FL(mpinttype)){
 			len = mptobe(*(mpint**)data, nil, 0, (uint8_t**)&data);
--- a/flisp.c
+++ b/flisp.c
@@ -1020,7 +1020,7 @@
 		type_error("string", args[0]);
 	if(fl_unlikely(!isvector(args[1])))
 		type_error("vector", args[1]);
-	cvalue_t *arr = (cvalue_t*)ptr(args[0]);
+	cvalue_t *arr = ptr(args[0]);
 	cv_pin(arr);
 	char *data = cv_data(arr);
 	int ms;
@@ -1102,7 +1102,7 @@
 	if(isbuiltin(v))
 		return symbol(builtins[uintval(v)].name, false);
 	if(iscbuiltin(v)){
-		v = (value_t)ptrhash_get(&FL(reverse_dlsym_lookup_table), (cvalue_t*)ptr(v));
+		v = (value_t)ptrhash_get(&FL(reverse_dlsym_lookup_table), ptr(v));
 		if(v == (value_t)HT_NOTFOUND)
 			return FL_f;
 		return v;
--- a/iostream.c
+++ b/iostream.c
@@ -152,7 +152,7 @@
 	ios_t *s = toiostream(args[0]);
 	if(!iscprim(args[1]) || ((cprim_t*)ptr(args[1]))->type != FL(runetype))
 		type_error("rune", args[1]);
-	Rune r = *(Rune*)cp_data((cprim_t*)ptr(args[1]));
+	Rune r = *(Rune*)cp_data(ptr(args[1]));
 	return fixnum(ios_pututf8(s, r));
 }
 
--- a/operators.c
+++ b/operators.c
@@ -185,11 +185,11 @@
 	if(atag == T_UINT64){
 		if(btag == T_INT64){
 			if(*(int64_t*)b >= 0)
-				return (*(uint64_t*)a < (uint64_t)*(int64_t*)b);
-			return ((int64_t)*(uint64_t*)a < *(int64_t*)b);
+				return *(uint64_t*)a < (uint64_t)*(int64_t*)b;
+			return (int64_t)*(uint64_t*)a < *(int64_t*)b;
 		}
 		if(btag == T_DOUBLE)
-			return db == db ? (*(uint64_t*)a < (uint64_t)*(double*)b) : 0;
+			return db == db ? *(uint64_t*)a < (uint64_t)*(double*)b : 0;
 		if(btag == T_MPINT)
 			return mpcmp(uvtomp(*(uint64_t*)a, cmpmpint), *(mpint**)b) < 0;
 	}
@@ -196,23 +196,23 @@
 	if(atag == T_INT64){
 		if(btag == T_UINT64){
 			if(*(int64_t*)a >= 0)
-				return ((uint64_t)*(int64_t*)a < *(uint64_t*)b);
-			return (*(int64_t*)a < (int64_t)*(uint64_t*)b);
+				return (uint64_t)*(int64_t*)a < *(uint64_t*)b;
+			return *(int64_t*)a < (int64_t)*(uint64_t*)b;
 		}
 		if(btag == T_DOUBLE)
-			return db == db ? (*(int64_t*)a < (int64_t)*(double*)b) : 0;
+			return db == db ? *(int64_t*)a < (int64_t)*(double*)b : 0;
 		if(btag == T_MPINT)
 			return mpcmp(vtomp(*(int64_t*)a, cmpmpint), *(mpint**)b) < 0;
 	}
 	if(btag == T_UINT64){
 		if(atag == T_DOUBLE)
-			return da == da ? (*(uint64_t*)b > (uint64_t)*(double*)a) : 0;
+			return da == da ? *(uint64_t*)b > (uint64_t)*(double*)a : 0;
 		if(atag == T_MPINT)
 			return mpcmp(*(mpint**)a, uvtomp(*(uint64_t*)b, cmpmpint)) < 0;
 	}
 	if(btag == T_INT64){
 		if(atag == T_DOUBLE)
-			return da == da ? (*(int64_t*)b > (int64_t)*(double*)a) : 0;
+			return da == da ? *(int64_t*)b > (int64_t)*(double*)a : 0;
 		if(atag == T_MPINT)
 			return mpcmp(*(mpint**)a, vtomp(*(int64_t*)b, cmpmpint)) < 0;
 	}
@@ -251,33 +251,33 @@
 		// this is safe because if a had been bigger than INT64_MAX,
 		// we would already have concluded that it's bigger than b.
 		if(btag == T_INT64)
-			return ((int64_t)*(uint64_t*)a == *(int64_t*)b);
+			return (int64_t)*(uint64_t*)a == *(int64_t*)b;
 		if(btag == T_DOUBLE)
-			return (*(uint64_t*)a == (uint64_t)(int64_t)*(double*)b);
+			return *(uint64_t*)a == (uint64_t)(int64_t)*(double*)b;
 		if(btag == T_MPINT)
 			return mpcmp(uvtomp(*(uint64_t*)a, cmpmpint), *(mpint**)b) == 0;
 	}
 	if(atag == T_INT64){
 		if(btag == T_UINT64)
-			return (*(int64_t*)a == (int64_t)*(uint64_t*)b);
+			return *(int64_t*)a == (int64_t)*(uint64_t*)b;
 		if(btag == T_DOUBLE)
-			return (*(int64_t*)a == (int64_t)*(double*)b);
+			return *(int64_t*)a == (int64_t)*(double*)b;
 		if(btag == T_MPINT)
 			return mpcmp(vtomp(*(int64_t*)a, cmpmpint), *(mpint**)b) == 0;
 	}
 	if(btag == T_UINT64){
 		if(atag == T_INT64)
-			return ((int64_t)*(uint64_t*)b == *(int64_t*)a);
+			return (int64_t)*(uint64_t*)b == *(int64_t*)a;
 		if(atag == T_DOUBLE)
-			return (*(uint64_t*)b == (uint64_t)(int64_t)*(double*)a);
+			return *(uint64_t*)b == (uint64_t)(int64_t)*(double*)a;
 		if(atag == T_MPINT)
 			return mpcmp(*(mpint**)a, uvtomp(*(uint64_t*)b, cmpmpint)) == 0;
 	}
 	if(btag == T_INT64){
 		if(atag == T_UINT64)
-			return (*(int64_t*)b == (int64_t)*(uint64_t*)a);
+			return *(int64_t*)b == (int64_t)*(uint64_t*)a;
 		if(atag == T_DOUBLE)
-			return (*(int64_t*)b == (int64_t)*(double*)a);
+			return *(int64_t*)b == (int64_t)*(double*)a;
 		if(atag == T_MPINT)
 			return mpcmp(*(mpint**)a, vtomp(*(int64_t*)b, cmpmpint)) == 0;
 	}
--- a/print.c
+++ b/print.c
@@ -168,9 +168,9 @@
 tinyp(value_t v)
 {
 	if(issymbol(v))
-		return (u8_strwidth(symbol_name(v)) < SMALL_STR_LEN);
+		return u8_strwidth(symbol_name(v)) < SMALL_STR_LEN;
 	if(fl_isstring(v))
-		return (cv_len((cvalue_t*)ptr(v)) < SMALL_STR_LEN);
+		return cv_len(ptr(v)) < SMALL_STR_LEN;
 	return (
 		isfixnum(v) || isbuiltin(v) || iscprim(v) ||
 		v == FL_f || v == FL_t ||
@@ -217,7 +217,7 @@
 	// get the width of an expression if we can do so cheaply
 	if(issymbol(v))
 		return u8_strwidth(symbol_name(v));
-	if(iscprim(v) && ptr(v) != nil && cp_class((cprim_t*)ptr(v)) == FL(runetype))
+	if(iscprim(v) && ptr(v) != nil && cp_class(ptr(v)) == FL(runetype))
 		return 4;
 	return -1;
 }
@@ -241,7 +241,7 @@
 indentafter3(value_t head, value_t v)
 {
 	// for certain X always indent (X a b c) after b
-	return ((head == FL_forsym) && !allsmallp(cdr_(v)));
+	return head == FL_forsym && !allsmallp(cdr_(v));
 }
 
 static int
@@ -248,8 +248,7 @@
 indentafter2(value_t head, value_t v)
 {
 	// for certain X always indent (X a b) after a
-	return ((head == FL_definesym || head == FL_defmacrosym) &&
-			!allsmallp(cdr_(v)));
+	return (head == FL_definesym || head == FL_defmacrosym) && !allsmallp(cdr_(v));
 }
 
 static int
@@ -272,7 +271,7 @@
 	// is no longer considered special:
 	// (a b c d e
 	//  f g h i j)
-	return (allsmallp(v) > 9);
+	return allsmallp(v) > 9;
 }
 
 static void
@@ -282,11 +281,11 @@
 	const char *op;
 	if(iscons(cdr_(v)) && cdr_(cdr_(v)) == FL_nil &&
 		!ptrhash_has(&FL(printconses), (void*)cdr_(v)) &&
-		(((car_(v) == FL_quote)	    && (op = "'"))  ||
-		 ((car_(v) == FL_backquote) && (op = "`"))  ||
-		 ((car_(v) == FL_comma)     && (op = ","))  ||
-		 ((car_(v) == FL_commaat)   && (op = ",@")) ||
-		 ((car_(v) == FL_commadot)  && (op = ",.")))){
+		((car_(v) == FL_quote     && (op = "'"))  ||
+		 (car_(v) == FL_backquote && (op = "`"))  ||
+		 (car_(v) == FL_comma     && (op = ","))  ||
+		 (car_(v) == FL_commaat   && (op = ",@")) ||
+		 (car_(v) == FL_commadot  && (op = ",.")))){
 		// special prefix syntax
 		unmark_cons(v);
 		unmark_cons(cdr_(v));
@@ -323,7 +322,7 @@
 		}
 
 		if(!FL(print_pretty) ||
-			((head == FL_lambda) && n == 0)){
+			(head == FL_lambda && n == 0)){
 			// never break line before lambda-list
 			ind = 0;
 		}else{
@@ -330,14 +329,14 @@
 			est = lengthestimate(car_(cd));
 			nextsmall = smallp(car_(cd));
 			thistiny = tinyp(car_(v));
-			ind = (((FL(vpos) > lastv) ||
+			ind = ((FL(vpos) > lastv ||
 					(FL(hpos)>FL(scr_width)/2 && !nextsmall && !thistiny && n>0)) ||
 
 				   (FL(hpos) > FL(scr_width)-4) ||
 
-				   (est != -1 && (FL(hpos)+est > FL(scr_width)-2)) ||
+				   (est != -1 && FL(hpos)+est > FL(scr_width)-2) ||
 
-				   ((head == FL_lambda) && !nextsmall) ||
+				   (head == FL_lambda && !nextsmall) ||
 
 				   (n > 0 && always) ||
 
@@ -803,7 +802,7 @@
 static void
 cvalue_print(ios_t *f, value_t v)
 {
-	cvalue_t *cv = (cvalue_t*)ptr(v);
+	cvalue_t *cv = ptr(v);
 	void *data = cptr(v);
 	value_t label;
 
--- a/read.c
+++ b/read.c
@@ -625,7 +625,7 @@
 	listwith:
 		v = cons_reserve(2);
 		car_(v) = *head;
-		cdr_(v) = tagptr(((cons_t*)ptr(v))+1, TAG_CONS);
+		cdr_(v) = tagptr((cons_t*)ptr(v)+1, TAG_CONS);
 		car_(cdr_(v)) = cdr_(cdr_(v)) = FL_nil;
 		PUSH(v);
 		if(label != UNBOUND)
--- a/string.c
+++ b/string.c
@@ -22,7 +22,7 @@
 		argcount(nargs, 1);
 	if(!fl_isstring(args[0]))
 		type_error("string", args[0]);
-	size_t len = cv_len((cvalue_t*)ptr(args[0]));
+	size_t len = cv_len(ptr(args[0]));
 	size_t stop = len;
 	if(nargs > 1){
 		start = tosize(args[1]);
@@ -181,7 +181,7 @@
 	if(nargs != 2)
 		argcount(nargs, 3);
 	char *s = tostring(args[0]);
-	size_t lenbytes = cv_len((cvalue_t*)ptr(args[0]));
+	size_t lenbytes = cv_len(ptr(args[0]));
 	size_t startbytes, n, startchar = tosize(args[1]);
 	for(startbytes = n = 0; n < startchar && startbytes < lenbytes; n++)
 		startbytes += u8_seqlen(s+startbytes);
@@ -219,7 +219,7 @@
 BUILTIN("char-upcase", char_upcase)
 {
 	argcount(nargs, 1);
-	cprim_t *cp = (cprim_t*)ptr(args[0]);
+	cprim_t *cp = ptr(args[0]);
 	if(!iscprim(args[0]) || cp_class(cp) != FL(runetype))
 		type_error("rune", args[0]);
 	return mk_rune(toupperrune(*(Rune*)cp_data(cp)));
@@ -324,7 +324,7 @@
 		needle[0] = *(char*)cp_data(cp);
 		needle[needlesz] = 0;
 	}else if(fl_isstring(v)){
-		cvalue_t *cv = (cvalue_t*)ptr(v);
+		cvalue_t *cv = ptr(v);
 		needlesz = cv_len(cv);
 		needle = (char*)cv_data(cv);
 	}else{
@@ -396,6 +396,6 @@
 {
 	argcount(nargs, 1);
 	char *s = tostring(args[0]);
-	size_t len = cv_len((cvalue_t*)ptr(args[0]));
+	size_t len = cv_len(ptr(args[0]));
 	return u8_isvalid(s, len) ? FL_t : FL_f;
 }
--- a/table.c
+++ b/table.c
@@ -71,7 +71,7 @@
 bool
 ishashtable(value_t v)
 {
-	return iscvalue(v) && cv_class((cvalue_t*)ptr(v)) == FL(tabletype);
+	return iscvalue(v) && cv_class(ptr(v)) == FL(tabletype);
 }
 
 BUILTIN("table?", tablep)