shithub: femtolisp

Download patch

ref: 5155bfd6b3ff944b62196c03f81d601c1c8a6b56
parent: 85e6759db8e1fd064efc3cf04716b15e84ca089f
author: Sigrid Solveig Haflínudóttir <[email protected]>
date: Sun Apr 2 18:56:30 EDT 2023

reformat some more

--- a/builtins.c
+++ b/builtins.c
@@ -145,11 +145,12 @@
 	return args[1];
 }
 
-static void global_env_list(symbol_t *root, value_t *pv)
+static void
+global_env_list(symbol_t *root, value_t *pv)
 {
 	while(root != nil){
 		if(root->name[0] != ':' && (root->binding != UNBOUND))
-			*pv = fl_cons(tagptr(root,TAG_SYM), *pv);
+			*pv = fl_cons(tagptr(root, TAG_SYM), *pv);
 		global_env_list(root->left, pv);
 		root = root->right;
 	}
@@ -274,7 +275,7 @@
 	v = alloc_vector((unsigned)i, 0);
 	f = nargs == 2 ? args[1] : FL_UNSPECIFIED;
 	for(k = 0; k < i; k++)
-		vector_elt(v,k) = f;
+		vector_elt(v, k) = f;
 	return v;
 }
 
--- a/cvalues.c
+++ b/cvalues.c
@@ -55,12 +55,13 @@
 }
 
 // remove dead objects from finalization list in-place
-static void sweep_finalizers(void)
+static void
+sweep_finalizers(void)
 {
 	cvalue_t **lst = Finalizers;
 	size_t n = 0, ndel = 0, l = nfinalizers;
 	cvalue_t *tmp;
-#define SWAP_sf(a,b) (tmp = a, a = b, b= tmp, 1)
+#define SWAP_sf(a, b) (tmp = a, a = b, b = tmp, 1)
 	if(l == 0)
 		return;
 	do{
@@ -483,7 +484,7 @@
 	if(isvector(arg)){
 		assert(cnt <= vector_size(arg));
 		for(i = 0; i < cnt; i++){
-			cvalue_init(eltype, vector_elt(arg,i), dest);
+			cvalue_init(eltype, vector_elt(arg, i), dest);
 			dest = (char*)dest + elsize;
 		}
 		return 0;
@@ -878,7 +879,8 @@
 	return el;
 }
 
-static value_t cvalue_array_aset(value_t *args)
+static value_t
+cvalue_array_aset(value_t *args)
 {
 	char *data; int index;
 	fltype_t *eltype = cv_class(ptr(args[0]))->eltype;
@@ -1234,7 +1236,7 @@
 	numerictype_t ta, tb;
 	void *aptr, *bptr;
 
-	if(bothfixnums(a,b)){
+	if(bothfixnums(a, b)){
 		if(a == b)
 			return 0;
 		if(numval(a) < numval(b))
@@ -1294,7 +1296,8 @@
 	return mk_double(da);
 }
 
-static value_t fl_idiv2(value_t a, value_t b)
+static value_t
+fl_idiv2(value_t a, value_t b)
 {
 	lltint_t ai, bi;
 	numerictype_t ta, tb;
--- a/equal.c
+++ b/equal.c
@@ -71,7 +71,7 @@
 	int taga = tag(a);
 	int tagb = cmptag(b);
 	int c;
-	switch (taga){
+	switch(taga){
 	case TAG_NUM :
 	case TAG_NUM1:
 		if(isfixnum(b))
@@ -164,18 +164,16 @@
 		return fixnum(1);
 	m = la < lb ? la : lb;
 	for(i = 0; i < m; i++){
-		xa = vector_elt(a,i);
-		xb = vector_elt(b,i);
+		xa = vector_elt(a, i);
+		xb = vector_elt(b, i);
 		if(leafp(xa) || leafp(xb)){
 			d = bounded_compare(xa, xb, 1, eq);
 			if(d != NIL && numval(d) != 0)
 				return d;
-		}else{
-			if(tag(xa) < tag(xb))
-				return fixnum(-1);
-			else if(tag(xa) > tag(xb))
-				return fixnum(1);
-		}
+		}else if(tag(xa) < tag(xb))
+			return fixnum(-1);
+		else if(tag(xa) > tag(xb))
+			return fixnum(1);
 	}
 
 	ca = eq_class(table, a);
@@ -186,8 +184,8 @@
 	eq_union(table, a, b, ca, cb);
 
 	for(i = 0; i < m; i++){
-		xa = vector_elt(a,i);
-		xb = vector_elt(b,i);
+		xa = vector_elt(a, i);
+		xb = vector_elt(b, i);
 		if(!leafp(xa) || tag(xa) == TAG_FUNCTION){
 			d = cyc_compare(xa, xb, table, eq);
 			if(numval(d) != 0)
@@ -310,7 +308,7 @@
 {
 	if(eq_comparable(a, b))
 		return a == b ? FL_T : FL_F;
-	return numval(compare_(a,b,1)) == 0 ? FL_T : FL_F;
+	return numval(compare_(a, b, 1)) == 0 ? FL_T : FL_F;
 }
 
 /*
@@ -384,7 +382,7 @@
 		}
 		len = vector_size(a);
 		for(i = 0; i < len; i++){
-			h = MIX(h, bounded_hash(vector_elt(a,i), bound/2, &oob2)^1);
+			h = MIX(h, bounded_hash(vector_elt(a, i), bound/2, &oob2)^1);
 			if(oob2)
 				bound /= 2;
 			*oob = *oob || oob2;
--- a/equalhash.c
+++ b/equalhash.c
@@ -3,6 +3,6 @@
 #include "equalhash.h"
 #include "htable.inc"
 
-#define _equal_lispvalue_(x,y) equal_lispvalue((value_t)(x),(value_t)(y))
+#define _equal_lispvalue_(x, y) equal_lispvalue((value_t)(x), (value_t)(y))
 
 HTIMPL(equalhash, hash_lispvalue, _equal_lispvalue_)
--- a/flisp.c
+++ b/flisp.c
@@ -195,7 +195,7 @@
 // safe cast operators --------------------------------------------------------
 
 #define isstring fl_isstring
-#define SAFECAST_OP(type,ctype,cnvt) \
+#define SAFECAST_OP(type, ctype, cnvt) \
 	ctype to##type(value_t v) \
 	{ \
 		if(is##type(v)) \
@@ -202,11 +202,11 @@
 			return (ctype)cnvt(v); \
 		type_error(#type, v); \
 	}
-SAFECAST_OP(cons,  cons_t*,  ptr)
-SAFECAST_OP(symbol,symbol_t*,ptr)
-SAFECAST_OP(fixnum,fixnum_t, numval)
-SAFECAST_OP(cvalue,cvalue_t*,ptr)
-SAFECAST_OP(string,char*,	cvalue_data)
+SAFECAST_OP(cons, cons_t*, ptr)
+SAFECAST_OP(symbol, symbol_t*, ptr)
+SAFECAST_OP(fixnum, fixnum_t, numval)
+SAFECAST_OP(cvalue, cvalue_t*, ptr)
+SAFECAST_OP(string, char*, cvalue_data)
 #undef isstring
 
 // symbol table ---------------------------------------------------------------
@@ -216,7 +216,7 @@
 int
 fl_is_keyword_name(char *str, size_t len)
 {
-	return ((str[0] == ':' || str[len-1] == ':') && str[1] != '\0');
+	return (str[0] == ':' || str[len-1] == ':') && str[1] != '\0';
 }
 
 static symbol_t *
@@ -427,19 +427,19 @@
 	if(t == TAG_VECTOR){
 		// N.B.: 0-length vectors secretly have space for a first element
 		size_t i, sz = vector_size(v);
-		if(vector_elt(v,-1) & 0x1){
+		if(vector_elt(v, -1) & 0x1){
 			// grown vector
-			nc = relocate(vector_elt(v,0));
+			nc = relocate(vector_elt(v, 0));
 			forward(v, nc);
 		}else{
 			nc = tagptr(alloc_words(sz+1), TAG_VECTOR);
 			vector_setsize(nc, sz);
-			a = vector_elt(v,0);
+			a = vector_elt(v, 0);
 			forward(v, nc);
 			if(sz > 0){
-				vector_elt(nc,0) = relocate(a);
+				vector_elt(nc, 0) = relocate(a);
 				for(i = 1; i < sz; i++)
-					vector_elt(nc,i) = relocate(vector_elt(v,i));
+					vector_elt(nc, i) = relocate(vector_elt(v, i));
 			}
 		}
 		return nc;
@@ -920,11 +920,11 @@
 	((int16_t) \
 	((((int16_t)a[0])<<0)  | \
 	 (((int16_t)a[1])<<8)))
-#define PUT_INT32(a,i) (*(int32_t*)(a) = bswap_32((int32_t)(i)))
+#define PUT_INT32(a, i) (*(int32_t*)(a) = bswap_32((int32_t)(i)))
 #else
 #define GET_INT32(a) (*(int32_t*)a)
 #define GET_INT16(a) (*(int16_t*)a)
-#define PUT_INT32(a,i) (*(int32_t*)(a) = (int32_t)(i))
+#define PUT_INT32(a, i) (*(int32_t*)(a) = (int32_t)(i))
 #endif
 
 #define OP(x) case x:
@@ -988,7 +988,7 @@
 		if(op < nelem(builtins) && builtins[op].name != nil)
 			curr_fname = builtins[op].name;
 
-		switch (op){
+		switch(op){
 		OP(OP_LOADA0)
 			PUSH(captured ? vector_elt(Stack[bp], 0) : Stack[bp]);
 			NEXT_OP;
@@ -1568,7 +1568,7 @@
 			if(bothfixnums(v, e))
 				v = v == e ? FL_T : FL_F;
 			else
-				v = !numeric_compare(v,e,1,0,1) ? FL_T : FL_F;
+				v = numeric_compare(v, e, 1, 0, 1) == 0 ? FL_T : FL_F;
 			POPN(1);
 			Stack[SP-1] = v;
 			NEXT_OP;
@@ -1593,7 +1593,7 @@
 		apply_vector:
 			v = alloc_vector(n, 0);
 			if(n){
-				memmove(&vector_elt(v,0), &Stack[SP-n], n*sizeof(value_t));
+				memmove(&vector_elt(v, 0), &Stack[SP-n], n*sizeof(value_t));
 				POPN(n);
 			}
 			PUSH(v);
@@ -1837,7 +1837,7 @@
 		if(Stack[top-1] /*captured*/){
 			vector_elt(v, 0) = Stack[bp];
 			memmove(&vector_elt(v, 1),
-				   &vector_elt(Stack[bp+1],0), (sz-1)*sizeof(value_t));
+				   &vector_elt(Stack[bp+1], 0), (sz-1)*sizeof(value_t));
 		}else{
 			uint32_t i;
 			for(i = 0; i < sz; i++){
@@ -1844,7 +1844,7 @@
 				value_t si = Stack[bp+i];
 				// if there's an error evaluating argument defaults some slots
 				// might be left set to UNBOUND (issue #22)
-				vector_elt(v,i) = si == UNBOUND ? FL_UNSPECIFIED : si;
+				vector_elt(v, i) = si == UNBOUND ? FL_UNSPECIFIED : si;
 			}
 		}
 		lst = fl_cons(v, lst);
@@ -2072,12 +2072,12 @@
 	return first;
 }
 
-#define BUILTIN_FN(l,c) extern BUILTIN(l,c);
+#define BUILTIN_FN(l, c) extern BUILTIN(l, c);
 #include "builtin_fns.h"
 #undef BUILTIN_FN
 
 static const builtinspec_t builtin_fns[] = {
-#define BUILTIN_FN(l,c){l,fn_builtin_##c},
+#define BUILTIN_FN(l, c){l, fn_builtin_##c},
 #include "builtin_fns.h"
 #undef BUILTIN_FN
 };
--- a/flisp.h
+++ b/flisp.h
@@ -78,16 +78,16 @@
 #define TAG_FWD UNBOUND
 #define tag(x) ((x) & 0x7)
 #define ptr(x) ((void*)((x) & (~(value_t)0x7)))
-#define tagptr(p,t) (((value_t)(p)) | (t))
+#define tagptr(p, t) (((value_t)(p)) | (t))
 #define fixnum(x) ((value_t)((fixnum_t)(x))<<2)
 #define numval(x)  (((fixnum_t)(x))>>2)
-#define fits_bits(x,b) (((x)>>(b-1)) == 0 || (~((x)>>(b-1))) == 0)
+#define fits_bits(x, b) (((x)>>(b-1)) == 0 || (~((x)>>(b-1))) == 0)
 #define uintval(x) (((unsigned int)(x))>>3)
 #define builtin(n) tagptr((((int)n)<<3), TAG_FUNCTION)
 #define iscons(x) (tag(x) == TAG_CONS)
 #define issymbol(x) (tag(x) == TAG_SYM)
 #define isfixnum(x) (((x)&3) == TAG_NUM)
-#define bothfixnums(x,y) ((((x)|(y)) & 3) == TAG_NUM)
+#define bothfixnums(x, y) ((((x)|(y)) & 3) == TAG_NUM)
 int isbuiltin(value_t x);
 #define isvector(x) (tag(x) == TAG_VECTOR)
 #define iscvalue(x) (tag(x) == TAG_CVALUE)
@@ -94,7 +94,7 @@
 #define iscprim(x)  (tag(x) == TAG_CPRIM)
 #define selfevaluating(x) (tag(x) < 6)
 // comparable with ==
-#define eq_comparable(a,b) (!(((a)|(b))&1))
+#define eq_comparable(a, b) (!(((a)|(b))&1))
 #define eq_comparablep(a) (!((a)&1))
 // doesn't lead to other values
 #define leafp(a) (((a)&3) != 3)
@@ -103,7 +103,7 @@
 
 #define isforwarded(v) (((value_t*)ptr(v))[0] == TAG_FWD)
 #define forwardloc(v) (((value_t*)ptr(v))[1])
-#define forward(v,to) \
+#define forward(v, to) \
 	do{ \
 		(((value_t*)ptr(v))[0] = TAG_FWD); \
 		(((value_t*)ptr(v))[1] = to); \
@@ -110,8 +110,8 @@
 	}while (0)
 
 #define vector_size(v) (((size_t*)ptr(v))[0]>>2)
-#define vector_setsize(v,n) (((size_t*)ptr(v))[0] = ((n)<<2))
-#define vector_elt(v,i) (((value_t*)ptr(v))[1+(i)])
+#define vector_setsize(v, n) (((size_t*)ptr(v))[0] = ((n)<<2))
+#define vector_elt(v, i) (((value_t*)ptr(v))[1+(i)])
 #define vector_grow_amt(x) ((x)<8 ? 5 : 6*((x)>>3))
 // functions ending in _ are unsafe, faster versions
 #define car_(v) (((cons_t*)ptr(v))->car)
--- a/llt/bitvector-ops.c
+++ b/llt/bitvector-ops.c
@@ -469,9 +469,9 @@
 		free(temp); \
 }
 
-#define BV_AND(a,b) ((a)&(b))
-#define BV_OR(a,b)  ((a)|(b))
-#define BV_XOR(a,b) ((a)^(b))
+#define BV_AND(a, b) ((a)&(b))
+#define BV_OR(a, b) ((a)|(b))
+#define BV_XOR(a, b) ((a)^(b))
 BITVECTOR_BINARY_OP_TO(and, BV_AND)
-BITVECTOR_BINARY_OP_TO(or,  BV_OR)
+BITVECTOR_BINARY_OP_TO(or, BV_OR)
 BITVECTOR_BINARY_OP_TO(xor, BV_XOR)
--- a/llt/bitvector.h
+++ b/llt/bitvector.h
@@ -9,7 +9,7 @@
 void bitvector_shr_to(uint32_t *dest, uint32_t *b, size_t n, uint32_t s);
 void bitvector_shl(uint32_t *b, size_t n, uint32_t s);
 void bitvector_shl_to(uint32_t *dest, uint32_t *b, size_t n, uint32_t s, int scrap);
-void bitvector_fill(uint32_t *b,uint32_t offs, uint32_t c, uint32_t nbits);
+void bitvector_fill(uint32_t *b, uint32_t offs, uint32_t c, uint32_t nbits);
 void bitvector_copy(uint32_t *dest, uint32_t doffs, uint32_t *a, uint32_t aoffs, uint32_t nbits);
 void bitvector_not(uint32_t *b, uint32_t offs, uint32_t nbits);
 void bitvector_not_to(uint32_t *dest, uint32_t doffs, uint32_t *a, uint32_t aoffs, uint32_t nbits);
--- a/llt/hashing.c
+++ b/llt/hashing.c
@@ -3,7 +3,7 @@
 lltuint_t
 nextipow2(lltuint_t i)
 {
-	if (i == 0)
+	if(i == 0)
 		return 1;
 	i |= i >> 1;
 	i |= i >> 2;
--- a/llt/htable.inc
+++ b/llt/htable.inc
@@ -124,7 +124,7 @@
 int \
 HTNAME##_has(htable_t *h, void *key) \
 { \
-    return HTNAME##_get(h,key) != HT_NOTFOUND; \
+    return HTNAME##_get(h, key) != HT_NOTFOUND; \
 } \
  \
 int \
--- a/llt/ios.c
+++ b/llt/ios.c
@@ -788,7 +788,8 @@
 	return s;
 }
 
-void ios_init_stdstreams(void)
+void
+ios_init_stdstreams(void)
 {
 	ios_stdin = LLT_ALLOC(sizeof(ios_t));
 	ios_fd(ios_stdin, STDIN_FILENO, 0, 0);
--- a/llt/llt.h
+++ b/llt/llt.h
@@ -20,11 +20,11 @@
 #ifdef BOEHM_GC /* boehm GC allocator */
 #include <gc.h>
 #define LLT_ALLOC(n) GC_MALLOC(n)
-#define LLT_REALLOC(p,n) GC_REALLOC((p),(n))
+#define LLT_REALLOC(p, n) GC_REALLOC((p), (n))
 #define LLT_FREE(x) USED(x)
 #else /* standard allocator */
 #define LLT_ALLOC(n) malloc(n)
-#define LLT_REALLOC(p,n) realloc((p),(n))
+#define LLT_REALLOC(p, n) realloc((p), (n))
 #define LLT_FREE(x) free(x)
 #endif
 
@@ -57,7 +57,7 @@
 #define rel_zero(a, b) (fabs((a)/(b)) < DBL_EPSILON)
 #define sign_bit(r) ((*(uint64_t*)&(r)) & BIT63)
 #define LABS(n) (((n)^((n)>>(NBITS-1))) - ((n)>>(NBITS-1)))
-#define NBABS(n,nb) (((n)^((n)>>((nb)-1))) - ((n)>>((nb)-1)))
+#define NBABS(n, nb) (((n)^((n)>>((nb)-1))) - ((n)>>((nb)-1)))
 #define DFINITE(d) (((*(uint64_t*)&(d))&0x7ff0000000000000ULL) != 0x7ff0000000000000ULL)
 #define LLT_ALIGN(x, sz) (((x) + (sz-1)) & (-sz))
 
--- a/llt/ptrhash.c
+++ b/llt/ptrhash.c
@@ -5,7 +5,7 @@
 
 #include "llt.h"
 
-#define OP_EQ(x,y) ((x) == (y))
+#define OP_EQ(x, y) ((x) == (y))
 
 #ifdef BITS64
 static uint64_t
--- a/llt/utf8.c
+++ b/llt/utf8.c
@@ -625,7 +625,7 @@
 			return 0;
 
 		/* Check for overlong sequences for each different length */
-		switch(ab) {
+		switch(ab){
 			/* Check for xx00 000x */
 		case 1:
 			if((c & 0x3e) == 0)
--- a/plan9/platform.h
+++ b/plan9/platform.h
@@ -35,7 +35,7 @@
 #define atanf atan
 
 #define LC_NUMERIC 0
-#define setlocale(x,y)
+#define setlocale(x, y)
 
 #define PRId64 "lld"
 #define PRIu64 "llud"
--- a/print.c
+++ b/print.c
@@ -95,7 +95,7 @@
 			mark_cons(v);
 		unsigned int i;
 		for(i = 0; i < vector_size(v); i++)
-			print_traverse(vector_elt(v,i));
+			print_traverse(vector_elt(v, i));
 	}else if(iscprim(v)){
 		// don't consider shared references to e.g. chars
 	}else if(isclosure(v)){
@@ -196,9 +196,10 @@
 	}
 	if(isvector(v)){
 		size_t s = vector_size(v);
-		return (s == 0 || (tinyp(vector_elt(v,0)) &&
-						   (s == 1 || (s == 2 &&
-									   tinyp(vector_elt(v,1))))));
+		return (
+			s == 0 ||
+			(tinyp(vector_elt(v, 0)) && (s == 1 || (s == 2 && tinyp(vector_elt(v, 1)))))
+		);
 	}
 	return 0;
 }
@@ -399,7 +400,7 @@
 	}
 	P_LEVEL++;
 
-	switch (tag(v)){
+	switch(tag(v)){
 	case TAG_NUM: case TAG_NUM1:
 		HPOS += ios_printf(f, "%"PRId64, (int64_t)numval(v));
 		break;
@@ -476,17 +477,15 @@
 					outsn("...", f, 3);
 					break;
 				}
-				fl_print_child(f, vector_elt(v,i));
+				fl_print_child(f, vector_elt(v, i));
 				if(i < sz-1){
 					if(!print_pretty)
 						outc(' ', f);
 					else{
-						est = lengthestimate(vector_elt(v,i+1));
+						est = lengthestimate(vector_elt(v, i+1));
 						if(HPOS > SCR_WIDTH-4 ||
-							(est != -1 && (HPOS+est > SCR_WIDTH-2)) ||
-							(HPOS > SCR_WIDTH/2 &&
-							 !smallp(vector_elt(v,i+1)) &&
-							 !tinyp(vector_elt(v,i))))
+						   (est != -1 && (HPOS+est > SCR_WIDTH-2)) ||
+						   (HPOS > SCR_WIDTH/2 && !smallp(vector_elt(v, i+1)) && !tinyp(vector_elt(v, i))))
 							newindent = outindent(newindent, f);
 						else
 							outc(' ', f);
@@ -592,7 +591,7 @@
 		mag = 0;
 	if((mag > max_digs_lf-1) || (mag < -max_digs_rt)){
 		num_format[1] = 'e';
-		temp = r/pow(10, mag);	  /* see if number will have a decimal */
+		temp = r/pow(10, mag); /* see if number will have a decimal */
 		fpart = temp - floor(temp); /* when written in scientific notation */
 	}else{
 		num_format[1] = 'f';
--- a/read.c
+++ b/read.c
@@ -118,23 +118,23 @@
 	}
 
 	if(tok[0] == '+'){
-		if(!strcmp(tok,"+NaN") || !strcasecmp(tok,"+nan.0")){
+		if(!strcmp(tok, "+NaN") || !strcasecmp(tok, "+nan.0")){
 			if(pval)
 				*pval = mk_double(D_PNAN);
 			return 1;
 		}
-		if(!strcmp(tok,"+Inf") || !strcasecmp(tok,"+inf.0")){
+		if(!strcmp(tok, "+Inf") || !strcasecmp(tok, "+inf.0")){
 			if(pval)
 				*pval = mk_double(D_PINF);
 			return 1;
 		}
 	}else if(tok[0] == '-'){
-		if(!strcmp(tok,"-NaN") || !strcasecmp(tok,"-nan.0")){
+		if(!strcmp(tok, "-NaN") || !strcasecmp(tok, "-nan.0")){
 			if(pval)
 				*pval = mk_double(D_NNAN);
 			return 1;
 		}
-		if(!strcmp(tok,"-Inf") || !strcasecmp(tok,"-inf.0")){
+		if(!strcmp(tok, "-Inf") || !strcasecmp(tok, "-inf.0")){
 			if(pval)
 				*pval = mk_double(D_NINF);
 			return 1;
@@ -468,7 +468,7 @@
 		elt = do_read_sexpr(UNBOUND);
 		v = Stack[SP-1];
 		assert(i < vector_size(v));
-		vector_elt(v,i) = elt;
+		vector_elt(v, i) = elt;
 		i++;
 	}
 	take();
--- a/string.c
+++ b/string.c
@@ -352,7 +352,7 @@
 		type_error("integer", n);
 	else
 		num = conv_to_uint64(cp_data(ptr(n)), cp_numtype(ptr(n)));
-	if(numval(fl_compare(args[0],fixnum(0))) < 0){
+	if(numval(fl_compare(args[0], fixnum(0))) < 0){
 		num = -num;
 		neg = 1;
 	}