shithub: sl

Download patch

ref: 7c4d7e09b3801f7453762953992727a9365d4293
parent: fdd1fd39e3a616139e48dae992ebc5d5cd710fb7
author: Sigrid Solveig Haflínudóttir <sigrid@ftrv.se>
date: Tue Feb 11 23:01:52 EST 2025

vm: less lines and indentation

--- a/src/flisp.c
+++ b/src/flisp.c
@@ -878,8 +878,7 @@
 	uint32_t i, ipd;
 	symbol_t *sym;
 	cons_t *c;
-	value_t *pv;
-	value_t v, e;
+	value_t *pv, v, e;
 	function_t *fn;
 	int x;
 
--- a/src/vm.inc
+++ b/src/vm.inc
@@ -27,7 +27,7 @@
 			if(tail){
 				FL(curr_frame) = FL(stack)[FL(curr_frame)-3];
 				for(s = -1; s < (fixnum_t)n; s++)
-					FL(stack)[bp+s] = FL(stack)[FL(sp)-n+s];
+					FL(stack)[bp+s] = FL(stack)[FL(sp)+s-n];
 				FL(sp) = bp+n;
 			}
 			nargs = n;
@@ -109,8 +109,7 @@
 	NEXT_OP;
 
 OP(OP_LOADA)
-	i = *ip++;
-	v = FL(stack)[bp+i];
+	v = FL(stack)[bp + *ip++];
 	PUSH(v);
 	NEXT_OP;
 
@@ -197,8 +196,7 @@
 	NEXT_OP;
 
 OP(OP_LOADI8)
-	s = (int8_t)*ip++;
-	PUSH(fixnum(s));
+	PUSH(fixnum((int8_t)*ip++));
 	NEXT_OP;
 
 OP(OP_POP)
@@ -288,14 +286,11 @@
 	NEXT_OP;
 
 OP(OP_NOT)
-	v = FL(stack)[FL(sp)-1];
-	FL(stack)[FL(sp)-1] = v == FL_nil ? FL_t : FL_nil;
+	FL(stack)[FL(sp)-1] = FL(stack)[FL(sp)-1] == FL_nil ? FL_t : FL_nil;
 	NEXT_OP;
 
 OP(OP_SETA)
-	v = FL(stack)[FL(sp)-1];
-	i = *ip++;
-	FL(stack)[bp+i] = v;
+	FL(stack)[bp + *ip++] = FL(stack)[FL(sp)-1];
 	NEXT_OP;
 
 OP(OP_VARGC)
@@ -408,26 +403,24 @@
 	NEXT_OP;
 
 OP(OP_NANP)
-	{
-		value_t q = FL(stack)[FL(sp)-1];
+	v = FL(stack)[FL(sp)-1];
+	if(!iscprim(v))
 		v = FL_nil;
-		if(iscprim(q)){
-			void *data = cp_data(ptr(q));
-			switch(cp_numtype(ptr(q))){
-			case T_DOUBLE:
-				if(isnan(*(double*)data))
-					v = FL_t;
-				break;
-			case T_FLOAT:
-				if(isnan(*(float*)data))
-					v = FL_t;
-				break;
-			default:
-				break;
-			}
+	else{
+		void *p = ptr(v);
+		switch(cp_numtype(p)){
+		case T_DOUBLE:
+			v = isnan(*(double*)cp_data(p)) ? FL_t : FL_nil;
+			break;
+		case T_FLOAT:
+			v = isnan(*(float*)cp_data(p)) ? FL_t : FL_nil;
+			break;
+		default:
+			v = FL_nil;
+			break;
 		}
-		FL(stack)[FL(sp)-1] = v;
 	}
+	FL(stack)[FL(sp)-1] = v;
 	NEXT_OP;
 
 OP(OP_LOAD0)
@@ -512,7 +505,7 @@
 	if(FL(stack)[FL(sp)-2] == FL(stack)[FL(sp)-1])
 		v = FL_t;
 	else
-		v = fl_compare(FL(stack)[FL(sp)-2], FL(stack)[FL(sp)-1], true) == 0 ? FL_t : FL_nil;//FL_nil
+		v = fl_compare(FL(stack)[FL(sp)-2], FL(stack)[FL(sp)-1], true) == 0 ? FL_t : FL_nil;
 	FL(stack)[FL(sp)-2] = v;
 	POPN(1);
 	NEXT_OP;
@@ -522,8 +515,8 @@
 	NEXT_OP;
 
 OP(OP_LOADC)
-	i = *ip++;
 	v = FL(stack)[bp+nargs];
+	i = *ip++;
 	assert(isvector(v));
 	assert(i < vector_size(v));
 	PUSH(vector_elt(v, i));
@@ -534,15 +527,13 @@
 	NEXT_OP;
 
 OP(OP_NUMBERP)
-	v = FL(stack)[FL(sp)-1];
-	FL(stack)[FL(sp)-1] = fl_isnumber(v) ? FL_t : FL_nil;
+	FL(stack)[FL(sp)-1] = fl_isnumber(FL(stack)[FL(sp)-1]) ? FL_t : FL_nil;
 	NEXT_OP;
 
 OP(OP_BRBOUND)
 	i = GET_INT32(ip);
 	ip += 4;
-	v = FL(stack)[bp+i];
-	PUSH(v != UNBOUND ? FL_t : FL_nil);
+	PUSH(FL(stack)[bp+i] != UNBOUND ? FL_t : FL_nil);
 	NEXT_OP;
 
 OP(OP_OPTARGS)
@@ -806,8 +797,7 @@
 	assert(nargs > 0);
 	i = GET_INT32(ip);
 	ip += 4;
-	v = FL(stack)[bp+i];
-	PUSH(v);
+	PUSH(FL(stack)[bp+i]);
 	NEXT_OP;
 
 OP(OP_EQV)
@@ -816,7 +806,7 @@
 	else if(!leafp(FL(stack)[FL(sp)-2]) || !leafp(FL(stack)[FL(sp)-1]))
 		v = FL_nil;
 	else
-		v = fl_compare(FL(stack)[FL(sp)-2], FL(stack)[FL(sp)-1], true) == 0 ? FL_t : FL_nil;//FL_nil
+		v = fl_compare(FL(stack)[FL(sp)-2], FL(stack)[FL(sp)-1], true) == 0 ? FL_t : FL_nil;
 	FL(stack)[FL(sp)-2] = v;
 	POPN(1);
 	NEXT_OP;
@@ -860,14 +850,14 @@
 	NEXT_OP;
 
 OP(OP_SETAL)
-	v = FL(stack)[FL(sp)-1];
 	i = GET_INT32(ip);
 	ip += 4;
-	FL(stack)[bp+i] = v;
+	FL(stack)[bp+i] = FL(stack)[FL(sp)-1];
 	NEXT_OP;
 
 OP(OP_BOXL)
-	i = GET_INT32(ip); ip += 4;
+	i = GET_INT32(ip);
+	ip += 4;
 	v = mk_cons();
 	car_(v) = FL(stack)[bp+i];
 	cdr_(v) = FL_nil;